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

Go to the source code of this file.

Data Structures

struct  tcp_Socket
 
struct  udp_Socket
 
struct  config_table
 
struct  DHCP_config
 
struct  watt_sockaddr
 
struct  PktStats
 
struct  PktParameters
 
struct  PktParameters
 

Typedefs

typedef void sock_type
 
typedef void in_Header
 
typedef void udp_Header
 
typedef void tcp_Header
 
typedef const struct config_tablecfg
 

Enumerations

enum  config_tab_types {
  ARG_ATOI,
  ARG_ATOB,
  ARG_ATOW,
  ARG_ATOIP,
  ARG_ATOX_B,
  ARG_ATOX_W,
  ARG_ATOX_D,
  ARG_STRDUP,
  ARG_STRCPY,
  ARG_RESOLVE,
  ARG_FUNC
}
 
enum  DHCP_config_op {
  DHCP_OP_READ = 0,
  DHCP_OP_WRITE = 1,
  DHCP_OP_ERASE = 2
}
 
enum  CHK_SOCKET_VAL {
  VALID_UDP = 1,
  VALID_TCP,
  VALID_IP4,
  VALID_IP6
}
 
enum  TCP_SIMPLE_STATE {
  TCP_CLOSED,
  TCP_LISTENING,
  TCP_OPENING,
  TCP_OPEN,
  TCP_CLOSING
}
 
enum  _watt_optmode {
  GETOPT_UNIX,
  GETOPT_ANY,
  GETOPT_KEEP
}
 

Functions

W32_FUNC const char *W32_CALL wattcpVersion (void)
 Return string for Watt-32 version. More...
 
W32_FUNC const char *W32_CALL wattcpCapabilities (void)
 Return compiled-in capabilities and features. More...
 
W32_FUNC const char *W32_CALL wattcpBuildCC (void)
 Return the target/compiler.
 
W32_FUNC const char *W32_CALL wattcpBuildCCexe (void)
 Return the the name if the compiler used. More...
 
W32_FUNC const char *W32_CALL wattcpBuildCflags (void)
 Return the used. More...
 
W32_FUNC int W32_CALL watt_sock_init (size_t tcp_Sock_size, size_t udp_Sock_size, size_t time_t_size)
 
W32_FUNC const char *W32_CALL sock_init_err (int rc)
 
W32_FUNC void MS_CDECL sock_exit (void)
 Our only atexit() handler. More...
 
W32_FUNC void W32_CALL dbug_init (void)
 
W32_FUNC void W32_CALL init_misc (void)
 Initialise various stuff. More...
 
W32_FUNC void W32_CALL sock_sig_exit (const char *msg, int sigint)
 Exit handler for unhandled signals.
 
W32_FUNC void W32_CALL assert_fail_test (void)
 
W32_FUNC void W32_CALL abort_test (void)
 
W32_FUNC void W32_CALL leak_test (void)
 
W32_FUNC void W32_CALL except_test (void)
 
W32_FUNC int W32_CALL sock_read (sock_type *s, BYTE *dp, size_t len)
 Read a socket with maximum 'maxlen' bytes. More...
 
W32_FUNC int W32_CALL sock_preread (const sock_type *s, BYTE *dp, int len)
 
W32_FUNC int W32_CALL sock_fastread (sock_type *s, BYTE *dp, int len)
 Read a socket with maximum 'len' bytes. More...
 
W32_FUNC int W32_CALL sock_write (sock_type *s, const BYTE *dp, int len)
 Writes data and returns length written. More...
 
W32_FUNC int W32_CALL sock_enqueue (sock_type *s, const BYTE *dp, int len)
 For UDP, this function is same as sock_write(). More...
 
W32_FUNC int W32_CALL sock_fastwrite (sock_type *s, const BYTE *dp, int len)
 Simpler, non-blocking (non-looping) version of sock_write(). More...
 
W32_FUNC size_t W32_CALL sock_setbuf (sock_type *s, BYTE *buf, size_t len)
 
W32_FUNC void W32_CALL sock_flush (sock_type *s)
 Send pending TCP data. More...
 
W32_FUNC void W32_CALL sock_noflush (sock_type *s)
 Sets non-flush mode on next TCP write.
 
W32_FUNC void W32_CALL sock_flushnext (sock_type *s)
 Causes next transmission to have a flush (PUSH bit set).
 
W32_FUNC int W32_CALL sock_puts (sock_type *s, const BYTE *dp)
 
W32_FUNC WORD W32_CALL sock_gets (sock_type *s, BYTE *dp, int n)
 
W32_FUNC BYTE W32_CALL sock_putc (sock_type *s, BYTE c)
 
W32_FUNC int W32_CALL sock_getc (sock_type *s)
 
W32_FUNC WORD W32_CALL sock_dataready (sock_type *s)
 sock_dataready - returns number of bytes waiting to be read. More...
 
W32_FUNC int W32_CALL sock_established (sock_type *s)
 
W32_FUNC int W32_CALL sock_close (sock_type *s)
 Close a UDP/TCP socket.
 
W32_FUNC int W32_CALL sock_abort (sock_type *s)
 Abort a UDP/TCP/Raw socket.
 
W32_FUNC WORD W32_CALL sock_mode (sock_type *s, WORD mode)
 
W32_FUNC int W32_CALL sock_sselect (const sock_type *s, int waitstate)
 
W32_FUNC int W32_CALL sock_timeout (sock_type *s, int seconds)
 
W32_FUNC int W32_CALL sock_recv (sock_type *s, void *buf, unsigned len)
 
W32_FUNC int W32_CALL sock_recv_init (sock_type *s, void *buf, unsigned len)
 
W32_FUNC int W32_CALL sock_recv_from (sock_type *s, DWORD *ip, WORD *port, void *buf, unsigned len, int peek)
 
W32_FUNC int W32_CALL sock_recv_used (const sock_type *s)
 
W32_FUNC int W32_CALL sock_keepalive (sock_type *s)
 
W32_FUNC size_t W32_CALL sock_rbsize (const sock_type *s)
 
W32_FUNC size_t W32_CALL sock_rbused (const sock_type *s)
 
W32_FUNC size_t W32_CALL sock_rbleft (const sock_type *s)
 
W32_FUNC size_t W32_CALL sock_tbsize (const sock_type *s)
 
W32_FUNC size_t W32_CALL sock_tbused (const sock_type *s)
 
W32_FUNC size_t W32_CALL sock_tbleft (const sock_type *s)
 
W32_FUNC VoidProc W32_CALL sock_yield (tcp_Socket *s, VoidProc fn)
 Enable user defined yield function. More...
 
