[lug] source for bind(int sockfd, struct sockaddr *my_addr, int addrlen)

rm at mamma.varadinet.de rm at mamma.varadinet.de
Tue Apr 17 18:36:44 MDT 2001


On Tue, Apr 17, 2001 at 05:44:25PM -0600, Matt McIllece (1-3762) wrote:
> Can someone tell me where the source is for the function that binds a name to a 
> socket?

A socket is never 'bound' to a name. A tcp socket (i assume you talk
about a IP-Socket here, not a Unix-socket) is defined by it's address
and it's port number. The names that are commonly used to refer to hosts
are only meant for us humble humans--the network stack doesn't know
(or care) about these names. If you need to asociate a name with an
IP address you need to create an entry in the DNS database, usually either
by setting up your own DNS zone and running your own name server or by having
someone else create an DNS entry in their servers database.
Think of it this way: the combination of IP-address and port number acts
like a telephone number--both together will uniquely identify a network
connecting point on a server. BTW, since DNS names (like www.host.com)
only map to IP-addresses (and _not_ to ports) they do not identify a network
connecting point. Many ports can be open on the same machine (and many sockets
on the same port, once a connection is established).

> I downloaded bind-9.2.0s20010214.tar.gz and looked all through 
> bind-9.2.0s20010214.  The best I could do was find a function that calls bind() 
> itself (bind-9.2.0s20010214/contrib/idn/mdnkit/dnsproxy/server.c).

The application 'bind' whose code you downloaded is a name server, i.e.
a special database that will answer questions like: "what is the IP
address of the host called pengu.corporation.com?" As i said earlier, this is
a convenience for humans that can't remember long numbers (to be fair, it
also provides the means for an abstraction between physical hosts and 
services seen by the outside world. Several hosts can share the same name).

The function 'bind' that you found doesn't bind a name to a socket but
binds a socket to an address (try 'man 2 bind' on a Unix/Linux system ).

> 
> I also looked under /usr/src/linux, but didn't find bind() implemented there 
> either.

Oh, that's just the kernel. The functions you need to look at are in
the C library (or libc as it's commonly called ;-) 

You would want to read up a bit on linux/unix networking. There are two
ways of doing this: you can browse through the man pages (start with
bind, socket, connect, accept etc. ) and read the gnu info pages on the
c library or get some books (which i find easier). Some starting points 
would be (very personal choice):

 - DNS and Bind from OReilly
   Basic introduction and instructions for the Domain Name Sytem

 - Beginning Linux Programming (Wrox Press) 
   Covers everything from the shell to sockets etc.
 
 - Stevens: Unix Network Programming. Expensive but one
   of my favourite books. This starts with simple examples
   but covers a lot -- and the code examples alone are worth the
   money. 

 If your local library has it, have a look at TCP/IP illustrated
 by Stevens. This might be overkill for your actuall problem but
 a good understanding of the inner workings of (inter)networking
 helps a lot.


  Ralf

> TIA,
> Matt
> 
> _______________________________________________
> Web Page:  http://lug.boulder.co.us
> Mailing List: http://lists.lug.boulder.co.us/mailman/listinfo/lug



More information about the LUG mailing list