Watt-32 tcp/ip  2.2 dev-rel.10
Functions
bind.c File Reference

Go to the source code of this file.

Functions

int W32_CALL bind (int s, const struct sockaddr *myaddr, int namelen)
 bind() - bind name to socket. More...
 
int main (int argc, char **argv)
 

Detailed Description

BSD bind().

Definition in file bind.c.

Function Documentation

int W32_CALL bind ( int  s,
const struct sockaddr myaddr,
int  namelen 
)

bind() - bind name to socket.

The purpose of bind is to fill in the information for the local IP address and local port (local_addr). In this respect, it is the opposite of connect(). connect() fills in the destination IP address and destination port (remote_addr). In most situations, one does not need to call bind().

Calling bind() on a

Precondition
SOCK_DGRAM socket and for multiple addresses ('myaddr->sin_addr.s_addr == INADDR_ANY' ) requires special attention: Wattcp's 'udp_handler()' doesn't store address information for broadcast.

We therefore install a 's->dataHandler' pointing to '_recvdaemon()' which queues up SOCK_DGRAM messages. This queue is polled (by 'sock_recv_from()') when we call 'receive()' on such a socket. Thus the '*from' address in 'receive()' will be correctly set to source address/port of peer.

Todo:
check for "sleeping" ports (lport_inuse in pctcp.c) also. And return EADDRINUSE if local port not free.

Definition at line 63 of file bind.c.

References _inet6_ntoa(), _sock_chk_sockaddr(), _socklist_find(), _UDP6_listen(), and sin_mask.