Re: [newbie] specify address in various formats?
Re: [newbie] specify address in various formats?
- Subject: Re: [newbie] specify address in various formats?
- From: "Justin C. Walker" <email@hidden>
- Date: Sat, 24 May 2003 11:58:55 -0700
It's difficult for me to figure out what is wrong. You haven't told us
what errors you are seeing, and it's not possible to tell from the
'heavily shortened' code whether you are correctly checking for and
acting on errors that are returned by the library calls.
Where do you expect to get the address resolution services from? With
a NULL as your server name, the code won't be able to handle names,
only numeric (dotted/hex) addresses, right? Also, the disconnect
between 'hostname' and 'in_hostname' is a result of the shortening,
right?
Regards,
Justin
On Saturday, May 24, 2003, at 11:20 AM, Sebastian Mecklenburg wrote:
hello,
i want to program a simple tcp-client (using unix sockets) where the
user should be able to specify the servers address either as ipv6
address ("fe80::1"), ipv4 address ("127.0.0.1") or as name-string
("localhost" or "www.whatever.org"). how would i do this? i tried
getaddrinfo() and then passing the ai_addr field of the resulting
addrinfo struct to the connect() function, but the connect fails.
a heavily shortened codesample:
doConnect(hostname) {
struct addrinfo hints, *res;
memset(&hints, 0, sizeof(hints));
hints.ai_flags = AI_CANONNAME; //AI_PASSIVE (not for clients)
hints.ai_family = PF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
getaddrinfo(in_hostname, NULL, &hints, &res);
int s = socket(res->ai_family, SOCK_STREAM, IPPROTO_TCP);
// Connect to the server
connect(s, res->ai_addr, sizeof(res->ai_addr) ;
}
but the connect fails. the manpages say about getaddrinfo():
"If the AI_PASSIVE bit is not set in the ai_flags member of the hints
structure, then the returned socket address structure will be ready
for a
call to connect()[...]"
what am i doing wrong?
regards,
sebastian mecklenburg
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
--
/~\ The ASCII Justin C. Walker, Curmudgeon-at-Large
\ / Ribbon Campaign
X Help cure HTML Email
/ \
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.