[newbie] specify address in various formats?
[newbie] specify address in various formats?
- Subject: [newbie] specify address in various formats?
- From: email@hidden (Sebastian Mecklenburg)
- Date: Sat, 24 May 2003 20:20:50 +0200
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.