home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / WATTCP.ZIP / SRC / PCBSD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1993-07-15  |  1.7 KB  |  91 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. _chk_socket( tcp_Socket *s )
  18. {
  19.     if ( s->ip_type == TCP_PROTO ) {
  20.     if ( s->state <= tcp_StateCLOSED)    /* skips invalid data */
  21.         return( 2 );
  22.     }
  23.     if ( s->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( tcp_Socket *s )
  46. {
  47.     if ( strlen( s->err_msg ) < 80 )
  48.     return( s->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( tcp_Socket *s )
  57. {
  58.     switch ( _chk_socket( s )) {
  59.        case  1 : return( "UDP Socket" );
  60.        case  2 : return( sock_states[ s->state ] );
  61.        default : return( "Not an active socket");
  62.     }
  63. }
  64. longword gethostid()
  65. {
  66.     return( my_ip_addr );
  67. }
  68.  
  69. longword sethostid( longword ip )
  70. {
  71.     return( my_ip_addr = ip );
  72. }
  73.  
  74. word ntohs( word a )
  75. {
  76.     return( intel16(a) );
  77. }
  78. word htons( word a )
  79. {
  80.     return( intel16(a) );
  81. }
  82. longword ntohl( longword x )
  83. {
  84.     return( intel( x ));
  85. }
  86. longword htonl( longword x )
  87. {
  88.     return( intel( x ));
  89. }
  90.  
  91.