Re: sockaddr structs vs. address strings
site_archiver@lists.apple.com Delivered-To: macnetworkprog@lists.apple.com Domainkey-signature: a=rsa-sha1; q=dns; c=nofws; s=dk20050327; d=earthlink.net; b=NnRS5iiaOjaBl9oFW/bW1CZrirLcakBDZdpCDBkcDgcHxQpjwuV2CmH5xqI+wm6w; h=Received:Mime-Version:In-Reply-To:References:Content-Type:Message-Id:Content-Transfer-Encoding:From:Subject:Date:To:X-Mailer:X-ELNK-Trace:X-Originating-IP; (downloadable from http://homepage.mac.com/d.j.v./FileSharing9.html) On 27 Sep 2005, at 2:35 AM, Quinn wrote: At 9:52 +1000 27/9/05, Heath Raftery wrote: My vote goes to the NSString. ... At 1:45 -0700 25/9/05, Dustin Voss wrote: At 9:52 +1000 27/9/05, Heath Raftery wrote: _______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/macnetworkprog/site_archiver%40lists.... Thanks for the advice, guys! I've released the next version of AsyncSocket, incorporating these changes. I'd probably vote for this as well. It's not the best approach in the specific case you mention (-acceptOnAddress:port:), but it's the best solution in general. Whichever I choose, I want to support both IPv4 and IPv6 addresses. I don't care about DNS names. But I will need to be able to verify that the developer did not pass a DNS name or an address of another computer to the method. And I need to end up with a sockaddr struct. You can just let bind do this for you. If you try to bind to an address that's not local, you'll get an error (AFAICT EADDRNOTAVAIL). 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 If you want to work at the BSD level, I think that getaddrinfo <x- man-page://3/getaddrinfo> is the best choice. It supports both v4 and v6. By passing AI_NUMERICHOST, you can get it to just support the textual representation of numerical IP addresses, and never hit the wire. This email sent to site_archiver@lists.apple.com
participants (1)
-
Dustin Voss