Simplest way to get IP/Port?
Simplest way to get IP/Port?
- Subject: Simplest way to get IP/Port?
- From: Dan Gelder <email@hidden>
- Date: Mon, 30 May 2005 13:57:03 -0700
I'm trying to put a listener socket up so others can connect to it. Here is my relevant code:
// bind the socket
sockaddr_in bindingAddress;
bindingAddress.sin_family = AF_INET;
bindingAddress.sin_port = htons(0);
bindingAddress.sin_addr.s_addr = htonl(INADDR_ANY);
CFDataRef addressData = CFDataCreate(
NULL, (UInt8 *)&bindingAddress, sizeof(bindingAddress));
// bind the socket
CFSocketError socketErr = CFSocketSetAddress(_socket, addressData);
CFRelease(addressData);
Now I just want to get the IP and port so I can give out that information:
CFDataRef dataRef = CFSocketCopyAddress(_socket);
sockaddr_in* sockaddr = (sockaddr_in*)CFDataGetBytePtr(dataRef);
char space[255];
inet_ntop(AF_INET, &sockaddr->sin_addr, space, sizeof(space) );
out.append ( space );
out.append (":");
out.append (integer(sockaddr->sin_port));
CFRelease(dataRef);
sin_port is ok, but sin_addr is always "0.0.0.0". How can I quickly/easily get the info for that particular socket? Sorry if that is elementary but I was never good with these APIs.
Thanks
Dan _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden