~ubuntu-branches/debian/jessie/mtr/jessie

« back to all changes in this revision

Viewing changes to dns.c

  • Committer: Bazaar Package Importer
  • Author(s): Robert Woodcock
  • Date: 2010-09-06 16:53:54 UTC
  • mfrom: (1.2.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20100906165354-ywnqjfwf66f0shj0
Tags: 0.80-1
* New upstream version
* Add Homepage field to debian/control, closes: #314651
* Change Priority field to match that of the archive overrides,
  closes: #416567
* Lintian cleanups

Show diffs side-by-side

added added

removed removed

Lines of Context:
3
3
    Copyright (C) 1997,1998  Matt Kimball
4
4
 
5
5
    This program is free software; you can redistribute it and/or modify
6
 
    it under the terms of the GNU General Public License as published by
7
 
    the Free Software Foundation; either version 2 of the License, or
8
 
    (at your option) any later version.
 
6
    it under the terms of the GNU General Public License version 2 as 
 
7
    published by the Free Software Foundation.
9
8
 
10
9
    This program is distributed in the hope that it will be useful,
11
10
    but WITHOUT ANY WARRANTY; without even the implied warranty of
310
309
 
311
310
int use_dns = 1;
312
311
 
 
312
#ifdef res_ninit
 
313
#define MY_RES_INIT() res_ninit(&myres);
 
314
#define RES_MKQUERY(a, b, c, d, e, f, g, h, i) \
 
315
    res_nmkquery(&myres, a, b, c, d, e, f, g, h, i)
 
316
struct __res_state myres;
 
317
#else
 
318
#define MY_RES_INIT() res_init();
 
319
#define RES_MKQUERY(a, b, c, d, e, f, g, h, i) \
 
320
    res_mkquery(a, b, c, d, e, f, g, h, i)
 
321
#define myres _res
 
322
#endif
313
323
 
314
324
/* Code */
315
325
#ifdef CorruptCheck
484
494
{
485
495
  int option,i;
486
496
 
487
 
  res_init();
488
 
  if (!_res.nscount) {
 
497
  if (!dns) return;
 
498
  MY_RES_INIT();
 
499
  if (!myres.nscount) {
489
500
    fprintf(stderr,"No nameservers defined.\n");
490
501
    exit(-1);
491
502
  }
492
 
  _res.options|= RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
493
 
  for (i = 0;i < _res.nscount;i++)
494
 
    _res.nsaddr_list[i].sin_family = AF_INET;
 
503
  myres.options|= RES_RECURSE | RES_DEFNAMES | RES_DNSRCH;
 
504
  for (i = 0;i < myres.nscount;i++)
 
505
    myres.nsaddr_list[i].sin_family = AF_INET;
495
506
  resfd = socket(AF_INET, SOCK_DGRAM, 0);
496
507
  if (resfd == -1) {
497
508
    fprintf(stderr,"Unable to allocate socket for nameserver communication: %s\n",
874
885
{
875
886
  packetheader *hp;
876
887
  int r,i;
877
 
  int buf[(MaxPacketsize/sizeof (int))+1];
 
888
  unsigned char buf[MaxPacketsize];
878
889
 
879
 
  r = res_mkquery(QUERY,s,C_IN,type,NULL,0,NULL,(unsigned char*)buf,MaxPacketsize);
 
890
  r = RES_MKQUERY(QUERY,s,C_IN,type,NULL,0,NULL,(unsigned char*)buf,MaxPacketsize);
880
891
  if (r == -1) {
881
892
    restell("Resolver error: Query too large.");
882
893
    return;
883
894
  }
884
895
  hp = (packetheader *)buf;
885
896
  hp->id = id;  /* htons() deliberately left out (redundant) */
886
 
  for (i = 0;i < _res.nscount;i++)
887
 
    (void)sendto(resfd,buf,r,0,(struct sockaddr *)&_res.nsaddr_list[i],
 
897
  for (i = 0;i < myres.nscount;i++)
 
898
    (void)sendto(resfd,buf,r,0,(struct sockaddr *)&myres.nsaddr_list[i],
888
899
                 sizeof(struct sockaddr));
889
900
}
890
901
 
1240
1251
    /* Check to see if this server is actually one we sent to */
1241
1252
    if ( addrcmp( (void *) &(from4->sin_addr), (void *) &localhost,
1242
1253
                  (int) AF_INET ) == 0 ) {
1243
 
      for (i = 0;i < _res.nscount;i++)
1244
 
        if ( addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
 
1254
      for (i = 0;i < myres.nscount;i++)
 
1255
        if ( addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
1245
1256
                      (void *) &(from4->sin_addr), (int) AF_INET ) == 0 ||
1246
 
             addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
 
1257
             addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
1247
1258
                      (void *) &unspec_addr, (int) AF_INET ) == 0 )     /* 0.0.0.0 replies as 127.0.0.1 */
1248
1259
          break;
1249
1260
    } else
1250
 
      for (i = 0;i < _res.nscount;i++)
1251
 
        if ( addrcmp( (void *) &(_res.nsaddr_list[i].sin_addr),
 
1261
      for (i = 0;i < myres.nscount;i++)
 
1262
        if ( addrcmp( (void *) &(myres.nsaddr_list[i].sin_addr),
1252
1263
                      (void *) &(from4->sin_addr), AF_INET ) == 0 )
1253
1264
          break;
1254
 
    if (i == _res.nscount) {
 
1265
    if (i == myres.nscount) {
1255
1266
      snprintf(tempstring, sizeof(tempstring), "Resolver error: Received reply from unknown source: %s",
1256
1267
              inet_ntoa(from4->sin_addr ));
1257
1268
      restell(tempstring);