W32_FUNC int MS_CDECL sock_printf (sock_type *s, const char *fmt,...) __attribute__((format(printf
 
W32_FUNC int MS_CDECL W32_FUNC
int MS_CDECL 
sock_scanf (sock_type *s, const char *fmt,...) __attribute__((format(scanf
 
W32_FUNC int MS_CDECL W32_FUNC
int MS_CDECL W32_FUNC int
W32_CALL 
udp_open (udp_Socket *s, WORD lport, DWORD ina, WORD port, ProtoHandler handler)
 UDP active open. More...
 
W32_FUNC int W32_CALL tcp_open (tcp_Socket *s, WORD lport, DWORD ina, WORD port, ProtoHandler handler)
 Actively open a TCP connection. More...
 
W32_FUNC int W32_CALL udp_listen (udp_Socket *s, WORD lport, DWORD ina, WORD port, ProtoHandler handler)
 UDP passive open. More...
 
W32_FUNC int W32_CALL tcp_listen (tcp_Socket *s, WORD lport, DWORD ina, WORD port, ProtoHandler handler, WORD timeout)
 Passively opens TCP a connection. More...
 
W32_FUNC int W32_CALL tcp_established (const tcp_Socket *s)
 Returns 1 if TCP connection is established.
 
W32_FUNC int W32_CALL tcp_cbreak (int mode)
 Sets our break mode. More...
 
W32_FUNC char *W32_CALL rip (char *s)
 Removes end-of-line termination from a string. More...
 
W32_FUNC int W32_CALL watt_kbhit (void)
 A less CPU hogging kbhit().
 
W32_FUNC int W32_CALL priv_addr (DWORD ip)
 
W32_FUNC const char *W32_CALL tcp_md5_secret (tcp_Socket *s, const char *secret)
 
W32_FUNC void W32_CALL make_md5_signature (const in_Header *ip, const tcp_Header *tcp, WORD datalen, const char *secret, BYTE *buf)
 
W32_FUNC BOOL W32_CALL check_md5_signature (const tcp_Socket *s, const in_Header *ip)
 
W32_FUNC DWORD W32_CALL set_timeout (DWORD msec)
 Return time for when given timeout (msec) expires. More...
 
W32_FUNC int W32_CALL chk_timeout (DWORD value)
 Check if milli-sec value has expired: More...
 
W32_FUNC int W32_CALL cmp_timers (DWORD t1, DWORD t2)
 Compare two timers with expirary at 't1' and 't2'. More...
 
W32_FUNC int W32_CALL set_timediff (long msec)
 Must be called by user right before or after a time change occurs. More...
 
W32_FUNC long W32_CALL get_timediff (DWORD now, DWORD t)
 Return time difference between timers 'now' and 'tim'. More...
 
W32_FUNC int W32_CALL hires_timer (int on)
 Control use of high-resolution timer. More...
 
W32_FUNC double W32_CALL timeval_diff (const struct timeval *a, const struct timeval *b)
 
W32_FUNC struct timeval W32_CALL timeval_diff2 (struct timeval *a, struct timeval *b)
 
W32_FUNC void W32_CALL init_timer_isr (void)
 
W32_FUNC void W32_CALL exit_timer_isr (void)
 
W32_FUNC void W32_CALL init_userSuppliedTimerTick (void)
 init_userSuppliedTimerTick() - setup timer handling for programs that are already running a periodic interrupt or whatever (i.e. More...
 
W32_FUNC void W32_CALL userTimerTick (DWORD)
 Provide timer-ticks from an application. More...
 
W32_FUNC void W32_CALL ip_timer_init (sock_type *s, unsigned delayseconds)
 
W32_FUNC int W32_CALL ip_timer_expired (const sock_type *s)
 
W32_DATA int (W32_CALL *loopback_handler)(in_Header *ip)
 
W32_FUNC void W32_CALL sock_debugdump (const sock_type *s)
 
W32_FUNC long W32_CALL tcp_config (const char *path)
 
W32_FUNC int W32_CALL tcp_config_name (char *name, int max)
 
W32_FUNC WORD W32_CALL tcp_tick (sock_type *s)
 Must be called periodically by user application (or BSD socket API). More...
 
W32_FUNC void W32_CALL tcp_set_debug_state (WORD x)
 Old comptibility function. More...
 
W32_FUNC DWORD W32_CALL resolve (const char *name)
 Convert host name to an address. More...
 
W32_FUNC int W32_CALL resolve_ip (DWORD ip, char *name, int len)
 Resolve an IP-address to a name.
 
W32_FUNC int W32_CALL resolve_ip6 (const char *name, void *addr)
 
W32_FUNC DWORD W32_CALL lookup_host (const char *host, char *ip_str)
 
W32_FUNC const char *W32_CALL dom_strerror (int err)
 Return text for error code (dom_errno).
 
W32_FUNC char *W32_CALL dom_remove_dot (char *name)
 
W32_FUNC int W32_CALL _ip_delay0 (sock_type *s, int sec, UserHandler fn, int *statusptr)
 
W32_FUNC int W32_CALL _ip_delay1 (sock_type *s, int sec, UserHandler fn, int *statusptr)
 
W32_FUNC int W32_CALL _ip_delay2 (sock_type *s, int sec, UserHandler fn, int *statusptr)
 
W32_DATA void (W32_CALL *usr_init)(const char *keyword
 Hook to a function called after we're initialised.
 
W32_FUNC int W32_CALL parse_config_table (const struct config_table *tab, const char *section, const char *name, const char *value)
 Parse the config-table and if a match is found for ('section'+'. More...
 
W32_FUNC void W32_CALL tcp_inject_config (const struct config_table *cfg, const char *key, const char *value)
 Callable from a user application to inject config values before the normal WATTCP.CFG is loaded and parsed. More...
 
typedef long (W32_CALL *WattUserConfigFunc)(int pass
 
W32_FUNC WattUserConfigFunc
W32_CALL 
_watt_user_config (WattUserConfigFunc fn)
 A user application may call the `_watt_user_config()' function prior to calling sock_init() to inject its own configuration values into the tcp_config() parser. More...
 
W32_FUNC WattDHCPConfigFunc
W32_CALL 
DHCP_set_config_func (WattDHCPConfigFunc fn)
 Sets up an application hook for doing DHCP operations (DHCP_config_op)
 
W32_FUNC void W32_CALL DHCP_release (BOOL force)
 Possibly send a DHCP release. More...
 
W32_FUNC int W32_CALL DHCP_read_config (void)
 Called from watt_sock_init() after "\c WATTCP.CFG" has been parsed. More...
 
W32_FUNC DWORD W32_CALL DHCP_get_server (void)
 Return current DHCP server address.
 
W32_DATA int (MS_CDECL *_printf)(const char *
 
W32_DATA __attribute__ ((format(printf, 1, 2)))
 
W32_FUNC void W32_CALL outs (const char *s)
 
W32_FUNC void W32_CALL outsnl (const char *s)
 
W32_FUNC void W32_CALL outsn (const char *s, int n)
 
W32_FUNC void W32_CALL outhexes (const char *s, int n)
 
W32_FUNC void W32_CALL outhex (char ch)
 
W32_FUNC int W32_CALL wintr_enable (void)
 
W32_FUNC void W32_CALL wintr_disable (void)
 
W32_FUNC void W32_CALL wintr_shutdown (void)
 
W32_FUNC void W32_CALL wintr_init (void)
 
W32_FUNC int W32_CALL _ping (DWORD host, DWORD num, const BYTE *pattern, size_t len)
 Format and send an ICMP echo request (ping). More...
 
W32_FUNC DWORD W32_CALL _chk_ping (DWORD host, DWORD *ping_num)
 Check for ICMP echo reply in ping-cache. More...
 
W32_FUNC void W32_CALL add_ping (DWORD host, DWORD tim, DWORD number)
 Add an ICMP echo reply to the ping-cache.
 
W32_FUNC int W32_CALL _eth_init (void)
 Initialize the network driver interface. More...
 
W32_FUNC void W32_CALL _eth_release (void)
 Release the hardware driver.
 
W32_FUNC void *W32_CALL _eth_formatpacket (const void *eth_dest, WORD eth_type)
 _eth_format_packet() places the next packet to be transmitted into the above link-layer output packet. More...
 
W32_FUNC void W32_CALL _eth_free (const void *buf)
 Free an input buffer once it is no longer needed.
 
W32_FUNC void *W32_CALL _eth_arrived (WORD *type, BOOL *brdcast)
 Poll for arrival of new packets (IP/ARP/RARP/PPPoE protocol). More...
 
W32_FUNC int W32_CALL _eth_send (WORD len, const void *sock, const char *file, unsigned line)
 _eth_send() does the actual transmission once we are complete with filling the buffer. More...
 
W32_FUNC int W32_CALL _eth_set_addr (const void *addr)
 Sets a new MAC address for our interface.
 
W32_FUNC BYTE W32_CALL _eth_get_hwtype (BYTE *hwtype, BYTE *hwlen)
 Fill in hardware address type/length for BOOTP/DHCP packets. More...
 
W32_DATA void *W32_CALL * _eth_recv_hook (WORD *type)
 
W32_FUNC WORD W32_CALL in_checksum (const void *buf, unsigned len)
 This checksum routine is only used by 16-bit targets (and files outside the library). More...
 
W32_FUNC int MS_CDECL gui_printf (const char *fmt,...)
 
W32_FUNC char *W32_CALL win_strerror (DWORD err)
 
W32_FUNC int W32_CALL pkt_win_print_GetIfTable (void)
 
W32_FUNC int W32_CALL pkt_win_print_GetIfTable2 (void)
 
W32_FUNC int W32_CALL pkt_win_print_GetAdaptersAddresses (void)
 
W32_FUNC int W32_CALL pkt_win_print_RasEnumConnections (void)
 
W32_FUNC int W32_CALL pkt_win_print_WlanEnumInterfaces (void)
 
W32_FUNC DWORD W32_CALL _gethostid (void)
 Core style: Returns local IPv4-address. More...
 
W32_FUNC DWORD W32_CALL _sethostid (DWORD ip)
 Core-style: Sets local IPv4-address. More...
 
W32_FUNC int W32_CALL _getsockname (const sock_type *s, void *dest, int *len)
 Core-style:
Return 'watt_sockaddr' for our side of a UDP/TCP connection.
 
W32_FUNC int W32_CALL _getpeername (const sock_type *s, void *dest, int *len)
 Core-style:
Return 'watt_sockaddr' for peer in a UDP/TCP connection.
 
W32_FUNC int W32_CALL _chk_socket (const sock_type *s)
 
W32_FUNC void W32_CALL psocket (const sock_type *s)
 
W32_FUNC void W32_CALL sock_sturdy (sock_type *s, int level)
 Keep the socket open inspite of receiving "ICMP Unreachable" For UDP or TCP socket.
 
W32_FUNC const char *W32_CALL sockerr (const sock_type *s)
 
W32_FUNC void W32_CALL sockerr_clear (sock_type *s)
 
W32_FUNC const char *W32_CALL sockstate (const sock_type *s)
 
W32_FUNC enum TCP_SIMPLE_STATE
W32_CALL 
tcp_simple_state (const tcp_Socket *s)
 
W32_FUNC char *W32_CALL _inet_ntoa (char *s, DWORD x)
 Convert an IP-address 'ip' into a string. More...
 
W32_FUNC DWORD W32_CALL _inet_addr (const char *name)
 Convert a string into an IP-address. More...
 
W32_FUNC DWORD W32_CALL aton (const char *name)
 Converts [a.b.c.d] or a.b.c.d to 32 bit IPv4 address. More...
 
W32_FUNC int W32_CALL isaddr (const char *name)
 Check if 'str' is simply an ip address. More...
 
W32_FUNC DWORD W32_CALL aton_dotless (const char *str)
 Converts `[dotless]' or `dotless' to 32 bit long (host order) More...
 
W32_FUNC BOOL W32_CALL isaddr_dotless (const char *str, DWORD *ip)
 Check if 'str' is a dotless ip address. More...
 
W32_FUNC int W32_CALL addwattcpd (VoidProc p)
 
W32_FUNC int W32_CALL delwattcpd (VoidProc p)
 
W32_FUNC void W32_CALL stopwattcpd (void)
 
W32_FUNC int W32_CALL close_s (int s)
 
W32_FUNC int W32_CALL write_s (int s, const char *buf, int nbyte)
 
W32_FUNC int W32_CALL read_s (int s, char *buf, int nbyte)
 
W32_FUNC int W32_CALL writev_s (int s, const struct iovec *vector, size_t count)
 
W32_FUNC int W32_CALL readv_s (int s, const struct iovec *vector, size_t count)
 
W32_FUNC int W32_CALL select_s (int num_sockets, fd_set *read_events, fd_set *write_events, fd_set *except_events, struct timeval *timeout)
 The select_s() function. More...
 
W32_FUNC int W32_CALL select (int num_sockets, fd_set *read_events, fd_set *write_events, fd_set *except_events, struct timeval *timeout)
 
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)
 
W32_FUNC int W32_CALL join_mcast_group (DWORD ip)
 
W32_FUNC int W32_CALL leave_mcast_group (DWORD ip)
 
W32_FUNC int W32_CALL multi_to_eth (DWORD ip, eth_address *eth)
 
W32_FUNC int W32_CALL udp_SetTTL (udp_Socket *s, BYTE ttl)
 Set the TTL on an outgoing UDP datagram.
 
W32_FUNC int W32_CALL num_mcast_active (void)
 
W32_FUNC int W32_CALL watt_getopt (int argc, char *const *argv, const char *opt_str)
 
W32_FUNC int W32_CALL _w_watt_getopt (int argc, wchar_t *const *argv, const wchar_t *opt_str)
 
W32_FUNC void W32_CALL print_mac_stats (void)
 
W32_FUNC void W32_CALL print_pkt_stats (void)
 
W32_FUNC void W32_CALL print_vjc_stats (void)
 
W32_FUNC void W32_CALL print_arp_stats (void)
 
W32_FUNC void W32_CALL print_pppoe_stats (void)
 
W32_FUNC void W32_CALL print_ip4_stats (void)
 
W32_FUNC void W32_CALL print_ip6_stats (void)
 
W32_FUNC void W32_CALL print_icmp_stats (void)
 
W32_FUNC void W32_CALL print_igmp_stats (void)
 
W32_FUNC void W32_CALL print_udp_stats (void)
 
W32_FUNC void W32_CALL print_tcp_stats (void)
 
W32_FUNC void W32_CALL print_all_stats (void)
 
W32_FUNC void W32_CALL reset_stats (void)
 
W32_FUNC int W32_CALL sock_stats (sock_type *s, DWORD *days, WORD *inactive, WORD *cwindow, DWORD *avg, DWORD *sd)
 
W32_FUNC int W32_CALL pkt_eth_init (mac_address *eth)
 Initialise Packet driver interface. More...
 
W32_FUNC int W32_CALL pkt_release (void)
 
W32_FUNC int W32_CALL pkt_reset_handle (WORD handle)
 Reset the driver-state associated with handle.
 
W32_FUNC int W32_CALL pkt_send (const void *tx, int length)
 Send a link-layer frame. More...
 
W32_FUNC int W32_CALL pkt_buf_wipe (void)
 Clear the receive queue.
 
W32_FUNC void W32_CALL pkt_free_pkt (const void *pkt)
 Release a packet from the receive queue. More...
 
W32_FUNC int W32_CALL pkt_waiting (void)
 Return number of packets waiting in queue.
 
W32_FUNC int W32_CALL pkt_set_addr (const void *eth)
 Set a new MAC source address.
 
W32_FUNC int W32_CALL pkt_get_addr (mac_address *eth)
 Return the MAC address.
 
W32_FUNC int W32_CALL pkt_get_mtu (void)
 Return PKTDRVR maximum-transmit-units (MTU). More...
 
W32_FUNC int W32_CALL pkt_get_drvr_ver (WORD *major, WORD *minor, WORD *unused, WORD *build)
 Return version of PKTDRVR.
 
W32_FUNC int W32_CALL pkt_get_api_ver (WORD *ver)
 Return version of spec. More...
 
W32_FUNC int W32_CALL pkt_set_rcv_mode (int mode)
 Sets the receive mode of the interface. More...
 
W32_FUNC int W32_CALL pkt_get_rcv_mode (void)
 Gets the receive mode of the interface (can never be mode 0). More...
 
W32_FUNC BOOL W32_CALL pkt_check_address (DWORD my_ip)
 
W32_FUNC BOOL W32_CALL pkt_is_init (void)
 
W32_FUNC int W32_CALL pkt_get_params (struct PktParameters *params)
 Get PKTDRVR parameters (MTU, version etc.)
 
W32_FUNC int W32_CALL pkt_get_stats (struct PktStats *stats, struct PktStats *total)
 Get PKTDRVR statistics. More...
 
W32_FUNC DWORD W32_CALL pkt_dropped (void)
 Return number of packets dropped.
 
W32_FUNC int W32_CALL pkt_get_vector (void)
 Return PKTDRVR vector.
 
W32_FUNC const char *W32_CALL pkt_strerror (int code)
 Return textual error representing error-code. More...
 
W32_FUNC const char *W32_CALL pkt_get_device_name (void)
 
W32_FUNC const char *W32_CALL pkt_get_drvr_name (void)
 
W32_FUNC const char *W32_CALL pkt_get_drvr_descr (void)
 
W32_FUNC WORD W32_CALL pkt_get_drvr_class (void)
 
W32_FUNC void W32_CALL backgroundon (void)
 
W32_FUNC void W32_CALL backgroundoff (void)
 
W32_FUNC void W32_CALL backgroundfn (VoidProc func)
 
W32_FUNC int W32_CALL ffs (int mask)
 
W32_FUNC int W32_CALL system (const char *cmd)
 
pragma Alias (system,"_mw_watt_system")
 
W32_FUNC void W32_CALL delay (unsigned int msec)
 
W32_FUNC unsigned W32_CALL Random (unsigned a, unsigned b)
 Returns a random integer in range [a..b].
 
W32_FUNC void W32_CALL RandomWait (unsigned a, unsigned b)
 Wait for a random period in range [a..b] millisec.
 
W32_FUNC int W32_CALL trace2com_init (WORD portAddress, DWORD baudRate)
 
W32_FUNC int MS_CDECL __trace2com (const char *fmt,...) __attribute__((format(printf
 

Variables

W32_DATA const char * wattcpCopyright
 
W32_DATA DWORD my_ip_addr
 
W32_DATA DWORD sin_mask
 
W32_DATA int sock_delay
 
W32_DATA int sock_inactive
 
W32_DATA int sock_data_timeout
 
W32_DATA WORD multihomes
 
W32_DATA int block_tcp
 
W32_DATA int block_udp
 
W32_DATA int block_icmp
 
W32_DATA int block_ip
 
W32_DATA WORD last_cookie
 
W32_DATA DWORD cookies [MAX_COOKIES]
 
W32_DATA BOOL survive_eth
 GvB 2002-09, allows us to survive without a (working) packet driver at all - in cases where life still has a meaning without TCP/IP.
 
W32_DATA BOOL survive_bootp
 Survive a failed BOOTP attempt. More...
 
W32_DATA BOOL survive_dhcp
 Survive a failed DHCP attempt. More...
 
W32_DATA BOOL survive_rarp
 Don't survive a failed RARP attempt.
 
W32_DATA unsigned tcp_OPEN_TO
 
W32_DATA unsigned tcp_CLOSE_TO
 
W32_DATA unsigned tcp_RTO_ADD
 
W32_DATA unsigned tcp_RTO_BASE
 
W32_DATA unsigned tcp_RTO_SCALE
 
W32_DATA unsigned tcp_RST_TIME
 
W32_DATA unsigned tcp_RETRAN_TIME
 
W32_DATA unsigned tcp_MAX_VJSA
 
W32_DATA unsigned tcp_MAX_VJSD
 
W32_DATA DWORD tcp_recv_win
 
W32_DATA WORD dns_timeout
 
W32_DATA BOOL dns_recurse
 
W32_DATA WORD _watt_handle_cbreak
 Turn off stack-checking here because stack may be out of bounds. More...
 
W32_DATA volatile int _watt_cbroke
 
W32_DATA unsigned _mtu
 
W32_DATA unsigned _mss
 
W32_DATA int ctrace_on
 
W32_DATA int debug_on
 
W32_DATA int has_rdtsc
 
W32_DATA DWORD clocks_per_usec
 
W32_DATA unsigned tcp_keep_idle
 
W32_DATA unsigned tcp_keep_intvl
 
W32_DATA unsigned tcp_max_idle
 
W32_DATA BOOL _resolve_exit
 
W32_DATA BOOL _resolve_timeout
 
W32_DATA char defaultdomain [MAX_HOSTLEN+1]
 
W32_DATA char * def_domain
 
W32_DATA DWORD def_nameservers [MAX_NAMESERVERS]
 
W32_DATA WORD last_nameserver
 
W32_DATA int dom_errno
 
W32_DATA const char * value
 
W32_DATA int _watt_no_config
 
W32_DATA BOOL DHCP_did_gratuitous_arp
 
W32_DATA size_t length
 
W32_DATA unsigned len
 
W32_DATA int _multicast_on
 
W32_DATA int _multicast_intvl
 
W32_DATA char * watt_optarg
 
W32_DATA int watt_optind
 
W32_DATA int watt_opterr
 
W32_DATA int watt_optopt
 
W32_DATA char * watt_optswchar
 
W32_DATA wchar_t * _w_watt_optarg
 
W32_DATA wchar_t * _w_watt_optswchar
 

Detailed Description

Watt-32 public API.

Definition in file tcp.h.

Enumeration Type Documentation

Convert 'arg_func' below to this type.

Enumerator
ARG_ATOI 

convert to int

ARG_ATOB 

convert to 8-bit byte

ARG_ATOW 

convert to 16-bit word

ARG_ATOIP 

convert to ip-address (host order)

ARG_ATOX_B 

convert to hex-byte

ARG_ATOX_W 

convert to hex-word

ARG_ATOX_D 

convert to hex-dword

ARG_STRDUP 

duplicate string value

ARG_STRCPY 

copy string value

ARG_RESOLVE 

resolve host to IPv4-address

ARG_FUNC 

call convertion function

Definition at line 423 of file tcp.h.

Function Documentation

W32_FUNC DWORD W32_CALL _chk_ping ( DWORD  host,
DWORD *  number 
)

Check for ICMP echo reply in ping-cache.

Return values
replytime in system ticks.
(DWORD)-1on failure

Definition at line 169 of file pcping.c.

W32_FUNC void* W32_CALL _eth_arrived ( WORD *  type_ptr,
BOOL *  broadcast 
)

Poll for arrival of new packets (IP/ARP/RARP/PPPoE protocol).

Sets protocol-type of packet received in 'type'.

For Ethernet/TokenRing-type drivers:

Return values
Pointerpast the MAC-header to the IP/ARP/RARP protocol header. Also check for link-layer broadcast.

For PPP/SLIP-type drivers (no MAC-headers):

Return values
Pointerto the IP-packet itself. IP-protocol is assumed. Can never be link-layer broadcast.

<

Todo:
push back packet, else it's lost

Definition at line 1026 of file pcsed.c.

References _eth_brdcast, _eth_free(), _eth_is_init, _eth_recv_hook(), _ip_recursion, _pktdevclass, _pktserial, fix_llc_head(), poll_recv_queue(), and update_in_stat().

W32_FUNC void* W32_CALL _eth_formatpacket ( const void mac_dest,
WORD  eth_type 
)

_eth_format_packet() places the next packet to be transmitted into the above link-layer output packet.

Returns
address of higher-level protocol (IP/RARP/RARP) header.

Definition at line 135 of file pcsed.c.

W32_FUNC BYTE W32_CALL _eth_get_hwtype ( BYTE *  hwtype,
BYTE *  hwlen 
)

Fill in hardware address type/length for BOOTP/DHCP packets.

Also used for ARP/RARP packets. Should never be called for PPP/SLIP.

Definition at line 751 of file pcsed.c.

References _pktdevclass.

W32_FUNC int W32_CALL _eth_init ( void  )
W32_FUNC int W32_CALL _eth_send ( WORD  len,
const void sock,
const char *  file,
unsigned  line 
)

_eth_send() does the actual transmission once we are complete with filling the buffer.

Do any last minute patches here, like fix the size. Send to "loopback" device if it's IP and destination matches loopback network (127.x.x.x.).

Return length of network-layer packet (not length of link-layer packet).

Definition at line 306 of file pcsed.c.

References _eth_is_init, _eth_last, _pkt_ip_ofs, _pktdevclass, has_rdtsc, send_loopback(), and update_out_stat().

W32_FUNC DWORD W32_CALL _gethostid ( void  )

Core style: Returns local IPv4-address.

Return values
addresson host order.

Definition at line 49 of file bsdname.c.

References my_ip_addr.

W32_FUNC DWORD W32_CALL _inet_addr ( const char *  s)

Convert a string into an IP-address.

Return values
addresson host order.
0string isn't a (dotless) address.

Definition at line 69 of file netaddr.c.

References aton(), isaddr(), and isaddr_dotless().

W32_FUNC char* W32_CALL _inet_ntoa ( char *  s,
DWORD  ip 
)

Convert an IP-address 'ip' into a string.

Return values
'p'.
Note
'ip' is on host order. Use 4 buffers in round-robin.

Definition at line 43 of file netaddr.c.

W32_FUNC int W32_CALL _ping ( DWORD  host,
DWORD  countnum,
const BYTE *  pattern,
size_t  len 
)

Format and send an ICMP echo request (ping).

  • countnum is the ICMP index value.
  • pattern optional data that will be sent.
  • len length of pattern data.
    Return values
    0if ARP fails or error in lower layer.
    Note
    if pattern or len is 0, only an 12 byte ICMP echo header will be sent.
    Sends fragments if needed.

Definition at line 45 of file pcping.c.

References _arp_resolve(), _default_tos, _eth_formatpacket(), set_timeout(), and sin_mask.

W32_FUNC DWORD W32_CALL _sethostid ( DWORD  ip)

Core-style: Sets local IPv4-address.

Return values
addresson host order.

Definition at line 58 of file bsdname.c.

References my_ip_addr.

W32_FUNC WattUserConfigFunc W32_CALL _watt_user_config ( WattUserConfigFunc  fn)

A user application may call the `_watt_user_config()' function prior to calling sock_init() to inject its own configuration values into the tcp_config() parser.

Useful when running diskless and setting `_watt_no_config = 0'.

Example:

  • 'pass' is 1 for first pass (PKTDRVR/WinPcap configuration), 2 for second pass.
  • 'cfg' is a pointer to the configuration table and must be passed to tcp_inject_config() as-is.

In most cases 'pass' can probably be ignored.

static long my_config_fn (int pass, const struct config_table *cfg) { // Keyword case is not significant (tcp_inject_config will convert // all keys to uppercase)

tcp_inject_config (cfg, "My_IP", "192.168.0.98"); tcp_inject_config (cfg, "NetMask", "255.255.255.0"); tcp_inject_config (cfg, "Gateway", "192.168.0.1"); (void)pass; return (1); // Returning 0 would make tcp_config() return 0 too, // as if the config file was not found }

int main (void) { _watt_no_config = 1; _watt_user_config (my_config_fn); if (sock_init()) return (-1); ... }

Never called inside Watt-32.

Definition at line 199 of file sock_ini.c.

W32_FUNC DWORD W32_CALL aton ( const char *  str)

Converts [a.b.c.d] or a.b.c.d to 32 bit IPv4 address.

Return values
0on error (safer than -1)
IPv4address (host order)

Definition at line 86 of file netaddr.c.

W32_FUNC DWORD W32_CALL aton_dotless ( const char *  str)

Converts `[dotless]' or `dotless' to 32 bit long (host order)

Return values
0on error (safer than -1)

Definition at line 115 of file netaddr.c.

References isaddr_dotless().

W32_FUNC int W32_CALL chk_timeout ( DWORD  value)

Check if milli-sec value has expired:

Return values
\liTRUE timer expired
  • FALSE not expired (or value not set)

Definition at line 547 of file timer.c.

References has_8254, and set_timeout().

W32_FUNC int W32_CALL cmp_timers ( DWORD  t1,
DWORD  t2 
)

Compare two timers with expirary at 't1' and 't2'.

Return values
\li-1 if t1 expires before t2
  • 0 if t1 == t2
  • +1 if t1 expires after t2
Note
This logic fails when timers approaches ULONG_MAX after approx. 50 days.

Definition at line 359 of file timer.c.

W32_FUNC int W32_CALL DHCP_read_config ( void  )

Called from watt_sock_init() after "\c WATTCP.CFG" has been parsed.

Open and parse transient configuration from 'config_file' or call user-defined function to read transient configuration.

Definition at line 1774 of file pcdhcp.c.

References dhcp_open(), dhcp_set_timers(), and eval_timers().

W32_FUNC void W32_CALL DHCP_release ( BOOL  force)

Possibly send a DHCP release.

  • force If TRUE, release unconditionally.
    Note
    Send release if we are configured and remaining lease is below minimum lease (DHCP_MIN_LEASE = 10 sec).

Definition at line 707 of file pcdhcp.c.

References dhcp_fsm(), DHCP_release_decline(), and sock_close().

W32_FUNC long W32_CALL get_timediff ( DWORD  now,
DWORD  tim 
)

Return time difference between timers 'now' and 'tim'.

Check for day rollover. Max timer distance is 24 hours. This function should be called immediately after chk_timeout() is called.

Definition at line 621 of file timer.c.

References has_8254.

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.

W32_FUNC int W32_CALL hires_timer ( int  on)

Control use of high-resolution timer.

When using Watt-32 together with programs that reprogram the PIT (8254 timer chip), the millisec_clock() function may return wrong values. In such cases it's best to use old-style 55ms timers. Using Watt-32 with Allegro graphics library is one such case where application program should call `hires_timer(0)' after `sock_init()' has been called.

Definition at line 377 of file timer.c.

References chk_timeout(), and has_8254.

W32_FUNC WORD W32_CALL in_checksum ( const void ptr,
unsigned  len 
)

This checksum routine is only used by 16-bit targets (and files outside the library).

32-bit targets use in_checksum_fast() in chksum0.s + chksum0.asm.

Note
`in_check_sum()' and `in_checksum_fast()' are equally fast on a Pentium 4 CPU. But on a Pentium 2 the ASM version is approx. 10 times faster.

Definition at line 29 of file chksum.c.

W32_FUNC void W32_CALL init_misc ( void  )

Initialise various stuff.

Todo:

Definition at line 324 of file misc.c.

References _watt_assert_buf, _watt_os_ver, has_rdtsc, init_timers(), is_in_stack_init(), and win32_dos_box.

W32_FUNC void W32_CALL init_userSuppliedTimerTick ( void  )

init_userSuppliedTimerTick() - setup timer handling for programs that are already running a periodic interrupt or whatever (i.e.

ALLEGRO & more). This is called to signify that the 'user task' will periodically call userTimerTick() to supply the elapsed time since the last call. Best called once before sock_init(). There is no way to revert to original timer handling once this is called. By GvB 2002-09

Definition at line 156 of file timer.c.

References has_8254.

W32_FUNC int W32_CALL isaddr ( const char *  str)

Check if 'str' is simply an ip address.

Accepts 'a.b.c.d' or '[a.b.c.d]' forms.

Return values
TRUEif 'str' is an IPv4 address.

Definition at line 128 of file netaddr.c.

W32_FUNC BOOL W32_CALL isaddr_dotless ( const char *  str,
DWORD *  ip 
)

Check if 'str' is a dotless ip address.

Accept "[ 0-9\[\]]+". Doesn't accept octal base.

Return values
TRUEif 'str' is a dotless address.

Definition at line 148 of file netaddr.c.

W32_FUNC int W32_CALL parse_config_table ( const struct config_table tab,
const char *  section,
const char *  name,
const char *  value 
)

Parse the config-table and if a match is found for ('section'+'.

'+)'name' either store variable to 'value' or call function with 'value'.

Definition at line 379 of file pcconfig.c.

References _strlcpy(), ARG_ATOB, ARG_ATOI, ARG_ATOIP, ARG_ATOW, ARG_ATOX_B, ARG_ATOX_D, ARG_ATOX_W, ARG_FUNC, ARG_RESOLVE, ARG_STRCPY, ARG_STRDUP, aton(), isaddr(), resolve(), set_value(), and void().

W32_FUNC int W32_CALL pkt_eth_init ( mac_address *  mac_addr)

Initialise Packet driver interface.

First determine vector to use; if WATTCP.CFG specifies a "PKT.VECTOR = 0xNN", use that vector, else search for PKTDRVR between PKT_FIRST_VEC and PKT_LAST_VEC (0x60 - 0x80). If the driver is outside this range, user must specify one with "PKT.VECTOR = 0x??".

If DOSX, probe and initialise protected-mode driver (not operational). Call pkt16_drvr_init() to initialise API.

Initialise Packet driver interface.

<

Todo:
Support Win-9x/ME/CE too

Definition at line 1449 of file pcpkt.c.

References _eth_airpcap, _eth_SwsVpkt, _eth_wanpacket, _eth_winpcap, _pkt_errno, _pkt_ip_ofs, _pkt_rxmode, _pkt_rxmode0, _pktdevclass, _pktdrvrname, _strlcpy(), _watt_no_config, expand_var_str(), find_adapter(), fopen_excl(), open_airpcap_adapter(), open_swsvpkt_adapter(), open_wanpacket_adapter(), open_winpcap_adapter(), parse_config_pass_1(), pkt16_drvr_init(), pkt_get_addr(), pkt_get_rcv_mode(), pkt_release(), pkt_set_rcv_mode(), strrtrim(), and winpcap_recv_thread().

W32_FUNC void W32_CALL pkt_free_pkt ( const void pkt)

Release a packet from the receive queue.

If USE_FAST_PKT, pkt has already been free'd. Just update drop count.

Definition at line 1349 of file pcpkt.c.

References _pkt_ip_ofs.

W32_FUNC int W32_CALL pkt_get_api_ver ( WORD *  ver)

Return version of spec.

this PKTDRVR conforms to.

Return values
-1on error. Return major version in upper 8 bit, minor in lower.

Definition at line 519 of file pcpkt.c.

References _eth_airpcap, _eth_SwsVpkt, and _eth_winpcap.

W32_FUNC int W32_CALL pkt_get_mtu ( void  )

Return PKTDRVR maximum-transmit-units (MTU).

Note
This includes length of MAC-header.

Definition at line 489 of file pcpkt.c.

References _pktdevclass.

W32_FUNC int W32_CALL pkt_get_rcv_mode ( void  )

Gets the receive mode of the interface (can never be mode 0).

Return values
!0Okay - _pkt_errno is 0, _pkt_rxmode and retval is current mode.
0Error - _pkt_errno is set.

_pkt_rxmode is one of the following modes: (upon successful return)

  • 1 - turn off receiver
  • 2 - receive only packets sent to this interface
  • 3 - mode 2 plus broadcast packets (default)
  • 4 - mode 3 plus limited multicast packets
  • 5 - mode 3 plus all multicast packets
  • 6 - all packets (a.k.a promiscuous mode)

Definition at line 1999 of file pcpkt.c.

References _eth_airpcap, _eth_SwsVpkt, _pkt_errno, _pkt_rxmode, _pktdevlevel, and _pktserial.

W32_FUNC int W32_CALL pkt_get_stats ( struct PktStats stats,
struct PktStats total 
)

Get PKTDRVR statistics.

Return both 'stats' for current session and 'total' statistics since driver loaded.

Definition at line 1243 of file pcpkt.c.

References get_rmode_data().

W32_FUNC int W32_CALL pkt_release ( void  )
Todo:
We might be called between 1st and 2nd packet-driver upcall. Need to wait for 2nd upcall to finish or else freeing the RMCB too early could cause a crash or a stuck PKTDRVR.

Definition at line 838 of file pcpkt.c.

References _eth_winpcap, _watt_fatal_error, pkt_release_handle(), pkt_reset_handle(), and release_real_mem().

W32_FUNC int W32_CALL pkt_send ( const void tx,
int  length 
)

Send a link-layer frame.

For PPP/SLIP 'tx' contains no MAC-header. For EtherNet, Token-Ring, ARCNET and FDDI, 'tx' contains the complete frame.

Todo:
Change this so that we doesn't retry if the driver was stuck for "too long". I've seen drivers using approx. 100 msec on each iteration below. Retrying if the driver is stuck is not worth the time.

Definition at line 1090 of file pcpkt.c.

References _eth_SwsVpkt, pkt_tx_buf(), and Wait().

W32_FUNC int W32_CALL pkt_set_rcv_mode ( int  mode)

Sets the receive mode of the interface.

mode is one of the following modes:

  • 1 - turn off receiver
  • 2 - receive only packets sent to this interface
  • 3 - mode 2 plus broadcast packets (default)
  • 4 - mode 3 plus limited multicast packets
  • 5 - mode 3 plus all multicast packets
  • 6 - all packets (AKA promiscuous mode)
Return values
0- upon error - _pkt_errno is set
1- if the mode was set successfully

Definition at line 1955 of file pcpkt.c.

References _eth_airpcap, _eth_SwsVpkt, _pkt_errno, _pkt_rxmode, _pktdevlevel, and _pktserial.

W32_FUNC const char* W32_CALL pkt_strerror ( int  code)

Return textual error representing error-code.

Todo:
Return strings for these: PDERR_GEN_FAIL PDERR_NO_DRIVER PDERR_NO_CLASS PDERR_NO_MULTICAST PDERR_NO_SPACE
  • GetLastError(). Use win_strerror()

Definition at line 216 of file pcpkt.c.

References _strlcpy().

W32_FUNC int W32_CALL priv_addr ( DWORD  ip)

Check if 'ip' is a private addresses in the "black-hole range" (ref. RFC-1918):

10.0.0.0 - 10.255.255.255 172.16.0.0 - 172.31.255.255 192.168.0.0 - 192.168.255.255

Todo:
: rewrite using mask_len().

Definition at line 516 of file netaddr.c.

References aton().

W32_FUNC DWORD W32_CALL resolve ( const char *  name)

Convert host name to an address.

Returns 0 if name is unresolvable right now. Return value is host-order.

Definition at line 775 of file pcdns.c.

References aton(), called_from_resolve, dom_strerror(), isaddr(), lookup_domain(), my_ip_addr, next_domain(), query_init(), rip(), and set_timeout().

W32_FUNC char* W32_CALL rip ( char *  s)

Removes end-of-line termination from a string.

Removes "\n" (Unix), "\r" (MacOS) or "\r\n" (DOS/net-ascii) terminations, but not single "\n\r" (who uses that?).

Definition at line 180 of file strings.c.

W32_FUNC int W32_CALL 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.

References _sock_crit_start(), _sock_crit_stop(), exc_select(), and tcp_tick().

W32_FUNC int W32_CALL set_timediff ( long  msec)

Must be called by user right before or after a time change occurs.

Not used in Watt-32.

Definition at line 608 of file timer.c.

W32_FUNC DWORD W32_CALL set_timeout ( DWORD  msec)

Return time for when given timeout (msec) expires.

Make sure it never returns 0 (it will confuse chk_timeout).

Definition at line 503 of file timer.c.

References has_8254.

W32_FUNC WORD W32_CALL sock_dataready ( sock_type s)

sock_dataready - returns number of bytes waiting to be read.

  • if in ASCII mode, return >0 if a terminated line is present or the buffer is full or state is LASTACK (tcp only).
  • if in binary mode (default), simply return number of bytes in receive buffer.
  • For UDP or TCP sockets only.

Definition at line 246 of file sock_io.c.

References _raw_Socket::ip_type, and tcp_Socket::state.

W32_FUNC int W32_CALL sock_enqueue ( sock_type s,
const BYTE *  data,
int  len 
)

For UDP, this function is same as sock_write().

For TCP, this function enqueues 'data' to transmit queue.

Note
user must not touch 'data' while sock_tbused() returns > 0.

Definition at line 3044 of file pctcp.c.

References tcp_Socket::tx_datalen, tcp_Socket::tx_queuelen, and udp_write().

W32_FUNC void MS_CDECL sock_exit ( void  )

Our only atexit() handler.

Called only once during normal program shutdown. Exception handlers exit differently (see except_handler() above)

Definition at line 1039 of file sock_ini.c.

References _watt_fatal_error, _watt_is_init, and tcp_shutdown().

W32_FUNC int W32_CALL sock_fastread ( sock_type s,
BYTE *  buf,
int  len 
)

Read a socket with maximum 'len' bytes.

Note
does not busywait until buffer is full.

Definition at line 2931 of file pctcp.c.

References _raw_Socket::ip_type, raw_read(), tcp_read(), and udp_read().

W32_FUNC int W32_CALL sock_fastwrite ( sock_type s,
const BYTE *  data,
int  len 
)

Simpler, non-blocking (non-looping) version of sock_write().

Note
UDP writes may truncate; check the return value.

Definition at line 3018 of file pctcp.c.

References tcp_write(), and udp_write().

W32_FUNC void W32_CALL sock_flush ( sock_type s)

Send pending TCP data.

If there is Tx-data to be sent, set the PUSH bit.

Definition at line 3103 of file pctcp.c.

References tcp_Socket::flags, tcp_Socket::send_una, and tcp_Socket::tx_datalen.

W32_FUNC int W32_CALL sock_puts ( sock_type s,
const BYTE *  dp 
)

<

Todo:
suppport UDP frags

Definition at line 39 of file sock_io.c.

References _raw_Socket::ip_type, sock_flushnext(), and sock_write().

W32_FUNC int W32_CALL sock_read ( sock_type s,
BYTE *  buf,
size_t  maxlen 
)

Read a socket with maximum 'maxlen' bytes.

Note
busywaits until 'buf' is full (and call 's->usr_yield').
Return values
0socket is not open.
<=maxlensocket has data to be read.

Definition at line 2875 of file pctcp.c.

References raw_read(), tcp_read(), tcp_tick(), and udp_read().

W32_FUNC int W32_CALL sock_write ( sock_type s,
const BYTE *  data,
int  len 
)

Writes data and returns length written.

Note
sends with PUSH-bit (flush data).
repeatedly calls 's->usr_yield'.
UDP packetsare sent in chunks of MTU-28.
Return values
0if some error in lower layer.
'len'if all data sent okay.

Definition at line 2960 of file pctcp.c.

References tcp_Socket::flags, tcp_tick(), tcp_write(), and udp_write().

W32_FUNC VoidProc W32_CALL sock_yield ( _tcp_Socket s,
VoidProc  func 
)

Enable user defined yield function.

Return address of previous yield function.

Definition at line 2803 of file pctcp.c.

W32_FUNC int W32_CALL tcp_cbreak ( int  mode)

Sets our break mode.

  • `mode' is composed of the following flags
    • 0x01: disallow breakouts
    • 0x10: display a message upon ^C/^BREAK (default)

Definition at line 207 of file pc_cbrk.c.

References set_cbreak(), sig_handler_watt(), sock_sig_exit(), and win32_dos_box.

W32_FUNC void W32_CALL tcp_inject_config ( const struct config_table cfg,
const char *  key,
const char *  value 
)

Callable from a user application to inject config values before the normal WATTCP.CFG is loaded and parsed.

See '_watt_user_config' in sock_ini.c.

Definition at line 893 of file pcconfig.c.

References strntrimcpy(), and tcp_inject_config_direct().

W32_FUNC int W32_CALL tcp_listen ( _tcp_Socket s,
WORD  lport,
DWORD  ip,
WORD  port,
ProtoHandler  handler,
WORD  timeout 
)
W32_FUNC int W32_CALL tcp_open ( _tcp_Socket s,
WORD  lport,
DWORD  ip,
WORD  rport,
ProtoHandler  handler 
)

Actively open a TCP connection.

Make connection to a particular destination. Not used for IPv6 (see _TCP6_open()).

Return values
0on error. 's->err_msg' filled.
Note
'lport' is local port to associate with the connection.
'rport' is remote port for same connection.

<

Todo:
use mss from setsockopt()
Todo:
use TCP_NODELAY set in setsockopt()

Definition at line 308 of file pctcp.c.

References _arp_start_lookup(), _default_ttl, _eth_is_init, _inet_ntoa(), _tcp_allsocs, _tcp_unthread(), tcp_Socket::cwindow, tcp_Socket::flags, tcp_Socket::max_seg, tcp_Socket::max_tx_data, my_ip_addr, tcp_Socket::next, tcp_Socket::rto, tcp_Socket::rx_buf, tcp_Socket::safetysig, tcp_Socket::safetytcp, tcp_Socket::send_next, tcp_Socket::state, tcp_nagle, tcp_OPEN_TO, tcp_Socket::tx_buf, tcp_Socket::tx_data, tcp_Socket::unhappy, tcp_Socket::vj_sa, and tcp_Socket::wwindow.

W32_FUNC void W32_CALL tcp_set_debug_state ( WORD  val)

Old comptibility function.

Callable from apps using Watt-32 only. Only allow apps to set a higher level than specified in cfg-file. Default: 'debug_on == 0'.

Definition at line 853 of file pcconfig.c.

W32_FUNC WORD W32_CALL tcp_tick ( sock_type s)

Must be called periodically by user application (or BSD socket API).

  • if 's != NULL', check this socket for timeout.
  • if 's == NULL', check all sockets in list.
Return values
0if 's' is non-NULL and 's' closes.
!0if 's' is NULL or 's' is still open.

Don't enter this loop if reentered. That could return the same packet twice (before we call _eth_free() on the 1st packet).

Todo:
Limit the time spent here (clamp # of loops)

Definition at line 1389 of file pctcp.c.

References _arp_handler(), _eth_arrived(), _eth_free(), _ip4_handler(), _rarp_handler(), _tcp_unthread(), pppoe_handler(), tcp_Socket::state, and tcp_Retransmitter().

W32_FUNC int W32_CALL udp_listen ( _udp_Socket s,
WORD  lport,
DWORD  ip,
WORD  port,
ProtoHandler  handler 
)

UDP passive open.

Listen for a connection on a particular port.

Definition at line 157 of file pctcp.c.

References _default_ttl, _eth_is_init, _udp_allsocs, udp_Socket::rx_buf, udp_Socket::safetysig, and udp_close().

W32_FUNC int MS_CDECL W32_FUNC int MS_CDECL W32_FUNC int W32_CALL udp_open ( _udp_Socket s,
WORD  lport,
DWORD  ip,
WORD  port,
ProtoHandler  handler 
)

UDP active open.

Open a connection on a particular port.

Definition at line 192 of file pctcp.c.

References _arp_resolve(), _default_ttl, _eth_is_init, _inet_ntoa(), _udp_allsocs, my_ip_addr, udp_Socket::rx_buf, udp_Socket::safetysig, sin_mask, and udp_close().

W32_FUNC void W32_CALL userTimerTick ( DWORD  elapsed_time_msec)

Provide timer-ticks from an application.

This should be periodically called from user code to increment the timer count once activated via init_userSuppliedTimerTick(). Best called from a periodic interrupt handler (int 8/1Ch/70h) which is the case now with init_timer_isr().

by GvB 2002-09

Definition at line 186 of file timer.c.

W32_FUNC int W32_CALL watt_sock_init ( size_t  tcp_Sock_size,
size_t  udp_Sock_size,
size_t  time_t_size 
)
W32_FUNC const char* W32_CALL wattcpBuildCCexe ( void  )

Return the the name if the compiler used.

E.g. = cl.

Definition at line 456 of file version.c.

References _strlcpy().

W32_FUNC const char* W32_CALL wattcpBuildCflags ( void  )

Return the used.

Since the makefiles contains "-I..\inc" for some targets (except gcc), replace "-I.." with "-I../inc". ("\i" is interpreted as an ESC-sequence).

Todo:
Remove excessive spaces between args. Using strtok_r() in a loop?

Definition at line 431 of file version.c.

References _strlcpy().

W32_FUNC const char* W32_CALL wattcpCapabilities ( void  )

Return compiled-in capabilities and features.

These features are set in "config.h"

Definition at line 568 of file version.c.

W32_FUNC const char* W32_CALL wattcpVersion ( void  )

Return string for Watt-32 version.

Include this:

  • Name and version of compiler used to build Watt-32.
  • Target environment (if any).
  • Build date.

E.g. Watt-32 (2.2.11 Win32), GNU-C 4.5.3, CygWin 1.7.16, Aug 31 2012

Definition at line 76 of file version.c.

Variable Documentation

W32_DATA volatile int _watt_cbroke

increment on SIGINT catch

Definition at line 321 of file tcp.h.

W32_DATA WORD _watt_handle_cbreak

Turn off stack-checking here because stack may be out of bounds.

longjmp() hopefully fixes that.changes operation of the break stuff

Definition at line 320 of file tcp.h.

W32_DATA BOOL survive_bootp

Survive a failed BOOTP attempt.

Don't survive a failed BOOTP attempt.

Definition at line 262 of file tcp.h.

W32_DATA BOOL survive_dhcp

Survive a failed DHCP attempt.

Don't survive a failed DHCP attempt.

Definition at line 263 of file tcp.h.