• 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
RE: Simplest way to get IP/Port?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Simplest way to get IP/Port?


  • Subject: RE: Simplest way to get IP/Port?
  • From: "Jamie Wood" <email@hidden>
  • Date: Mon, 30 May 2005 18:54:10 -0700

INADDR_ANY is defined to be 0, or 0.0.0.0. It means that other computers can connect to your program using any IP address that is assigned to your computer. You need to simply "give out" one of these addresses.

Hope this helps,
Jamie

From: Dan Gelder <email@hidden>
To: email@hidden
Subject: Simplest way to get IP/Port?
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


_______________________________________________
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


References: 
 >Simplest way to get IP/Port? (From: Dan Gelder <email@hidden>)

  • Prev by Date: Re: How to Enumerate LAN for machines
  • Next by Date: Re: Simplest way to get IP/Port?
  • Previous by thread: Simplest way to get IP/Port?
  • Next by thread: Re: Simplest way to get IP/Port?
  • Index(es):
    • Date
    • Thread