home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B97.ZIP / WATTSRC.ZIP / PCBSD.C < prev    next >
Text File  |  1994-11-28  |  2KB  |  95 lines

  1. #include <copyright.h>
  2. #include <stdio.h>
  3. #include <wattcp.h>
  4. #include <stdlib.h>    /* itoa */
  5. #include <string.h>
  6. #include <elib.h>
  7.  
  8. /*
  9.  * PCBSD - provide some typical BSD UNIX functionality
  10.  * Erick Engelke, Feb 22, 1991
  11.  */
  12.  
  13. /*
  14.  * chk_socket - determine whether a real socket or not
  15.  *
  16.  */
  17. int _chk_socket( sock_type *s )
  18. {
  19.     if ( s->tcp.ip_type == TCP_PROTO ) {
  20.     if ( s->tcp.state <= tcp_StateCLOSED)    /* skips invalid data */
  21.         return( 2 );
  22.     }
  23.     if ( s->udp.ip_type == UDP_PROTO ) return( 1 );
  24.     return( 0 );
  25. }
  26.  
  27. char *inet_ntoa( char *s, longword x )
  28. {
  29.  
  30.     itoa( x >> 24, s, 10 );
  31.     strcat( s, ".");
  32.     itoa( (x >> 16) & 0xff, strchr( s, 0), 10);
  33.     strcat( s, ".");
  34.     itoa( (x >> 8) & 0xff, strchr( s, 0), 10);
  35.     strcat( s, ".");
  36.     itoa( (x) & 0xff, strchr( s, 0), 10);
  37.     return( s );
  38. }
  39.  
  40. longword inet_addr( char *s )
  41. {
  42.     return( isaddr( s ) ? aton( s ) : 0 );
  43. }
  44.  
  45. char *sockerr( sock_type *s )
  46. {
  47.     if ( strlen( s->tcp.err_msg ) < 80 )
  48.     return( s->tcp.err_msg );
  49.     return( NULL );
  50. }
  51.  
  52. static char *sock_states[] = {
  53.     "Listen","SynSent","SynRec","Established","FinWt1","FinWt2","ClosWt","LastAck"
  54.     "TmWt","Closed"};
  55.  
  56. char *sockstate( sock_type *s )
  57. {
  58.     switch ( _chk_socket( s )) {
  59.        case  1 : return( "UDP Socket" );
  60.        case  2 : return( sock_states[ s->tcp.state ] );
  61.        default : return( "Not an active socket");
  62.     }
  63. }
  64.  
  65. longword gethostid(void)
  66. {
  67.     return( my_ip_addr );
  68. }
  69.  
  70. longword sethostid( longword ip )
  71. {
  72.     return( my_ip_addr = ip );
  73. }
  74.  
  75. word ntohs( word a )
  76. {
  77.     return( intel16(a) );
  78. }
  79.  
  80. word htons( word a )
  81. {
  82.     return( intel16(a) );
  83. }
  84.  
  85. longword ntohl( longword x )
  86. {
  87.     return( intel( x ));
  88. }
  89.  
  90. longword htonl( longword x )
  91. {
  92.     return( intel( x ));
  93. }
  94.  
  95.