Watt-32 tcp/ip  2.2 dev-rel.10
Data Structures | Functions
socket.h File Reference

Go to the source code of this file.

Data Structures

struct  linger
struct  sockaddr
struct  sockproto
struct  cmsghdr
struct  msghdr


__BEGIN_DECLS W32_FUNC int W32_CALL accept (int, struct sockaddr *, int *)
W32_FUNC int W32_CALL bind (int, const struct sockaddr *, int)
 bind() - bind name to socket. More...
W32_FUNC int W32_CALL closesocket (int s)
W32_FUNC int W32_CALL connect (int, const struct sockaddr *, int)
W32_FUNC int W32_CALL ioctlsocket (int s, long cmd, char *argp)
W32_FUNC int MS_CDECL fcntlsocket (int s, int cmd,...)
W32_FUNC int W32_CALL getdomainname (char *name, size_t len)
Return domain name of this host. More...
W32_FUNC int W32_CALL setdomainname (const char *name, size_t len)
Set the host's domain name. More...
W32_FUNC int W32_CALL getpeername (int, struct sockaddr *, int *)
W32_FUNC int W32_CALL getsockname (int, struct sockaddr *, int *)
W32_FUNC int W32_CALL getsockopt (int, int, int, void *, int *)
W32_FUNC int W32_CALL listen (int, int)
W32_FUNC int W32_CALL recv (int, void *, int, int)
W32_FUNC int W32_CALL recvfrom (int, void *, int, int, struct sockaddr *, int *)
W32_FUNC int W32_CALL recvmsg (int, struct msghdr *, int)
W32_FUNC int W32_CALL send (int, const void *, int, int)
W32_FUNC int W32_CALL sendto (int, const void *, int, int, const struct sockaddr *, int)
W32_FUNC int W32_CALL sendmsg (int, const struct msghdr *, int)
W32_FUNC int W32_CALL setsockopt (int, int, int, const void *, int)
W32_FUNC int W32_CALL shutdown (int, int)
W32_FUNC int W32_CALL socket (int, int, int)
 socket(). More...
W32_FUNC int W32_CALL gethostname (char *name, int len)
W32_FUNC int W32_CALL gethostname (char *name, size_t len)
W32_FUNC long W32_CALL gethostid (void)
 BSD style: returns local IPv4-address. More...
W32_FUNC long W32_CALL sethostid (u_long ip)
W32_FUNC int W32_CALL sethostname (const char *name, size_t len)
W32_FUNC int W32_CALL sethostname (const char *name, int len)

Detailed Description

BSD socket API.

Definition in file socket.h.

Function Documentation

__BEGIN_DECLS W32_FUNC int W32_CALL accept ( int  ,
struct sockaddr ,
int *   
Should maybe loop over all maxconn TCBs and accept the one with oldest 'syn_timestamp'.

Definition at line 59 of file accept.c.

References _inet6_ntoa(), _sock_crit_start(), _sock_crit_stop(), _sock_free_rcv_buf(), _socklist_find(), _tcp_unthread(), chk_timeout(), tcp_Socket::his6addr, set_timeout(), sock_noflush(), socket(), tcp_Socket::state, and tcp_tick().

W32_FUNC 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

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.

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.

W32_FUNC int MS_CDECL fcntlsocket ( int  s,
int  cmd,
handle O_TEXT and O_BINARY

Definition at line 69 of file fcntl.c.

References _socklist_find(), list_lookup(), and tcp_Socket::timeout.

W32_FUNC int W32_CALL getdomainname ( char *  buffer,
size_t  buflen 

Return domain name of this host.

As per BSD spec, the resultant buffer ... ... "will be null-terminated _unless_there_is_insufficient_space_";

Set errno on failure and return -1.

Definition at line 186 of file bsdname.c.

W32_FUNC long W32_CALL gethostid ( void  )

BSD style: returns local IPv4-address.

Return values
addresson network order.

Definition at line 68 of file bsdname.c.

References my_ip_addr, and netdb_init().

W32_FUNC int W32_CALL setdomainname ( const char *  name,
size_t  len 

Set the host's domain name.

Set errno on failure and return -1.

Definition at line 213 of file bsdname.c.

References _strlcpy(), and defaultdomain.

W32_FUNC int W32_CALL shutdown ( int  ,
For tcp, should send RST if we get incoming data. Don't send ICMP error.
For tcp, should send FIN when all Tx data has been ack'ed. close_s(s) should be same as shutdown(s,SHUT_WR)

Definition at line 46 of file shutdown.c.

References _socklist_find().

W32_FUNC int W32_CALL socket ( int  family,
int  type,
int  protocol 


  • family The protocol family. Supports the AF_INET, AF_INET6, AF_PACKET families.
  • type SOCK_STREAM (tcp), SOCK_DGRAM (udp), SOCK_RAW (ip) or SOCK_PACKET (link).
Return values
Thesocket ID number

Definition at line 1794 of file socket.c.

References _bsd_socket_hook(), init_sockets(), set_proto(), socket_op_demux(), and socklist_add().