home *** CD-ROM | disk | FTP | other *** search
/ Super Net 1 / SUPERNET_1.iso / PC / OTROS / MSDOS / WATTCP / MSWATTCP.ZIP / SRC / UDP_NDS.C < prev   
Encoding:
C/C++ Source or Header  |  1993-03-25  |  977 b   |  61 lines

  1. /****
  2.  *
  3.  * File: udp_nds.c
  4.  *
  5.  * 18-Jun-92 lr
  6.  *
  7.  */
  8.  
  9. #include <tcp.h>
  10. #include <string.h>
  11. #include <ctype.h>
  12.  
  13. /*
  14.  * Name Domain Service
  15.  *
  16.  * V
  17.  *  0.0 : Jan 11, 1991 : E. Engelke
  18.  */
  19.  
  20. /*
  21.  * aton()
  22.  *    - converts [a.b.c.d] or a.b.c.d to 32 bit long
  23.  *    - returns 0 on error (safer than -1)
  24.  */
  25.  
  26. longword
  27. aton( char *text )
  28. {
  29.     int i, cur;
  30.     longword ip=0;
  31.  
  32.     if ( *text == '[' ) ++text;
  33.     for ( i = 24; i >= 0; i -= 8 ) {
  34.     cur = atoi( text );
  35.     ip |= (longword)(cur & 0xff) << i;
  36.     if (!i) return( ip );
  37.  
  38.     if (!(text = strchr( text, '.')))
  39.         return( 0 );    /* return 0 on error */
  40.     ++text;
  41.     }
  42.     return(ip); /* NOTREACHED */
  43. }
  44.  
  45. /*
  46.  * isaddr
  47.  *    - returns nonzero if text is simply ip address
  48.  */
  49. word
  50. isaddr( char *text )
  51. {
  52.     char ch;
  53.     while ( ch = *text++ ) {
  54.     if ( isdigit(ch) ) continue;
  55.     if ( ch == '.' || ch == ' ' || ch == '[' || ch == ']' )
  56.         continue;
  57.     return( 0 );
  58.     }
  59.     return( 1 );
  60. }
  61.