Watt-32 tcp/ip
2.2 dev-rel.10
|
Go to the source code of this file.
Functions | |
int | _fsext_demux (__FSEXT_Fnumber func, int *rv, va_list _args) |
long | _get_osfhandle (int) |
static __inline Socket * | sock_hash_get (int fd) |
static __inline void | sock_hash_add (int fd, Socket *sock) |
void * | _sock_calloc (size_t size, const char *file, unsigned line) |
Memory allocation; print some info if allocation fails. | |
static int | sock_alloc_fd (char **err) |
BOOL | _sock_dos_fd (int s) |
_sock_dos_fd - Return TRUE if `s' is a valid DOS/Win32 handle. 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. | |
static __inline Socket * | sk_list_del (int s) |
Deletes the list element associated with a socket. More... | |
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... | |
static __inline BOOL | other_tcp_listeners (const Socket *_this) |
Traverse socket-list to find other SOCK_STREAM sockets besides '_this' which are also listening. | |
void | _sock_set_syn_hook (int(*func)(_tcp_Socket **)) |
static __inline BOOL | other_raw_socks (const Socket *_this) |
Traverse socket-list to find other SOCK_RAW sockets besides '_this'. More... | |
BOOL | _sock_set_normal_rx_mode (const Socket *_this) |
BOOL | _sock_set_mcast_rx_mode (void) |
BOOL | _sock_set_promisc_rx_mode (void) |
static void | sock_raw_del (Socket *sock) |
Free buffers and hooks used by a SOCK_RAW socket. | |
static BOOL | sock_packet_add (Socket *sock) |
Allocate ringbuffer and rx-buffers for a SOCK_PACKET socket. | |
static void | sock_packet_del (Socket *sock) |
static int W32_CALL | sock_packet_peek (const union link_Packet *pkt) |
static char | get_pkt_type_eth (const eth_Header *eth) |
Return correct PACKET_xx type. | |
static char | get_pkt_type_fddi (const fddi_Header *fddi) |
static char | get_pkt_type_tok (const tok_Header *tok) |
static char | get_pkt_type_arc (const arcnet_Header *arc) |
static char | get_pkt_type (const union link_Packet *pkt) |
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) |
unsigned | sock_packet_transmit (Socket *socket, const void *buf, unsigned len, const struct sockaddr *to, int tolen) |
static void | sock_close_fd (int fd) |
Socket * | _sock_del_fd (int fd, const char *file, unsigned line) |
Delete the socket from `inuse' array and all memory associated with it. More... | |
static int | sock_find_fd (const Socket *socket) |
Finds the 'fd' associated with pointer 'socket'. More... | |
static Socket * | sock_find_udp (const _udp_Socket *udp) |
Finds the 'Socket' associated with udp-socket 'udp'. More... | |
static void * | sock_find_tcp (const _tcp_Socket *tcp) |
Finds the 'Socket*' associated with tcp-socket '*tcp'. | |
int | _sock_chk_sockaddr (Socket *socket, const struct sockaddr *sa, int len) |
Check `sockaddr*' passed to bind/connect. | |
static struct _raw_Socket * | find_free_raw_sock (Socket *sock) |
Search in sock->raw?_sock list for an unused raw-buffer. | |
static struct _raw6_Socket * | find_free_raw6_sock (Socket *sock) |
static int | sock_raw4_recv (const in_Header *ip) |
Called from _ip4_handler() via `_bsd_socket_hook'. More... | |
static int | sock_raw6_recv (const in6_Header *ip) |
static void | do_keepalive (Socket *sock) |
Handle keepalive on STREAM socket. More... | |
static void *MS_CDECL | socket_op_demux (enum BSD_SOCKET_OPS op,...) |
The demultiplexer for callback operations called via '_bsd_socket_hook' from functions in the core Wattcp API. | |
static Socket * | tcp_sock_daemon (Socket *sock) |
Called by sock_daemon() to handle SOCK_STREAM sockets. More... | |
static Socket * | udp_sock_daemon (Socket *sock) |
Called by sock_daemon() for SOCK_DGRAM sockets. More... | |
static void | sock_daemon (void) |
A daemon called from tcp_tick(). More... | |
void | _sock_crit_start (void) |
Start a critical region. More... | |
void | _sock_crit_stop (void) |
Mark the end of a critical region. More... | |
static void | sock_fortify_exit (void) |
Exit handler for Fortify. More... | |
static const char * | vendor_version (void) |
Return version string of current compiler. | |
static void | check_errno_version (void) |
Check that . More... | |
static BOOL | init_sockets (void) |
Main initialisation routine for the BSD socket API. More... | |
Socket * | _socklist_find (int s) |
Returns a pointer to the Socket structure associated with socket 's'. More... | |
static BOOL | sock_raw_add (Socket *sock, int family) |
Allocate raw?_Socket buffers for a SOCK_RAW socket. | |
static Socket * | socklist_add (int s, int type, int proto, int family) |
Adds a new socket to the sk_list. | |
static int | set_proto (int type, BOOL is_ip6, int *proto) |
Select (and check) a suitable protocol for socket-type. More... | |
static const char * | proto_name (int proto) |
int W32_CALL | socket (int family, int type, int protocol) |
socket(). More... | |
static int | stream_cancel (const _tcp_Socket *tcp, BYTE icmp_type, int error) |
Callback handlers for "ICMP Port/Host/Network Unreachable" or "ICMP Parameter Problem" issued by lower layer (udp_cancel() and tcp_cancel() in pctcp.c) More... | |
static int | dgram_cancel (const _udp_Socket *udp, BYTE icmp_type, int error) |
static __inline const char * | ip_proto_str (WORD prot) |
static int | icmp_callback (sock_type *s, BYTE icmp_type, BYTE icmp_code) |
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 | _UDP_listen (Socket *socket, struct in_addr host, WORD 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. More... | |
int | _TCP_listen (Socket *socket, struct in_addr host, WORD port) |
int | _TCP6_open (Socket *socket, const void *dst, WORD loc_port, WORD rem_port) |
int | _TCP6_listen (Socket *socket, const void *host, WORD loc_port) |
int | _UDP6_open (Socket *socket, const void *host, WORD loc_port, WORD rem_port) |
int | _UDP6_listen (Socket *socket, const void *host, WORD port) |
int | _sock_half_open (const _tcp_Socket *s) |
_sock_half_open - Return true if peer closed his side. More... | |
int W32_CALL | socketpair (int family, int type, int protocol, int usockvec[2]) |
socketpair() - Create a pair of connected sockets. More... | |
Variables | |
static int | sk_block = 0 |
static int | sk_last = SK_FIRST+1 |
static Socket * | sk_list = NULL |
static DWORD | raw_seq = 0 |
static int(* | tcp_syn_hook )(_tcp_Socket **tcp) = NULL |
static int(* | ip4_raw_hook )(const in_Header *ip) = NULL |
static int(* | ip6_raw_hook )(const in6_Header *ip) = NULL |
static Socket * | sk_hashes [SOCK_HASH_SIZE] |
static fd_set | inuse [NUM_SOCK_FDSETS] |
`inuse[]' has a non-zero bit for each socket-descriptor in use. More... | |
static BOOL | mcast_set = FALSE |
Switch back to normal rx-mode (RXMODE_BROADCAST) if no multicasts active and no more IPv6/SOCK_PACKET sockets besides '_this'. | |
static BOOL | promis_set = FALSE |
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().
Start a critical region.
Prevent `sk_list' being destroyed (e.g. in sock_daemon) and thus confusing select_s(), connect() etc.
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 | ) |
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 | ||
) |
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().
<
Definition at line 2110 of file socket.c.
References _default_ttl, _eth_is_init, _inet6_ntoa(), _sock_set_rcv_buf(), _tcp_allsocs, _tcp_unthread(), tcp_Socket::cwindow, tcp_Socket::flags, tcp_Socket::his6addr, icmp6_neigh_solic(), tcp_Socket::max_seg, tcp_Socket::my6addr, my_ip_addr, tcp_Socket::next, tcp_Socket::rto, tcp_Socket::rtt_time, tcp_Socket::safetysig, tcp_Socket::safetytcp, tcp_Socket::send_next, set_timeout(), tcp_Socket::state, tcp_nagle, tcp_OPEN_TO, tcp_recv_win, tcp_Socket::timeout, tcp_Socket::unhappy, tcp_Socket::vj_sa, and tcp_Socket::wwindow.
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.
Definition at line 2211 of file socket.c.
References _sock_set_rcv_buf().
Check that .
/util/xx_err.exe is built with same version we're using here. Print a warning if there's a mismatch.
Definition at line 1457 of file socket.c.
References vendor_version().
Handle keepalive on STREAM socket.
Not complete; doesn't consider tcp_max_idle.
Definition at line 1063 of file socket.c.
References _tcp_keepalive(), chk_timeout(), set_timeout(), and tcp_keep_idle.
|
static |
Main initialisation routine for the BSD socket API.
Called only once to do:
Definition at line 1483 of file socket.c.
References _watt_do_exit, check_errno_version(), sock_daemon(), sock_fortify_exit(), and watt_sock_init().
|
static |
|
static |
Select (and check) a suitable protocol for socket-type.
<
Definition at line 1685 of file socket.c.
References _pkt_errno, pkt_strerror(), and sock_raw4_recv().
|
static |
A daemon called from tcp_tick().
Called every DAEMON_PERIOD (500 msec) to perform cleanup of bound SOCK_STREAM and SOCK_DGRAM sockets still in use.
Definition at line 1256 of file socket.c.
References tcp_sock_daemon(), and udp_sock_daemon().
|
static |
|
static |
Exit handler for Fortify.
Traverse all sockets and print some state and memory statistics.
Definition at line 1326 of file socket.c.
References tcp_Socket::state.
unsigned sock_packet_receive | ( | Socket * | sock, |
void * | buf, | ||
unsigned | len, | ||
struct sockaddr * | from, | ||
size_t * | fromlen | ||
) |
Called from receive.c for AF_PACKET sockets.
Definition at line 601 of file socket.c.
References _eth_get_hwtype(), and _pkt_ip_ofs.
|
static |
Called from _ip4_handler() via `_bsd_socket_hook'.
IP-header is already checked in `_ip4_handler()'. Finds all 'Socket' associated with raw IP-packet 'ip'. Enqueue to 'sock->raw_sock'. Return >=1 if 'ip' is consumed, 0 otherwise.
Definition at line 925 of file socket.c.
References find_free_raw_sock(), _raw_Socket::rx_data, _raw_Socket::seq_num, and _raw_Socket::used.
int W32_CALL socket | ( | int | family, |
int | type, | ||
int | protocol | ||
) |
The | socket ID number |
Definition at line 1794 of file socket.c.
References _bsd_socket_hook(), init_sockets(), set_proto(), socket_op_demux(), and socklist_add().
int W32_CALL socketpair | ( | int | family, |
int | type, | ||
int | protocol, | ||
int | usockvec[2] | ||
) |
socketpair() - Create a pair of connected sockets.
Modified version based on Linux's version.
|
static |
Callback handlers for "ICMP Port/Host/Network Unreachable" or "ICMP Parameter Problem" issued by lower layer (udp_cancel() and tcp_cancel() in pctcp.c)
We should drop (i.e. set ECONNREFUSED in lack of a better errno) on receiving "ICMP-param problem" or "ICMP-unreachable" reached stress-level.
Definition at line 1912 of file socket.c.
References socket().
Called by sock_daemon() to handle SOCK_STREAM sockets.
Unlink the socket from the linked list if application has read all data and tcp_state has become CLOSED and the linger period has expired.
Definition at line 1169 of file socket.c.
References _sock_free_rcv_buf(), do_keepalive(), sock_fastread(), and tcp_Socket::state.
Called by sock_daemon() for SOCK_DGRAM sockets.
Unlink the socket from the linked list if application has read all data and "state" is disconnecting.
|
static |
`inuse[]' has a non-zero bit for each socket-descriptor in use.
There can be max `MAX_SOCKETS' allocated at any time. Dead stream sockets will be unlinked by `sock_daemon()' in due time.
Non-djgpp targets: Allocate a new descriptor (handle) by searching through `inuse' for the first zero bit. Update `sk_last' as needed.
djgpp target: Allocate a descriptior from the "File System Extension" layer. `sk_last' is not used (initialised to MAX_SOCKETS). Thus max # of sockets are limited by max # of DOS handles that can be created.