home *** CD-ROM | disk | FTP | other *** search
/ Collection of Internet / Collection of Internet.iso / msdos / lynx / source / wattcp / src / udp_nds.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-10-25  |  994 b   |  60 lines

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