Re: sockaddr structs vs. address strings
Re: sockaddr structs vs. address strings
- Subject: Re: sockaddr structs vs. address strings
- From: Heath Raftery <email@hidden>
- Date: Tue, 27 Sep 2005 09:52:13 +1000
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:
This email sent to email@hidden