Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: sockaddr structs vs. address strings



On 25/09/2005, at 6:45 PM, Dustin Voss wrote:

So, what should I do? Should the method take an NSString, and if so, how shall I turn it into a sockaddr? Or should the method take a sockaddr, so that I put the burden on the developer?

My vote goes to the NSString. When I'm working with the network layer I always start with a string, and only when necessary build the sockaddr. When grabbing from a file, a header constant, the GUI (unlikely for an accept, I admit) it'll be strings. I think the generation of the sockaddr should be in the network class, since they are all but useless in any other function.


I haven't had to deal with the extra difficulties you'll face, and you've probably already got this far, but here's what I use to go from NSString to sockaddr:

struct sockaddr_in socketAddress;
socketAddress.sin_family = AF_INET;
socketAddress.sin_port = htons(fRemoteHostPort);
inet_aton([fRemoteHostIPAddress cString], & (socketAddress.sin_addr));
memset(&(socketAddress.sin_zero), '\0', 8); // zero the rest of the struct


Regards,
Heath
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/macnetworkprog/email@hidden

This email sent to email@hidden
References: 
 >sockaddr structs vs. address strings (From: Dustin Voss <email@hidden>)



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.