home *** CD-ROM | disk | FTP | other *** search
/ Media Share 9 / MEDIASHARE_09.ISO / hamradio / wattcp.zip / UDP_NDS.C < prev    next >
C/C++ Source or Header  |  1991-09-05  |  950b  |  58 lines

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