www.delorie.com/gnu/docs/glibc/libc_304.html   search  
 
Buy the book!


The GNU C Library

[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

16.3 Socket Addresses

The name of a socket is normally called an address. The functions and symbols for dealing with socket addresses were named inconsistently, sometimes using the term "name" and sometimes using "address". You can regard these terms as synonymous where sockets are concerned.

A socket newly created with the socket function has no address. Other processes can find it for communication only if you give it an address. We call this binding the address to the socket, and the way to do it is with the bind function.

You need be concerned with the address of a socket if other processes are to find it and start communicating with it. You can specify an address for other sockets, but this is usually pointless; the first time you send data from a socket, or use it to initiate a connection, the system assigns an address automatically if you have not specified one.

Occasionally a client needs to specify an address because the server discriminates based on address; for example, the rsh and rlogin protocols look at the client's socket address and only bypass password checking if it is less than IPPORT_RESERVED (see section 16.6.3 Internet Ports).

The details of socket addresses vary depending on what namespace you are using. See section 16.5 The Local Namespace, or 16.6 The Internet Namespace, for specific information.

Regardless of the namespace, you use the same functions bind and getsockname to set and examine a socket's address. These functions use a phony data type, struct sockaddr *, to accept the address. In practice, the address lives in a structure of some other data type appropriate to the address format you are using, but you cast its address to struct sockaddr * when you pass it to bind.

16.3.1 Address Formats  About struct sockaddr.
16.3.2 Setting the Address of a Socket  Binding an address to a socket.
16.3.3 Reading the Address of a Socket  Reading the address of a socket.


[ < ] [ > ]   [ << ] [ Up ] [ >> ]         [Top] [Contents] [Index] [ ? ]

  webmaster     delorie software   privacy  
  Copyright 2003   by The Free Software Foundation     Updated Jun 2003