• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Simplest way to get IP/Port?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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

  • Follow-Ups:
    • Re: Simplest way to get IP/Port?
      • From: Quinn <email@hidden>
    • RE: Simplest way to get IP/Port?
      • From: "Jamie Wood" <email@hidden>
  • Prev by Date: Re: How to Enumerate LAN for machines
  • Next by Date: Re: How to Enumerate LAN for machines
  • Previous by thread: Re: How to Enumerate LAN for machines
  • Next by thread: RE: Simplest way to get IP/Port?
  • Index(es):
    • Date
    • Thread