Comparing files:     (IBM Internal Use Only)           (Version 88/06/24)
  (1) host.c ....................................Fri Jan 10 23:12:42 1997
  (2) ..\wattcp\udp_dom.c .......................Fri Aug 23 13:00:08 1996

 Mismatch ͵
   1 #include <copyright.h>
   2 #include <mem.h>                        /* movmem() */
   3 #include <stdio.h>
   4 #include <string.h>
   5 #include <tcp.h>
   6 #include <elib.h>                       /* outs() */
Ĵ
   1 #define JOEL_DEBUG      0

 Mismatch ͵
  21 
  22 /* These next 'constants' are loaded from WATTCP.CFG file */
  23 
  24 extern char *def_domain;
  25 extern char *loc_domain;       /* current subname to be used by the domain system */
  26 
  27 extern longword def_nameservers[ MAX_NAMESERVERS ];
  28 extern int _last_nameserver;
  29 extern word _domaintimeout = 0;
Ĵ
  16 #include "..\wattcp\copyright.h"
  17 #include <stdio.h>
  18 #include <string.h>
  19 #include <mem.h>            /* movmem() */
  20 #include "..\wattcp\tcp.h"
  21 #include "..\wattcp\elib.h"
  22 
  23 /* These next 'constants' are loaded from WATTCP.CFG file */
  24 
  25 char *def_domain;
  26 char *loc_domain;       /* current subname to be used by the domain system */
  27 
  28 longword def_nameservers[ MAX_NAMESERVERS ];
  29 int _last_nameserver;
  30 word _domaintimeout = 0;

 Mismatch ͵
  39 #define DOMSIZE 512             /* maximum domain message size to mess with */
Ĵ
  40 #define DOMSIZE 512                             /* maximum domain message size to mess with */

 Mismatch ͵
  47 word    ident,      /* unique identifier */
  48 flags,
  49 qdcount,    /* question section, # of entries */
  50 ancount,    /* answers, how many */
  51 nscount,    /* count of name server RRs */
  52 arcount;    /* number of "additional" records */
Ĵ
  48 word        ident,          /* unique identifier */
  49 flags,
  50 qdcount,        /* question section, # of entries */
  51 ancount,        /* answers, how many */
  52 nscount,        /* count of name server RRs */
  53 arcount;        /* number of "additional" records */

 Mismatch ͵
  58 #define DQR     0x8000  /* query = 0, response = 1 */
  59 #define DOPCODE     0x7100  /* opcode, see below */
  60 #define DAA     0x0400  /* Authoritative answer */
  61 #define DTC     0x0200  /* Truncation, response was cut off at 512 */
  62 #define DRD     0x0100  /* Recursion desired */
  63 #define DRA     0x0080  /* Recursion available */
  64 #define DRCODE      0x000F  /* response code, see below */
  65 
  66 /* opcode possible values: */
  67 #define DOPQUERY    0   /* a standard query */
  68 #define DOPIQ           1       /* an inverse query */
  69 #define DOPCQM      2   /* a completion query, multiple reply */
  70 #define DOPCQU      3       /* a completion query, single reply */
  71 /* the rest reserved for future */
  72 
  73 /* legal response codes: */
  74 #define DROK    0       /* okay response */
  75 #define DRFORM  1       /* format error */
  76 #define DRFAIL  2       /* their problem, server failed */
  77 #define DRNAME  3       /* name error, we know name doesn't exist */
  78 #define DRNOPE  4       /* no can do request */
  79 #define DRNOWAY 5       /* name server refusing to do request */
  80 
  81 #define DTYPEA      1   /* host address resource record (RR) */
  82 #define DTYPEPTR    12  /* a domain name ptr */
  83 
  84 #define DIN     1   /* ARPA internet class */
  85 #define DWILD       255 /* wildcard for several of the classifications */
