Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 10 May 1999 11:38:50 -0700
From:      "Justin C. Walker" <justin@apple.com>
To:        Zhihui Zhang <zzhang@cs.binghamton.edu>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: Sockets and SYSTEM V message queue
Message-ID:  <199905101838.LAA00711@rhapture.apple.com>

next in thread | raw e-mail | index | archive | help
> From: Zhihui Zhang <zzhang@cs.binghamton.edu>
> Date: 1999-05-10 11:11:45 -0700
> To: freebsd-hackers@FreeBSD.ORG
> Subject: Sockets and SYSTEM V message queue
> Delivered-to: freebsd-hackers@freebsd.org
> X-Loop: FreeBSD.ORG
>
>
> My impression is that whenever you create a socket, you bind to some IP 
> address.  If you creates two sockets on the same machine, these two 
> sockets will bind to the same IP address (assuming that the machine has 
> only one NIC). When these two sockets communicate with each other,  
the OS
> should be smart enough to figure out that they associated with the  
same IP
> address and therefore do not actually send packets out to the network.  
>
> If this is the case, why do we bind a socket to an IP address.  I mean, 
> the sockets should be able to be used alone.  If they have to be  
bound to
> an IP address to be used, why do not we use message queue of SYS V?  If 
> so, which mechanism is better - message queue or standalone socket? 

Typically, the "server" (receiver) end of the initiated connection  
will bind either to INADDR_ANY, with a well-known port.  If the  
server is really concerned with networking details, it might  
determine the addresses and interfaces on the system, and bind  
separately to each.  The client (initiator) will generally always  
bind to INADDR_ANY, and let the system choose a port.

One reason to use IP is that you may, in the future, want to run the  
two pieces on different systems.  If so, you can do it without code  
changes.

If your app is always going to run on a single system, there are  
better ways to implement it.  Local-domain sockets is one; pipes is  
another (which may or may not be implemented with local-domain  
sockets).  SysV message queues could be used as well.  Don't know  
enough about their limitations to know whether it's a good choice,  
though.

Also, even tho the binds are done with INADDR_ANY, at the time a  
connection is made, a real address is assigned.  This is how IP  
works.  Why is this a problem?

Regards,

Justin

--
Justin C. Walker, Curmudgeon-At-Large *
Institute for General Semantics       |
Manager, CoreOS Networking            |   Men are from Earth.
Apple Computer, Inc.                  |   Women are from Earth.
2 Infinite Loop                       |       Deal with it.
Cupertino, CA 95014                   |
*-------------------------------------*-------------------------------*


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199905101838.LAA00711>