TCP.H
Upload User: qiye66666
Upload Date: 2007-01-03
Package Size: 202k
Code Size: 8k
Category:

TCP/IP Stack

Development Platform:

Visual C++

  1. /*
  2.  * Waterloo TCP
  3.  *
  4.  * Copyright 1991, University of Waterloo
  5.  *
  6.  * This library is free software; you can use it or redistribute under
  7.  * the terms of the license included in LICENSE.H.
  8.  *
  9.  * This program is distributed in the hope that it will be useful,
  10.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  12.  * file LICENSE.H for more details.
  13.  *
  14.  * This network library was created by Erick Engelke of the University of
  15.  * Waterloo, Waterloo, Ontario, Canada.
  16.  *
  17.  * Name resolution services were adapted from sources made available by
  18.  * the National Centre for Supercomputer Applications (NCSA) and Clarkson
  19.  * University.
  20.  *
  21.  */
  22. #ifdef OLD
  23. #define sock_Read       sock_read
  24. #define sock_FastRead   sock_fastread
  25. #define sock_Write      sock_write
  26. #define sock_FastWrite  sock_fastwrite
  27. #define sock_Flush      sock_flush
  28. #define sock_FlushNext  sock_flushnext
  29. #define sock_Puts       sock_puts
  30. #define sock_Gets       sock_gets
  31. #define sock_Putc       sock_putc
  32. #define sock_Getc       sock_getc
  33. #define sock_DataReady  sock_dataready
  34. #define sock_Close      sock_close
  35. #define sock_Abort      sock_abort
  36. #define sock_Printf     sock_printf
  37. #define sock_Scanf      sock_scanf
  38. #define udp_Open        udp_open
  39. #define tcp_Open        tcp_open
  40. #define tcp_Listen      tcp_listen
  41. #endif OLD
  42. /* Kernal version (major major minor minor) */
  43. #define WTCP_VER 0x0102
  44. /*
  45.  * Typedefs and constants
  46.  */
  47. #ifndef byte
  48. typedef unsigned char byte;
  49. #endif  byte
  50. #ifndef word
  51. typedef unsigned int word;
  52. #endif  word
  53. #ifndef longword
  54. typedef unsigned long longword;
  55. #endif  longword
  56. typedef struct {
  57.     byte undoc[ 4300 ];
  58. } tcp_Socket;
  59. typedef struct {
  60.     byte undoc[ 2200 ];
  61. } udp_Socket;
  62. typedef struct sockaddr {
  63.     word        s_type;
  64.     word        s_port;
  65.     longword    s_ip;
  66.     byte        s_spares[6];    /* unused in TCP realm */
  67. };
  68. #define MAX_COOKIES     10
  69. #define MAX_NAMESERVERS 10
  70. #define TCP_MODE_BINARY 0
  71. #define TCP_MODE_ASCII 1
  72. #define UDP_MODE_CHK 0 /*default to checksum */
  73. #define UDP_MODE_NOCHK 2
  74. #define TCP_MODE_NAGLE  0       /* Nagle algorithm */
  75. #define TCP_MODE_NONAGLE 4
  76. sock_init();
  77. /*
  78.  *   s is the pointer to a udp or tcp socket
  79.  */
  80. sock_read(void  *s, byte *dp, int len );
  81. sock_fastread(void  *s, byte *dp, int len );
  82. sock_write(void  *s, byte *dp, int len);
  83. void sock_enqueue(void  *s, byte *dp, int len);
  84. sock_fastwrite(void *s, byte *dp, int len );
  85. sock_flush( void  *s );
  86. sock_flushnext( void  *s);
  87. sock_puts( void  *s, byte *dp );
  88. word sock_gets( void  *s, byte *dp, int n );
  89. byte sock_putc( void  *s, byte c );
  90. byte sock_getc( void  *s );
  91. word sock_dataready( void  *s );
  92. sock_close( void *s );
  93. sock_abort( void *s );
  94. sock_printf( void  *s, char *format, ... );
  95. sock_scanf( void  *s, char *format, ... );
  96. sock_mode( void *s, word mode ); /* see TCP_MODE_... */
  97. db_write( char *msg );
  98. dbuginit();
  99. /*
  100.  * TCP or UDP specific stuff, must be used for open's and listens, but
  101.  * sock stuff is used for everything else
  102.  */
  103. int udp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  104. int tcp_open(void *s, word lport, longword ina, word port, int (*datahandler)());
  105. tcp_listen(void *s, word lport, longword ina, word port, int (*datahandler)(), word timeout);
  106. int tcp_established(void *s);
  107. char *rip( char *s );
  108. longword resolve( char *name);
  109. /*
  110.  * less general functions
  111.  */
  112. longword aton( char *text );
  113. int isaddr( char *text );
  114. tcp_cbreak( word mode );
  115. longword intel( longword x );
  116. word intel16( word x );
  117. /*
  118.  * timers
  119.  */
  120. void ip_timer_init( void *s , word delayseconds );
  121. word ip_timer_expired( void *s );
  122.         /*
  123.          * TCP/IP system variables - do not change these since they
  124.          *      are not necessarily the source variables, instead use
  125.          *      ip_Init function
  126.          */
  127. extern longword my_ip_addr;
  128. extern longword sin_mask;       /* eg.  0xfffffe00L */
  129. extern word sock_delay;
  130.         /*
  131.          * tcp_init/tcp_shutdown
  132.          *      - init/kill all tcp and lower services
  133.          *      - only call if you do not use sock_init
  134.          * (NOT RECOMMENDED)
  135.          */
  136. tcp_shutdown();
  137. tcp_Init();
  138. /*
  139.  * things you probably won't need to know about
  140.  */
  141. /*
  142.  * sock_debugdump
  143.  * - dump some socket control block parameters
  144.  * used for testing the kernal, not recommended
  145.  */
  146. sock_debugdump( void *s);
  147.         /*
  148.          * tcp_config - read a configuration file
  149.          *            - if special path desired, call after sock_init()
  150.          *            - null reads path from executable
  151.          * see sock_init();
  152.          */
  153. tcp_config( char *path );
  154.         /*
  155.          * tcp_tick - called periodically by user application in sock_wait_...
  156.          *          - returns 1 when our socket closes
  157.          */
  158. tcp_tick( void *s );
  159.         /*
  160.          * Retransmitter - called periodically to perform tcp retransmissions
  161.          *          - normally called from tcp_tick, you have to be pretty
  162.          *            low down to use this one
  163.          */
  164. tcp_Retransmitter();
  165.         /*
  166.          * tcp_set_debug_state - set 1 or reset 0 - depends on what I have done
  167.          */
  168. tcp_set_debug_state( word x );
  169. extern int _last_cookie;
  170. extern longword _cookie[MAX_COOKIES];
  171.         /*
  172.          * name domain constants
  173.          */
  174. extern char *def_domain;
  175. extern longword def_nameservers[ MAX_NAMESERVERS ];
  176. extern word wathndlcbrk;
  177. extern word watcbroke;
  178. /*
  179.  * sock_wait_... macros
  180.  */
  181. /*
  182.  * sock_wait_established()
  183.  * - waits then aborts if timeout on s connection
  184.  * sock_wait_input()
  185.  * - waits for received input on s
  186.  * - may not be valid input for sock_Gets... check returned length
  187.  * sock_tick()
  188.  * - do tick and jump on abort
  189.  * sock_wait_closed();
  190.  * - discards all received data
  191.  *
  192.  * jump to sock_err with contents of *statusptr set to
  193.  *  1 on closed
  194.  * -1 on timeout
  195.  *
  196.  */
  197. int _ip_delay0( void *s, int seconds, int (*fn)(), void *statusptr );
  198. int _ip_delay1( void *s, int seconds, int (*fn)(), void *statusptr );
  199. int _ip_delay2( void *s, int seconds, int (*fn)(), void *statusptr );
  200. unsigned long set_timeout( unsigned int seconds );
  201. unsigned long set_ttimeout( unsigned int ticks );
  202. int chk_timeout( unsigned long timeout );
  203. int tcp_tick( void *s );
  204. #define sock_wait_established( s, seconds, fn, statusptr ) 
  205.     if (_ip_delay0( s, seconds, fn, statusptr )) goto sock_err;
  206. #define sock_wait_input( s, seconds, fn , statusptr ) 
  207.     if (_ip_delay1( s, seconds, fn, statusptr )) goto sock_err;
  208. #define sock_tick( s, statusptr ) 
  209.     if ( !tcp_tick(s)) { if (statusptr) *statusptr = 1 ; goto sock_err; }
  210. #define sock_wait_closed(s, seconds, fn, statusptr )
  211.     if (_ip_delay2( s, seconds, fn, statusptr )) goto sock_err;
  212. /* user initialization file */
  213. extern void (*usr_init)();
  214. void outs( char far * string );
  215. longword aton( char * string);
  216. int _ping( longword host , longword countnum );
  217. longword _chk_ping( longword host , longword *ptr);
  218. void _arp_register( longword use, longword instead_of );
  219. void _eth_init();
  220. byte *_eth_formatpacket( void *eth_dest, word eth_type );
  221. void _eth_send( word len);
  222. void _eth_free( void *buf);
  223. byte *_eth_arrived( word *type_ptr);
  224. void _eth_release();
  225. /* bsd-similar stuff */
  226. int sock_rbsize( void *s );
  227. int sock_rbused( void *s );
  228. int sock_rbleft( void *s );
  229. int sock_tbsize( void *s );
  230. int sock_tbused( void *s );
  231. int sock_tbleft( void *s );
  232. _chk_socket( tcp_Socket *s );
  233. char *inet_ntoa( char *s, longword x );
  234. char *psocket( tcp_Socket *s );
  235. longword inet_addr( char *s );
  236. char *sockerr( tcp_Socket *s );
  237. char *sockstate( tcp_Socket *s );
  238. getpeername( tcp_Socket *s, void *dest, int *len );
  239. getsockname(  tcp_Socket *s, void *dest, int *len );
  240. longword gethostid();
  241. longword sethostid( longword ip );
  242. char *getdomainname( char *name, int length );
  243. char *setdomainname( char *string );
  244. char *gethostname( char *name, int length );
  245. char *sethostname( char *string );
  246. word ntohs( word a );
  247. word htons( word a );
  248. longword ntohl( longword x );
  249. longword htonl( longword x );
  250. void _arp_register( longword use, longword instead_of );
  251. int _arp_resolve( longword ina, void *ethap);
  252. extern _survivebootp;
  253. sock_stats( tcp_Socket *s, word *days, word *inactive, word *cwindow, word *avg, word *sd );