chiark / gitweb /
Licensing: Update copyright dates for Ian Jackson
[adns.git] / src / setup.c
index 79e00e13ff71220b7e0494984e1d2a25dad30a56..6060a0807dc70d19012a9747009e9749739a1471 100644 (file)
@@ -5,14 +5,14 @@
  */
 /*
  *  This file is part of adns, which is
- *    Copyright (C) 1997-2000,2003,2006  Ian Jackson
+ *    Copyright (C) 1997-2000,2003,2006,2014  Ian Jackson
  *    Copyright (C) 1999-2000,2003,2006  Tony Finch
  *    Copyright (C) 1991 Massachusetts Institute of Technology
  *  (See the file INSTALL for full details.)
  *  
  *  This program is free software; you can redistribute it and/or modify
  *  it under the terms of the GNU General Public License as published by
- *  the Free Software Foundation; either version 2, or (at your option)
+ *  the Free Software Foundation; either version 3, or (at your option)
  *  any later version.
  *  
  *  This program is distributed in the hope that it will be useful,
@@ -21,8 +21,7 @@
  *  GNU General Public License for more details.
  *  
  *  You should have received a copy of the GNU General Public License
- *  along with this program; if not, write to the Free Software Foundation,
- *  Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
+ *  along with this program; if not, write to the Free Software Foundation.
  */
 
 #include <stdlib.h>
@@ -41,7 +40,7 @@
 
 static void readconfig(adns_state ads, const char *filename, int warnmissing);
 
-static void addserver(adns_state ads, const struct sockaddr *sa, int n) {
+static void addserver(adns_state ads, const struct sockaddr *sa, int salen) {
   int i;
   adns_rr_addr *ss;
   char buf[ADNS_ADDR2TEXT_BUFLEN];
@@ -61,9 +60,9 @@ static void addserver(adns_state ads, const struct sockaddr *sa, int n) {
   }
 
   ss= ads->servers+ads->nservers;
-  assert(n <= sizeof(ss->addr));
-  ss->len = n;
-  memcpy(&ss->addr, sa, n);
+  assert(salen <= sizeof(ss->addr));
+  ss->len = salen;
+  memcpy(&ss->addr, sa, salen);
   ads->nservers++;
 }
 
@@ -580,7 +579,7 @@ static int init_begin(adns_state *ads_r, adns_initflags flags,
   LIST_INIT(ads->intdone);
   ads->forallnext= 0;
   ads->nextid= 0x311f;
-  ads->nudp= 0;
+  ads->nudpsockets= 0;
   ads->tcpsocket= -1;
   adns__vbuf_init(&ads->tcpsend);
   adns__vbuf_init(&ads->tcprecv);
@@ -604,7 +603,7 @@ static int init_finish(adns_state ads) {
   struct sockaddr_in sin;
   struct protoent *proto;
   struct udpsocket *udp;
-  int i, j;
+  int i;
   int r;
   
   if (!ads->nservers) {
@@ -618,16 +617,16 @@ static int init_finish(adns_state ads) {
   }
 
   proto= getprotobyname("udp"); if (!proto) { r= ENOPROTOOPT; goto x_free; }
-  ads->nudp= 0;
+  ads->nudpsockets= 0;
   for (i=0; i<ads->nservers; i++) {
     if (adns__udpsocket_by_af(ads, ads->servers[i].addr.sa.sa_family))
       continue;
-    assert(ads->nudp < MAXUDP);
-    udp= &ads->udpsocket[ads->nudp];
+    assert(ads->nudpsockets < MAXUDP);
+    udp= &ads->udpsockets[ads->nudpsockets];
     udp->af= ads->servers[i].addr.sa.sa_family;
     udp->fd= socket(udp->af,SOCK_DGRAM,proto->p_proto);
     if (udp->fd < 0) { r= errno; goto x_free; }
-    ads->nudp++;
+    ads->nudpsockets++;
     r= adns__setnonblock(ads,udp->fd);
     if (r) { r= errno; goto x_closeudp; }
   }
@@ -635,7 +634,7 @@ static int init_finish(adns_state ads) {
   return 0;
 
  x_closeudp:
-  for (j=0; j<ads->nudp; j++) close(ads->udpsocket[j].fd);
+  for (i=0; i<ads->nudpsockets; i++) close(ads->udpsockets[i].fd);
  x_free:
   free(ads);
   return r;
@@ -752,7 +751,7 @@ void adns_finish(adns_state ads) {
     else if (ads->intdone.head) adns__cancel(ads->output.head);
     else break;
   }
-  for (i=0; i<ads->nudp; i++) close(ads->udpsocket[i].fd);
+  for (i=0; i<ads->nudpsockets; i++) close(ads->udpsockets[i].fd);
   if (ads->tcpsocket >= 0) close(ads->tcpsocket);
   adns__vbuf_free(&ads->tcpsend);
   adns__vbuf_free(&ads->tcprecv);