getaddrinfo returns a host's address. The port is not used here. Its more like "dnsname" to "ip" translation. and your "http" would be looked up in /etc/services file statically. You can set port in the struct sockaddr
struct addrinfo *addrInfos = NULL; int port = 12345; int res =getaddrinfo("www.myserver.com <http://www.myserver.com/>","http", NULL, &addrInfos); if(res==0) { struct addrinfo *thisAddr = addrInfos; while(thisAddr) { /* you might only want IPv4 or IPv6 records */ if(thisAddr->ai_family == AF_INET) { struct sockaddr_in *sa = (struct sockaddr_in *)thisAddr->ai_addr; sa->port = htons(port); /* here your sockaddr is usable for connections over IPv4 to port 12345 */ } else if(thisAddr->ai_family == AF_INET6)) { struct sockaddr_in6 *sa6 = (struct sockaddr_in *)thisAddr->ai_addr; sa6->port = htons(port); /* here your sockaddr is usable for connections over IPv6 to port 12345 */ } /* but there might be more servers in the list....*/ thisAddr = thisAddr->ai_next; } freeaddrinfo(addrInfos); } > On 16 Jan 2018, at 21:50, Carl Hoefs <newsli...@autonomy.caltech.edu> wrote: > > >> On Jan 16, 2018, at 1:22 PM, Carl Hoefs <newsli...@autonomy.caltech.edu >> <mailto:newsli...@autonomy.caltech.edu>> wrote: >> >> >>> On Jan 16, 2018, at 11:05 AM, Jens Alfke <j...@mooseyard.com >>> <mailto:j...@mooseyard.com>> wrote: >>> >>>> On Jan 16, 2018, at 2:11 AM, Quinn The Eskimo! <eski...@apple.com >>>> <mailto:eski...@apple.com>> wrote: >>>> >>>> The fact you’re using a legacy API like this implies that you’re not >>>> IPv6-compatible. To can learn more about this is my “Supporting IPv6-only >>>> Networks” pinned post on DevForums. >>>> >>>> <https://forums.developer.apple.com/message/136166#136166 >>>> <https://forums.developer.apple.com/message/136166#136166>> >>> >>> According to Stuart Cheshire(?)’s talk at a recent WWDC, some cell carriers >>> have switched their data networks over to IPV6-_only_. This may be the >>> cause of the problem. Even if gethostbyname is able to retrieve an IPv4 >>> address for your server, your device would be unable to send packets to it >>> because there’s no IPv4 router upstream. >> >> Jens, Quinn, >> >> I have verified that I can indeed access the server via cell data using >> NSURLSessionDataTask & friends. So yes, it appears that trying to go through >> IPV6-only networks using IPV4 APIs doesn’t work very well… > > Okay, I’ve been looking around for a temporary stop-gap measure for the time > of being, and I think getaddrinfo() may work. > > The problem I’m having is getting getaddrinfo() to accept a hostname with a > port number specification: > > struct addrinfo hints, *res, *res0; > int error; > int s; > const char *cause = NULL; > > memset(&hints, 0, sizeof(hints)); > hints.ai_family = PF_UNSPEC; > hints.ai_socktype = SOCK_STREAM; > error = getaddrinfo(“www.myserver.com:12345 > <http://www.myserver.com:12345/>", "http", &hints, &res0); > > The above call to getaddrinfo() returns "nodename nor servname provided, or > not known”. It works (and I can connect) if I don’t specify the port number > (but it connects to the wrong server, of course). > > Is there a way to use getaddrinfo() with a port number? > > -Carl > > _______________________________________________ > Do not post admin requests to the list. They will be ignored. > Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) > Help/Unsubscribe/Update your Subscription: > https://lists.apple.com/mailman/options/macnetworkprog/afink%40list.fink.org > > This email sent to af...@list.fink.org
_______________________________________________ Do not post admin requests to the list. They will be ignored. Macnetworkprog mailing list (Macnetworkprog@lists.apple.com) Help/Unsubscribe/Update your Subscription: https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com This email sent to arch...@mail-archive.com