Main Page | Alphabetical List | Data Structures | File List | Data Fields | Globals | Related Pages

SRC/socket.h File Reference


Detailed Description

Definition in file socket.h.

Go to the source code of this file.

Data Structures

struct  sock_packet_buf
struct  sock_packet_pool
struct  Socket

Typedefs

typedef sock_packet_pool sock_packet_pool
typedef Socket Socket

Functions

W32_FUNC int close_s (int s)
W32_FUNC int write_s (int s, const char *buf, int num)
W32_FUNC int writev_s (int s, const struct iovec *vec, size_t num)
W32_FUNC int recvmsg (int s, struct msghdr *msg, int flags)
W32_FUNC int read_s (int s, char *buf, int num)
W32_FUNC int select_s (int n, fd_set *r, fd_set *w, fd_set *x, struct timeval *t)
 The select_s() function.
W32_FUNC int W32_CALL select (int num_sockets, fd_set *read_events, fd_set *write_events, fd_set *except_events, struct timeval *timeout)
int _sock_sig_setup (void)
int _sock_sig_restore (void)
int _sock_sig_pending (void)
int _sock_sig_epipe (const Socket *s)
void _sock_crit_start (void)
 Start a critical region.
void _sock_crit_stop (void)
 Mark the end of a critical region.
void _sock_start_timer (void)
void _sock_stop_timer (void)
unsigned sock_packet_transmit (Socket *sock, const void *buf, unsigned len, const struct sockaddr *to, int tolen)
unsigned sock_packet_receive (Socket *sock, void *buf, unsigned len, struct sockaddr *from, int *fromlen)
 Called from receive.c for AF_PACKET sockets.
unsigned sock_packet_rbused (Socket *sock)
void * _sock_calloc (size_t size, const char *file, unsigned line)
 Memory allocation; print some info if allocation fails.
Socket * _sock_del_fd (int sock, const char *file, unsigned line)
 Delete the socket from `inuse' array and all memory associated with it.
Socket * _socklist_find (int s)
 Returns a pointer to the Socket structure associated with socket 's'.
BOOL _sock_dos_fd (int s)
 _sock_dos_fd - Return TRUE if `s' is a valid DOS/Win32 handle.
int _sock_half_open (const _tcp_Socket *tcp)
 _sock_half_open - Return true if peer closed his side.
int _sock_append (_tcp_Socket **tcp)
 Called from tcp_fsm.c / tcp_listen_state() (via _bsd_socket_hook) to append a new connection to the listen-queue of socket 'sock'.
int _sock_set_rcv_buf (sock_type *s, size_t len)
 Setup a bigger receive buffer, the default in Wattcp is only 2k.
void _sock_free_rcv_buf (sock_type *s)
 Free receive buffer associated with udp/tcp sockets.
void _sock_set_syn_hook (int(*func)(_tcp_Socket **))
BOOL _sock_set_promisc_rx_mode (void)
BOOL _sock_set_mcast_rx_mode (void)
BOOL _sock_set_normal_rx_mode (const Socket *_this)
const sock_type__get_sock_from_s (int s, int proto)
 Hack function if user application needs to use Wattcp core functions for BSD sockets.
void __get_ifname (char *if_name)
void __set_ifname (const char *if_name)
int __scope_ascii_to_id (const char *str)
int __scope_id_to_ascii (int scope)
int _sock_chk_sockaddr (Socket *socket, const struct sockaddr *sa, int len)
 Check `sockaddr*' passed to bind/connect.
int _TCP_open (Socket *socket, struct in_addr host, WORD loc_port, WORD rem_port)
 Open and listen routines for SOCK_STREAM at the socket-level.
int _UDP_open (Socket *socket, struct in_addr host, WORD loc_port, WORD rem_port)
 Open and listen routines for SOCK_DGRAM at the socket-level.
int _TCP_listen (Socket *socket, struct in_addr host, WORD loc_port)
int _UDP_listen (Socket *socket, struct in_addr host, WORD port)
int _TCP6_open (Socket *socket, const void *host, WORD loc_port, WORD rem_port)
int _UDP6_open (Socket *socket, const void *host, WORD loc_port, WORD rem_port)
int _TCP6_listen (Socket *socket, const void *host, WORD loc_port)
int _UDP6_listen (Socket *socket, const void *host, WORD port)


Function Documentation

const sock_type* __get_sock_from_s int  s,
int  proto
 

Hack function if user application needs to use Wattcp core functions for BSD sockets.

Must *not* modify return value in any way. Definition at line 293 of file SOCKET.C.

int _sock_append _tcp_Socket **  tcp  ) 
 

Called from tcp_fsm.c / tcp_listen_state() (via _bsd_socket_hook) to append a new connection to the listen-queue of socket 'sock'.

TCB on input ('orig') has received a SYN. Replace TCB on output with a cloned TCB that we append to the listen-queue and eventually is used by accept() to create a new socket.

TCB on input ('orig') must still be listening for further connections on the same port as specified in call to _TCP_listen().

Todo:
Implement SYN-cookies. http://cr.yp.to/syncookies.html

Todo:
Implement SYN-cookies and drop the segment if no match

drop the oldest (or a random) slot in the listen-queue.

Definition at line 419 of file ACCEPT.C.

References _bsd_socket_hook(), _sock_set_rcv_buf(), _tcp_allsocs, _tcp_Socket::last_acknum, _tcp_Socket::last_seqnum, _tcp_Socket::my6addr, _tcp_Socket::send_next, set_timeout(), tcp_recv_win, and _tcp_Socket::unhappy.

void _sock_crit_start void   ) 
 

Start a critical region.

Prevent `sk_list' being destroyed (e.g. in sock_daemon) and thus confusing select_s(), connect() etc. Definition at line 1282 of file SOCKET.C.

