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

Go to the source code of this file.

Data Structures

struct  sock_packet_buf
 
struct  sock_packet_pool
 
struct  Socket
 

Typedefs

typedef struct sock_packet_pool sock_packet_pool
 
typedef struct Socket Socket
 

Functions

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. More...
 
void _sock_crit_stop (void)
 Mark the end of a critical region. More...
 
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, size_t *fromlen)
 Called from receive.c for AF_PACKET sockets. More...
 
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. More...
 
Socket_socklist_find (int s)
 Returns a pointer to the Socket structure associated with socket 's'. More...
 
BOOL _sock_dos_fd (int s)
 _sock_dos_fd - Return TRUE if `s' is a valid DOS/Win32 handle. More...
 
int _sock_half_open (const _tcp_Socket *tcp)
 _sock_half_open - Return true if peer closed his side. More...
 
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'. More...
 
int _sock_set_rcv_buf (sock_type *s, size_t len)
 Setup a bigger receive buffer, the default in Wattcp is only 2k. More...
 
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. More...
 
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. More...
 
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 308 of file socket.c.

References _socklist_find().

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. Ref. http://cr.yp.to/syncookies.html
Todo:
Implement SYN-cookies and drop the segment if no match
Todo:
drop the oldest (or a random) slot in the listen-queue.

Definition at line 418 of file accept.c.

References _bsd_socket_hook(), _sock_set_rcv_buf(), _tcp_allsocs, tcp_Socket::last_acknum, tcp_Socket::last_seqnum, tcp_Socket::max_tx_data, tcp_Socket::my6addr, tcp_Socket::next, tcp_Socket::send_next, set_timeout(), tcp_recv_win, tcp_Socket::tx_buf, tcp_Socket::tx_data, tcp_Socket::tx_datalen, 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 1296 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.

Definition at line 1306 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 701 of file socket.c.

References _bsd_socket_hook(), _pkt_forced_rxmode, _pkt_rxmode, _sock_free_rcv_buf(), _socklist_find(), other_tcp_listeners(), RXMODE_BROADCAST, sk_list_del(), sock_abort(), and sock_raw_del().

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 222 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 2239 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 252 of file socket.c.

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 1534 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 2202 of file socket.c.

int _TCP6_open ( Socket socket,
const void host,
WORD  loc_port,
WORD  rem_port 
)
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 2067 of file socket.c.

References _sock_set_rcv_buf(), tcp_open(), and tcp_recv_win.

int _UDP6_listen ( Socket socket,
const void host,
WORD  port 
)
Todo:
Support UDP listen() for AF_INET6

Definition at line 2222 of file socket.c.

int _UDP6_open ( Socket socket,
const void host,
WORD  loc_port,
WORD  rem_port 
)
Todo:
Support UDP connect() for AF_INET6

Definition at line 2211 of file socket.c.

References _sock_set_rcv_buf().

unsigned sock_packet_receive ( Socket sock,
void buf,
unsigned  len,
struct sockaddr from,
size_t *  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 601 of file socket.c.

References _eth_get_hwtype(), and _pkt_ip_ofs.