• 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: determining if connection is local
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: determining if connection is local


  • Subject: Re: determining if connection is local
  • From: Quinn <email@hidden>
  • Date: Fri, 26 Sep 2003 09:49:57 +0100

At 18:03 -0600 25/9/03, Chaz McGarvey wrote:
So, what do you think about that?

That's weird. Before I suggested testing just for 127.0.0.1 I actually wrote a little test program to check my assumptions. Here's the code:

--------------------------------------------------------------------
int main (int argc, const char * argv[])
{
int listener;
int err;
int worker;
struct sockaddr_in addr;
int addrLen;

fprintf(stderr, "Hello Cruel World!\n");
listener = socket(AF_INET, SOCK_STREAM, 0);
memset(&addr, 0, sizeof(addr));
addr.sin_port = 12345;
err = bind(listener, (struct sockaddr *) &addr, sizeof(addr));
err = listen(listener, 10);
addrLen = sizeof(addr);

worker = accept(listener, (struct sockaddr *) &addr, &addrLen);

return 0;
}
--------------------------------------------------------------------

I ran this under GDB and used another Terminal window to connect to it using "telnet localhost 12345". The address returned by accept was 127.0.0.1.

Weird.

I'd be a *lot* happier if you used a Unix domain socket for local comms. The sockets API is pretty transport independent in this respect. To switch to a Unix domain socket all you need to do is change the first parameter of "socket" to AF_UNIX, change the server to bind to a path (in a sockaddr_un), and change the list to connect to that same path. The rest of your sockets code should work pretty much transparently.

S+E
--
Quinn "The Eskimo!" <http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
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.

  • Follow-Ups:
    • Re: determining if connection is local
      • From: Chaz McGarvey <email@hidden>
    • Re: determining if connection is local
      • From: "Matt Slot" <email@hidden>
References: 
 >Re: determining if connection is local (From: Chaz McGarvey <email@hidden>)

  • Prev by Date: Re: Using BSD sockets with MacOS 8 and 9
  • Next by Date: Re: determining if connection is local
  • Previous by thread: Re: determining if connection is local
  • Next by thread: Re: determining if connection is local
  • Index(es):
    • Date
    • Thread