void _sock_crit_stop void   ) 
 

Mark the end of a critical region.

If blocking-level reached zero, we run our socket-daemon.

Todo:
handle SIGALRM raised in a critical-section
Definition at line 1292 of file SOCKET.C.

References sock_daemon().

Socket* _sock_del_fd int  fd,
const char *  file,
unsigned  line
 

Delete the socket from `inuse' array and all memory associated with it.

Also unlink it from the socket list (sk_list). Clear _tcp_syn_hook is no more SOCK_STREAM listeners. Return pointer to next node in list or NULL if none/error. Definition at line 686 of file SOCKET.C.

References _bsd_socket_hook(), _pkt_rxmode, _sock_free_rcv_buf(), _socklist_find(), inuse, other_tcp_listeners(), RXMODE_BROADCAST, sk_list_del(), sock_abort(), sock_raw_del(), sock_type::tcp, and sock_type::udp.

BOOL _sock_dos_fd int  s  ) 
 

_sock_dos_fd - Return TRUE if `s' is a valid DOS/Win32 handle.

Used to differentiate EBADF from ENOTSOCK.

Note: for non-djgpp targets `s' may have same value as a DOS-handle. This function should only be used when `s' isn't found in `sk_list'. Definition at line 213 of file SOCKET.C.

int _sock_half_open const _tcp_Socket s  ) 
 

_sock_half_open - Return true if peer closed his side.

There might still be data to read Definition at line 2167 of file SOCKET.C.

References _tcp_Socket::state.

int _sock_set_rcv_buf sock_type s,
size_t  len
 

Setup a bigger receive buffer, the default in Wattcp is only 2k.

Note:
If calloc() fails, sock_setbuf() reverts to default 2kB socket buffer.

Todo:
allow user to define size using SO_RCVBUF/SO_SNDBUF before calling connect().
Definition at line 243 of file SOCKET.C.

References BYTE.

Socket* _socklist_find int  s  ) 
 

Returns a pointer to the Socket structure associated with socket 's'.

If socket `s' was not found, NULL is returned. Definition at line 1500 of file SOCKET.C.

References init_sockets().

int _TCP6_listen Socket *  socket,
const void *  host,
WORD  loc_port
 

Todo:
Support TCP listen() for AF_INET6
Definition at line 2130 of file SOCKET.C.

References socket(), and WORD.

int _TCP6_open Socket *  socket,
const void *  dst,
WORD  loc_port,
WORD  rem_port
 

Todo:
use mss from setsockopt()

Yield for IPv6 sockets

use TCP_NODELAY set in setsockopt()

< Definition at line 2038 of file SOCKET.C.

References _default_ttl, _eth_is_init, _inet6_ntoa(), _sock_set_rcv_buf(), _tcp_allsocs, _tcp_unthread(), icmp_upcall, my_ip_addr, set_timeout(), socket(), tcp_nagle, tcp_OPEN_TO, tcp_recv_win, UINT, and WORD.

int _TCP_open Socket *  socket,
struct in_addr  host,
WORD  loc_port,
WORD  rem_port
 

Open and listen routines for SOCK_STREAM at the socket-level.

The parameters to tcp_open() is a bit tricky, but the internal Wattcp socket 's' contains the following elements that must match in the first 'for-loop' of _tcp_handler().

s->hisport != 0 i.e. active (non-listening) port s->myaddr == ip->destination, our IP-address s->hisaddr == ip->source, above 'dest' address s->myport == tcp->dstPort, above 'loc_port' s->hisport == tcp->srcPort, above 'rem_port' Definition at line 1995 of file SOCKET.C.

References _sock_set_rcv_buf(), DWORD, icmp_upcall, socket(), tcp_open(), tcp_recv_win, and WORD.

int _UDP6_listen Socket *  socket,
const void *  host,
WORD  port
 

Todo:
Support UDP listen() for AF_INET6
Definition at line 2150 of file SOCKET.C.

References socket(), and WORD.

int _UDP6_open Socket *  socket,
const void *  host,
WORD  loc_port,
WORD  rem_port
 

Todo:
Support UDP connect() for AF_INET6
Definition at line 2139 of file SOCKET.C.

References _sock_set_rcv_buf(), icmp_upcall, socket(), and WORD.

W32_FUNC int select_s int  nfds,
fd_set *  readfds,
fd_set *  writefds,
fd_set *  exceptfds,
struct timeval *  timeout
 

The select_s() function.

Note:
It supports more sockets than would fit in a fd_set. I.e. it handles an array of 'fd_set's on input/output. Thus it is the user's responsibilty to not use a too high 'nfds' value. I.e. If nfs > 512*8 and user fd_set's on input is smaller than 512*, select_s() could trash the fd_set's on output.

Clear our "working" fd_sets.

Note:
Don't use FD_ZERO() since our working fd_sets contain more than FD_SETSIZE sockets.
Definition at line 112 of file select.c.

unsigned sock_packet_receive Socket *  sock,
void *  buf,
unsigned  len,
struct sockaddr *  from,
int *  fromlen
 

Called from receive.c for AF_PACKET sockets.

Todo:
This should loop until some packet is received.

Todo:
should check fromlen is large enough
Definition at line 586 of file SOCKET.C.

References _eth_get_hwtype(), _pkt_ip_ofs, BYTE, and WORD.


Generated on Wed Aug 4 08:55:58 2010 for Watt-32 tcp/ip by doxygen 1.3.8