Ĵ
  59 #define DQR             0x8000  /* query = 0, response = 1 */
  60 #define DOPCODE         0x7100  /* opcode, see below */
  61 #define DAA             0x0400  /* Authoritative answer */
  62 #define DTC             0x0200  /* Truncation, response was cut off at 512 */
  63 #define DRD             0x0100  /* Recursion desired */
  64 #define DRA             0x0080  /* Recursion available */
  65 #define DRCODE          0x000F  /* response code, see below */
  66 
  67 /* opcode possible values: */
  68 #define DOPQUERY        0       /* a standard query */
  69 #define DOPIQ           1       /* an inverse query */
  70 #define DOPCQM          2       /* a completion query, multiple reply */
  71 #define DOPCQU          3       /* a completion query, single reply */
  72 /* the rest reserved for future */
  73 
  74 /* legal response codes: */
  75 #define DROK    0               /* okay response */
  76 #define DRFORM  1               /* format error */
  77 #define DRFAIL  2               /* their problem, server failed */
  78 #define DRNAME  3               /* name error, we know name doesn't exist */
  79 #define DRNOPE  4               /* no can do request */
  80 #define DRNOWAY 5               /* name server refusing to do request */
  81 
  82 #define DTYPEA          1       /* host address resource record (RR) */
  83 #define DTYPEPTR        12      /* a domain name ptr */
  84 
  85 #define DIN             1       /* ARPA internet class */
  86 #define DWILD           255     /* wildcard for several of the classifications */

 Mismatch ͵
  92 word    rtype,      /* resource record type = DTYPEA */
  93 rclass;     /* RR class = DIN */
  94 longword    ttl;        /* time-to-live, changed to 32 bits */
  95 word    rdlength;   /* length of next field */
  96 byte    rdata[DOMSIZE]; /* data field */
Ĵ
  93 word        rtype,          /* resource record type = DTYPEA */
  94 rclass;         /* RR class = DIN */
  95 longword    ttl;            /* time-to-live, changed to 32 bits */
  96 word        rdlength;       /* length of next field */
  97 byte        rdata[DOMSIZE]; /* data field */

 Insert into (2) ͵ between lines 106 - 107 of (1)
 108 static void qinit( void )
 109 {
 110 question->h.flags = htons(DRD);
 111 question->h.qdcount = htons(1);
 112 question->h.ancount = 0;
 113 question->h.nscount = 0;
 114 question->h.arcount = 0;
 115 }

 Mismatch ͵
 115 static packdom(dst,src)
 116 char *src,*dst;
