06.08.2013 Views

pSOSystem System Calls - Read

pSOSystem System Calls - Read

pSOSystem System Calls - Read

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

ind pNA+ <strong>System</strong> <strong>Calls</strong><br />

bind Binds an address to a socket.<br />

#include <br />

long bind(<br />

int s, /* socket descriptor */<br />

struct sockaddr_in *addr, /* socket structure */<br />

int addrlen /* structure size */<br />

)<br />

Description<br />

Arguments<br />

This system call is used to assign (or bind) an address (a 32-bit internet address<br />

and a 16-bit port number) to a socket. A socket is created without an address and<br />

cannot be used to receive data until it is assigned one. Raw IP sockets are an<br />

exception. If they are unbound then they receive all packets regardless of the<br />

packet’s addresses.<br />

To simplify address binding, a wildcard internet address is supported to free the<br />

user from needing to know the local internet address. It also makes programs more<br />

portable. When the internet address is specified as the symbolic constant<br />

INADDR_ANY, pNA+ interprets it as any valid address. This allows the socket to<br />

receive data regardless of its node's internet address. For example, if a socket is<br />

bound to and it resides on a node that is attached to networks<br />

90.0.0.2 and 100.0.0.3, the socket can receive data addressed to <br />

or .<br />

s Specifies the socket to which the address is bound.<br />

addr Points to a structure of type sockaddr_in that stores the socket<br />

attributes to be bound to the socket. The structure sockaddr_in is<br />

defined in the file and has the following format:<br />

struct sockaddr_in {<br />

short sin_family; /* must be AF_INET */<br />

unsigned short sin_port; /* 16-bit port number */<br />

struct in_addr sin_addr; /* 32-bit IP address */<br />

char sin_zero[8]; /* must be 0 */<br />

};<br />

This structure cannot be packed.<br />

4-6 <strong>pSO<strong>System</strong></strong> <strong>System</strong> <strong>Calls</strong>

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!