home *** CD-ROM | disk | FTP | other *** search
/ ftp.wwiv.com / ftp.wwiv.com.zip / ftp.wwiv.com / pub / PPPBCKP / SRC / SRC15B95.ZIP / WATTSRC.ZIP / UDP_NDS.C < prev    next >
Text File  |  1994-11-28  |  989b  |  58 lines

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