Ĵ
 124 static packdom(char *dst,char *src)

 Mismatch ͵
 125 do {            /* copy whole string */
Ĵ
 133 do {                        /* copy whole string */

 Mismatch ͵
 137 if (*p) {                   /* update pointers */
Ĵ
 145 if (*p) {                                       /* update pointers */

 Mismatch ͵
 143 p = loc_domain;     /* continue packing with default */
Ĵ
 151 p = loc_domain;             /* continue packing with default */

 Mismatch ͵
 151 return(q-savedst);          /* length of packed string */
Ĵ
 159 return(q-savedst);                  /* length of packed string */

 Mismatch ͵
 162 static unpackdom(dst,src,buf)
 163 char *src,*dst,buf[];
Ĵ
 170 static unpackdom(char *dst,char *src,char *buf)

 Mismatch ͵
 178 src = &buf[(j & 0x3f)*256+*src];        /* pointer dereference */
Ĵ
 185 src = &buf[(j & 0x3f)*256+*src];            /* pointer dereference */

 Mismatch ͵
 189 *(--dst) = 0;           /* add terminator */
 190 src++;                  /* account for terminator on src */
Ĵ
 196 *(--dst) = 0;                       /* add terminator */
 197 src++;                                      /* account for terminator on src */

 Mismatch ͵
 202 *   num is used as identifier
 203 */
 204 static sendom(s,towho,num)
 205 char *s;
 206 longword towho;
 207 word num;
Ĵ
 209 *       num is used as identifier
 210 */
 211 static sendom(char *s,longword towho,word num)

 Mismatch ͵
 213 i = packdom(&(question->x),s);
 214 
 215 p = &(question->x[i]);
 216 *p++ = 0;               /* high byte of qtype */
 217 *p++ = DTYPEA;          /* number is < 256, so we know high byte=0 */
 218 *p++ = 0;               /* high byte of qclass */
 219 *p++ = DIN;             /* qtype is < 256 */
 220 
 221 question->h.ident = intel16(num);
 222 ulen = sizeof(struct dhead)+(p-psave);
 223 
 224 udp_open( dom_sock, 997, towho, 53, NULL );    /* divide err */
 225 
 226 sock_write( dom_sock, question, ulen );
 227 return( ulen);
 228 }
 229 
 230 
 231 /*********************************************************************/
 232 /*  senrdom
 233 *   put together a reverse domain lookup packet and send it
 234 *   uses port 53
 235 *   num is used as identifier
 236 */
 237 static sendrdom(char *s, longword towhom, word num )
 238 {
 239 word i,ulen;
 240 byte *psave,*p;
 241 
 242 
 243 
 244 psave = (byte*)&(question->x);
 245 i = packdom(&(question->x),s);
 246 
 247 p = &(question->x[i]);
 248 *p++ = 0;               /* high byte of qtype */
 249 *p++ = DTYPEA;                      /* want host address */
 250 *p++ = 0;               /* high byte of qclass */
 251 *p++ = DIN;             /* qtype is < 256 */
 252 
 253 question->h.ident = intel16(num);
 254 ulen = sizeof(struct dhead)+(p-psave);
 255 
 256 udp_open( dom_sock, 997, towhom, 53, NULL );    /* divide err */
 257 
 258 sock_write( dom_sock, question, ulen );
 259 return( ulen);
 260 }
 261 
 262 static int countpaths(pathstring)
 263 char *pathstring;
Ĵ
 217 i = packdom((byte *)&(question->x),s);
 218 
 219 p = &(question->x[i]);
 220 *p++ = 0;                           /* high byte of qtype */
 221 *p++ = DTYPEA;                      /* number is < 256, so we know high byte=0 */
 222 *p++ = 0;                           /* high byte of qclass */
 223 *p++ = DIN;                         /* qtype is < 256 */
 224 
 225 question->h.ident = htons(num);
 226 ulen = sizeof(struct dhead)+(p-psave);
 227 
 228 if( !udp_open( dom_sock, 997, towho, 53, NULL ) )
 229 printf( "couldn't open DNS socket\n" );
 230 else
 231 {
 232 #if JOEL_DEBUG
 233 printf( "writing to DNS socket\n" );
 234 #endif
 235 sock_write( dom_sock, (byte *)question, ulen );
 236 }
 237 
 238 return( ulen);
 239 }
 240 
 241 int countpaths(char *pathstring)

 Mismatch ͵
 275 static char *getpath(pathstring,whichone)
 276 char *pathstring;            /* the path list to search      */
 277 int   whichone;               /* which path to get, starts at 1 */
Ĵ
 253 static char *getpath(char *pathstring,int whichone)
 254 /* the path list to search      */
 255 /* which path to get, starts at 1 */

 Mismatch ͵
 297 static longword ddextract(qp,mip)
 298 struct useek *qp;
 299 unsigned char *mip;
Ĵ
 275 static longword ddextract(struct useek *qp, longword *mip)

 Mismatch ͵
 305 nans = intel16(qp->h.ancount);      /* number of answers */
 306 rcode = DRCODE & intel16(qp->h.flags);  /* return code for this message*/
 307 if (rcode > 0)
 308 return(rcode);
 309 
 310 if (nans > 0 &&                             /* at least one answer */
 311 (intel16(qp->h.flags) & DQR)) {         /* response flag is set */
 312 p = (byte *)&qp->x;                 /* where question starts */
 313 i = unpackdom(space,p,qp);              /* unpack question name */
 314 /*  spec defines name then  QTYPE + QCLASS = 4 bytes */
 315 p += i+4;
 316 printf(" NAME : ? %s\n", space );
 317 
Ĵ
 281 nans = ntohs(qp->h.ancount);                /* number of answers */
 282 rcode = DRCODE & ntohs(qp->h.flags);        /* return code for this message*/
 283 if (rcode > 0)
 284 return(rcode);
 285 
 286 if (nans > 0 &&                                                             /* at least one answer */
 287 (ntohs(qp->h.flags) & DQR)) {               /* response flag is set */
 288 p = (byte *)&qp->x;                     /* where question starts */
 289 i = unpackdom(space, p, (char *)qp);                              /* unpack question name */
 290 /*  spec defines name then  QTYPE + QCLASS = 4 bytes */
 291 p += i+4;

 Mismatch ͵
 323 while (nans-- > 0) {                    /* look at each answer */
 324 i = unpackdom(space,p,qp);          /* answer name to unpack */
 325 /*          n_puts(space);*/
 326 p += i;                             /* account for string */
 327 rrp = (struct rrpart *)p;           /* resource record here */
 328 /*
 329 *  check things which might not align on 68000 chip one byte at a time
 330 */
 331 if (!*p && *(p+1) == DTYPEA &&      /* correct type and class */
 332 !*(p+2) && *(p+3) == DIN) {
 333 movmem(rrp->rdata,mip,4);   /* save IP #        */
 334 return(0);                      /* successful return */
 335 }
 336 movmem(&rrp->rdlength,&j,2);    /* 68000 alignment */
 337 p += 10+intel16(j);             /* length of rest of RR */
 338 }
 339 }
 340 
 341 return(-1);                     /* generic failed to parse */
Ĵ
 297 while (nans-- > 0) {                                    /* look at each answer */
 298 i = unpackdom( space, p, (char *)qp);                  /* answer name to unpack */
 299 /*                  n_puts(space);*/
 300 p += i;                                                             /* account for string */
 301 rrp = (struct rrpart *)p;                   /* resource record here */
 302 /*
 303 *  check things which might not align on 68000 chip one byte at a time
 304 */
 305 if (!*p && *(p+1) == DTYPEA &&              /* correct type and class */
 306 !*(p+2) && *(p+3) == DIN) {
 307 movmem(rrp->rdata,mip,4);       /* save IP #            */
 308 return(0);                                              /* successful return */
 309 }
 310 movmem(&rrp->rdlength,&j,2);        /* 68000 alignment */
 311 p += 10+ntohs(j);                         /* length of rest of RR */
 312 }
 313 }
 314 
 315 return(-1);                                         /* generic failed to parse */

 Mismatch ͵
 350 static longword udpdom()
Ĵ
 324 static longword udpdom( void )

 Mismatch ͵
 355 uret = sock_fastread(dom_sock, question, sizeof(struct useek ));
 356 /* this does not happen */
 357 if (uret < 0) {
 358 /*      netputevent(USERCLASS,DOMFAIL,-1);  */
 359 return(-1);
 360 }
 361 
 362 /* num = intel16(question->h.ident); */     /* get machine number */
Ĵ
 329 uret = sock_fastread( dom_sock, (byte *)question, sizeof(struct useek ));
 330 /* this does not happen */
 331 if (uret < 0) {
 332 /*              netputevent(USERCLASS,DOMFAIL,-1);  */
 333 return(-1);
 334 }
 335 
 336 /* num = ntohs(question->h.ident); */     /* get machine number */

 Mismatch ͵
 369 case 3: return(0);      /* name does not exist */
 370 case 0: return(intel(desired)); /* we found the IP number */
 371 case -1:return( 0 );        /* strange return code from ddextract */
Ĵ
 343 case 3: return(0);              /* name does not exist */
 344 case 0: return(ntohl(desired)); /* we found the IP number */
 345 case -1:return( 0 );            /* strange return code from ddextract */

 Mismatch ͵
 381 *   Returns the machine number of the machine record for future reference.
Ĵ
 355 *       Returns the machine number of the machine record for future reference.

 Mismatch ͵
 386 */
 387 static longword Sdomain(mname, adddom, nameserver, timedout )
 388 char *mname;
 389 int adddom;
 390 longword nameserver;
 391 int *timedout;  /* set to 1 on timeout */
 392 {
 393 char namebuff[512];
 394 int isaname;
 395 int domainsremaining;
 396 int status, i;
 397 longword response;
 398 
 399 isaname = !isaddr( mname );
Ĵ
 360 *
 361 *   timedout is set to 1 on timeout
 362 */
 363 static longword Sdomain(char *mname, int adddom, longword nameserver, byte *timedout )
 364 {
 365 char namebuff[512];
 366 //int domainsremaining;
 367 int status, i;
 368 longword response;
 369 

 Mismatch ͵
 413 question->h.flags = intel16(DRD);   /* use recursion */
 414 question->h.qdcount = 0;
 415 question->h.ancount = 0;
 416 question->h.nscount = 0;
 417 question->h.arcount = 0;
 418 
 419 //    qinit();                /* initialize some flag fields */
 420 
 421 strcpy( namebuff, mname );
 422 
 423 if ( isaname ) {
 424 /* forward lookup */
 425 /* only add these things if we are doing a real name */
 426 
 427 question->h.qdcount = intel16(1);
 428 if ( adddom ) {
 429 if(namebuff[strlen(namebuff)-1] != '.') {       /* if no trailing dot */
 430 if(loc_domain) {             /* there is a search list */
 431 domainsremaining = countpaths( loc_domain );
Ĵ
 383 qinit();                            /* initialize some flag fields */
 384 
 385 strcpy( namebuff, mname );
 386 
 387 if ( adddom ) {
 388 if(namebuff[strlen(namebuff)-1] != '.') {       /* if no trailing dot */
 389 if(loc_domain) {             /* there is a search list */
 390 //domainsremaining = countpaths( loc_domain );

 Mismatch ͵
 438 }
 439 } else {
 440 /* reverse lookup */
 441 question->h.ancount = intel16(1);
 442 
 443 }
Ĵ
 397 }           \
 398 

 Mismatch ͵
 450 if ( isaname ) sendom(namebuff,nameserver, 0xf001);    /* try UDP */
 451 else sendrdom( namebuff, nameserver, 0xf001 );
Ĵ
 405 sendom(namebuff,nameserver, 0xf001);    /* try UDP */

 Mismatch ͵
 466 if ( !*timedout ) break;    /* got an answer */
Ĵ
 420 if ( !*timedout ) break;        /* got an answer */

 Mismatch ͵
 478 *      domain or NULL when no more are available
Ĵ
 432 *              domain or NULL when no more are available

 Mismatch ͵
 497 * newresolve()
 498 *  convert domain name -> address resolution.
 499 *  returns 0 if name is unresolvable right now
 500 */
 501 longword newresolve(name)
 502 char *name;
Ĵ
 451 * resolve()
 452 *      convert domain name -> address resolution.
 453 *      returns 0 if name is unresolvable right now
 454 */
 455 longword resolve(char *name)

 Insert into (2) ͵ between lines 516 - 517 of (1)
 470 if ( isaddr( name ))
 471 return( aton( name ));
 472 

 Mismatch ͵
 527 if (!(loc_domain = nextdomain( def_domain, count )))
 528 count = -1; /* use default name */
 529 
 530 for ( i = 0; i < _last_nameserver ; ++i ) {
 531 if (!timeout[i])
 532 if (ip_address = Sdomain( name , count != -1 ,
 533 def_nameservers[i], &timeout[i] ))
 534 break;  /* got name, bail out of loop */
Ĵ
 483 loc_domain = nextdomain( def_domain, count );
 484 if( !loc_domain )
 485 count = -1;     /* use default name */
 486 
 487 for ( i = 0; i < _last_nameserver ; ++i ) {
 488 if (!timeout[i])
 489 {
 490 ip_address = Sdomain( name, count!=-1, def_nameservers[i], &timeout[i] );
 491 if( ip_address )
 492 break;      /* got name, bail out of loop */
 493 }

 Delete from (1) ͵ lines 546 - 582 of (1)
 546 
 547 
 548 main(int argc, char **argv )
 549 {
 550 char *name;
 551 longword host;
 552 int status,i;
 553 char buffer[ 20];
 554 
 555 if (argc < 2) {
 556 puts("HOST  hostname");
 557 exit(3);
 558 }
 559 
 560 sock_init();
 561 
 562 for ( i = 1 ; i < argc ; ++i ) {
 563 if ((*argv[i] == '/') || (*argv[i] == '-' )) {
 564 }
 565 else {
 566 name = strdup( argv[i] );
 567 
 568 printf("resolving \"%s\"...", name );
 569 host = newresolve( name );
 570 printf("\r");
 571 clreol();
 572 }
 573 }
 574 if ( host ) {
 575 printf("\r");
 576 clreol();
 577 printf("%s : %s\n", name, inet_ntoa( buffer , host ));
 578 }
 579 exit( host ? 0 : 1 );
 580 }
 581 /* udpdom &&  ddextract(question, &desired); */
 582 
 *** EOF ***
