home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / NEWWATCP.ZIP / INCLUDE / TCP.H < prev    next >
Encoding:
C/C++ Source or Header  |  1993-11-05  |  8.5 KB  |  285 lines

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