Andreas, James, Both of your ways to add the port number work! My app can now send/recv data over Wifi and cell networks seamlessly. This will buy me some time before I can get around to rearchitecting everything to use the modern URL approach.
Many thanks!!! -Carl > On Jan 16, 2018, at 2:11 PM, Andreas Fink <af...@list.fink.org> wrote: > > 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 Jan 16, 2018, at 1:58 PM, James R Cutler <james.cut...@consultant.com> wrote: The man page for getaddrinfo implies that > error = getaddrinfo(“www.myserver.com:12345 > <http://www.myserver.com:12345/>", "http", &hints, &res0); should rather be > error = getaddrinfo(“www.myserver.com > <http://www.myserver.com:12345/>", “12345", &hints, &res0);
_______________________________________________ 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