📄 tcp.h
字号:
extern WORD last_nameserver;
extern WORD arp_last_gateway;
extern WORD arp_timeout;
extern WORD arp_alive;
extern struct {
DWORD gate_ip;
DWORD subnet;
DWORD mask;
int metric;
} arp_gate_list[];
extern struct {
DWORD ip;
eth_address hardware;
BYTE flags;
BYTE bits;
DWORD expiry;
} arp_cache_data[];
extern WORD wathndlcbrk;
extern WORD watcbroke;
extern WORD mtu, mss;
extern int ctrace_on;
/*
* sock_wait_... macros
*/
/*
* sock_wait_established()
* - waits then aborts if timeout on s connection
* sock_wait_input()
* - waits for received input on s
* - may not be valid input for sock_Gets... check returned length
* sock_tick()
* - do tick and jump on abort
* sock_wait_closed();
* - discards all received data
*
* jump to sock_err with contents of *statusptr set to
* 1 on closed
* -1 on timeout
*
*/
extern int _ip_delay0 (void *s, int seconds, UserHandler fn, void *statusptr);
extern int _ip_delay1 (void *s, int seconds, UserHandler fn, void *statusptr);
extern int _ip_delay2 (void *s, int seconds, UserHandler fn, void *statusptr);
#define sock_wait_established(s,seconds,fn,statusptr) \
do { \
if (_ip_delay0 (s,seconds,fn,statusptr)) \
goto sock_err; \
} while (0)
#define sock_wait_input(s,seconds,fn,statusptr) \
do { \
if (_ip_delay1 (s,seconds,fn,statusptr)) \
goto sock_err; \
} while (0)
#define sock_tick(s, statusptr) \
do { \
if (!tcp_tick(s)) { \
if (statusptr) *statusptr = 1; \
goto sock_err; \
} \
} while (0)
#define sock_wait_closed(s,seconds,fn,statusptr) \
do { \
if (_ip_delay2(s,seconds,fn,statusptr)) \
goto sock_err; \
} while (0)
/*
* User hook for WATTCP.CFG initialisation file.
*/
extern void (*usr_init) (const char *keyword, const char *value);
struct config_table {
const char *keyword;
int type;
void *arg_func;
};
#define ARG_ATOI 0 /* convert to int */
#define ARG_ATOB 1 /* convert to 8-bit byte */
#define ARG_ATOW 2 /* convert to 16-bit word */
#define ARG_ATON 3 /* convert to ip-address */
#define ARG_ATOX_B 4 /* convert to hex-byte */
#define ARG_ATOX_W 5 /* convert to hex-word */
#define ARG_STRDUP 6 /* duplicate string value */
#define ARG_RESOLVE 7 /* resolve host to ip-address */
#define ARG_FUNC 8 /* call convertion function */
extern int parse_config_table (struct config_table *tab,
const char *section,
const char *name,
const char *value);
/*
* Run with no config file (embedded/diskless)
*/
extern int _watt_no_config;
/*
* Various function-pointer hooks etc.
*/
extern int (*_printf) (const char *, ...); /* only if defined USE_DEBUG */
extern void (*_outch) (char c); /* or else user must define it */
extern int (*_resolve_hook) (void);
extern int (*tftp_writer) (const void *buf, unsigned length);
extern int (*tftp_terminator) (void);
extern void outs (const char *s);
extern void outsnl (const char *s);
extern void outsn (const char *s, int n);
extern void outhexes(const char *s, int n);
extern void outhex (char ch);
extern int _ping (DWORD host, DWORD num, const BYTE *pattern, int len);
extern DWORD _chk_ping (DWORD host, DWORD *ping_num);
extern void _eth_init (void);
extern void _eth_release (void);
extern BYTE *_eth_formatpacket (const void *eth_dest, WORD eth_type);
extern void _eth_free (const void *buf, WORD type);
extern BYTE *_eth_arrived (WORD *type, int *brdcast);
extern void _eth_send (WORD len);
extern int _eth_set_addr (eth_address *addr);
extern void *_eth_hardware (BYTE *p);
extern BYTE _eth_get_hwtype (BYTE *hwtype, BYTE *hwlen);
extern void *(*_eth_recv_hook) (WORD *type);
extern int (*_eth_xmit_hook) (void *buf, unsigned len);
extern WORD inchksum (const void *ptr, int len);
/*
* Turn off "C" scope because <stdio.h> may include
* features specific to "C++". Nested scopes are bad.
*/
#ifdef __cplusplus
};
#endif
#ifdef __cplusplus
extern "C" {
#endif
/*
* BSD-socket similarities
*/
struct watt_sockaddr { /* for _getpeername, _getsockname */
WORD s_type;
WORD s_port;
DWORD s_ip;
BYTE s_spares[6]; /* unused */
};
extern int sock_rbsize (const void *s);
extern int sock_rbused (const void *s);
extern int sock_rbleft (const void *s);
extern int sock_tbsize (const void *s);
extern int sock_tbused (const void *s);
extern int sock_tbleft (const void *s);
extern char *_inet_ntoa (char *s, DWORD x);
extern DWORD _inet_addr (const char *name);
extern int _getsockname(const tcp_Socket *s, void *dest, int *len);
extern int _getpeername(const tcp_Socket *s, void *dest, int *len);
extern DWORD _gethostid (void);
extern DWORD _sethostid (DWORD ip);
extern int _chk_socket (const tcp_Socket *s);
extern void psocket (tcp_Socket *s);
extern int getdomainname (char *name, int len);
extern int setdomainname (char *name, int len);
extern int gethostname (char *name, int len);
extern int sethostname (char *name, int len);
extern void _arp_register (DWORD use, DWORD instead_of, int nowait);
extern int _arp_resolve (DWORD ina, void *eth, int nowait);
extern int addwattcpd (void (*p)());
extern int delwattcpd (void (*p)());
extern void _sock_debug_on (void);
extern void _sock_debug_off (void);
extern const char *sockerr (tcp_Socket *s);
extern const char *sockstate(tcp_Socket *s);
#ifndef iovec_defined
#define iovec_defined
struct iovec {
void *iov_base;
int iov_len;
};
#endif
extern int close_s (int s);
extern int write_s (int s, const char *buf, int nbyte);
extern int read_s (int s, char *buf, int nbyte);
extern int writev_s (int s, const struct iovec *vector, size_t count);
extern int select_s (int num_sockets,
fd_set *read_events,
fd_set *write_events,
fd_set *except_evenst,
struct timeval *timeout);
/*
* Multicast stuff (if built with `USE_MULTICAST')
*/
extern int _multicast_on;
extern int join_mcast_group (DWORD);
extern int leave_mcast_group (DWORD);
extern int is_multicast (DWORD);
extern int multi_to_eth (DWORD, void *);
extern int udp_SetTTL (udp_Socket *s, BYTE ttl);
/*
* Commandline parsing
*/
extern char *optarg; /* argument of current option */
extern int optind; /* index of next argument; default=0: initialize */
extern int opterr; /* 0=disable error messages; default=1: enable */
extern int optopt; /* option char returned from getopt() */
extern char *optswchar; /* characters introducing options; default="-" */
extern enum _optmode {
GETOPT_UNIX, /* options at start of argument list (default) */
GETOPT_ANY, /* move non-options to the end */
GETOPT_KEEP, /* return options in order */
} optmode;
int getopt (int argc, char *const argv[], const char *opt_str);
/*
* Statistics printing
*/
extern void print_eth_stats (void);
extern void print_ip_stats (void);
extern void print_icmp_stats(void);
extern void print_igmp_stats(void);
extern void print_udp_stats (void);
extern void print_tcp_stats (void);
extern void print_all_stats (void);
extern void reset_stats (void);
extern int sock_stats (tcp_Socket *s, WORD *days, WORD *inactive,
WORD *cwindow, WORD *avg, WORD *sd);
/*
* Controlling timer interrupt handler for background processing.
* Not recommended, little tested
*/
extern void backgroundon (void);
extern void backgroundoff (void);
extern void backgroundfn (void (*func)(void));
/*
* Misc functions
*/
extern int ffs (int mask);
extern int Random (unsigned a, unsigned b);
#if defined (__HIGHC__)
extern int system (const char *cmd);
pragma Alias (system, "_mw_watt_system");
#endif
#ifdef __cplusplus
};
#endif
#endif /* __WATTCP_H */
#endif /* __WATT_TCP_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -