Removed write_n() function.
[tinc] / src / net.c
index 1130fa9..fdedf55 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -109,27 +109,6 @@ cp
   return 0;
 }
 
-/*
-  write as many bytes as possible to the tap
-  device, possibly in multiple turns.
-*/
-int write_n(int fd, void *buf, size_t len)
-{
-  int r, done = 0;
-cp  
-  do
-    {
-      if((r = write(fd, buf, len)) < 0)
-       return -1;
-      len -= r;
-      buf += r;
-      done += r;
-    } while(len > 0);
-
-  return done;
-cp
-}
-
 int xrecv(conn_list_t *cl, void *packet)
 {
   vpn_packet_t vp;
@@ -157,13 +136,13 @@ cp
   if(debug_lvl > 3)
     syslog(LOG_DEBUG, "packet to queue: %d", s);
 
-  e = xmalloc(sizeof(queue_element_t));
+  e = xmalloc(sizeof(*e));
   e->packet = xmalloc(s);
   memcpy(e->packet, packet, s);
 
   if(!*q)
     {
-      *q = xmalloc(sizeof(packet_queue_t));
+      *q = xmalloc(sizeof(**q));
       (*q)->head = (*q)->tail = NULL;
     }
 
@@ -185,9 +164,8 @@ cp
 }
 
 /* Remove a queue element */
-void del_queue(packet_queue_t **q, packet_element_t *e)
+void del_queue(packet_queue_t **q, queue_element_t *e)
 {
-  queue_element_t *p, *n;
 cp
   free(e->packet);
 
@@ -230,7 +208,7 @@ cp
 void flush_queue(conn_list_t *cl, packet_queue_t **pq,
                 int (*function)(conn_list_t*,void*))
 {
-  queue_element_t *p, *prev = NULL, *next = NULL;
+  queue_element_t *p, *next = NULL;
 cp
   for(p = (*pq)->head; p != NULL; )
     {
@@ -307,7 +285,7 @@ cp
     {
       add_queue(&(cl->sq), packet, packet->len + 2);
       if(!cl->status.waitingforkey)
-       send_key_request(to);
+       send_key_request(cl->vpn_ip);                   /* Keys should be sent to the host running the tincd */
       return 0;
     }
 
@@ -795,7 +773,7 @@ cp
   if(rp.len >= 0)
     {
       f = lookup_conn(rp.from);
-      if(debug_lvl > 2)
+      if(debug_lvl > 3)
        syslog(LOG_DEBUG, "packet from " IP_ADDR_S " (len %d)",
               IP_ADDR_V(rp.from), rp.len);
       if(!f)
@@ -915,7 +893,7 @@ int handle_new_meta_connection(conn_list_t *cl)
 {
   conn_list_t *ncn;
   struct sockaddr client;
-  int nfd, len = sizeof(struct sockaddr);
+  int nfd, len = sizeof(client);
 cp
   if((nfd = accept(cl->meta_socket, &client, &len)) < 0)
     {
@@ -958,7 +936,7 @@ cp
       return -1;
     }
 
-  if((lenin = recv(cl->meta_socket, &tmp, sizeof(tmp), 0)) <= 0)
+  if((lenin = read(cl->meta_socket, &tmp, sizeof(tmp))) <= 0)
     {
       syslog(LOG_ERR, "Receive failed: %m");
       return -1;
@@ -1062,10 +1040,10 @@ cp
   from = ntohl(*((unsigned long*)(&vp.data[26])));
   to = ntohl(*((unsigned long*)(&vp.data[30])));
 
-  if(debug_lvl > 2)
+  if(debug_lvl > 3)
     syslog(LOG_DEBUG, "An IP packet (%04x) for " IP_ADDR_S " from " IP_ADDR_S,
           ether_type, IP_ADDR_V(to), IP_ADDR_V(from));
-  if(debug_lvl > 3)
+  if(debug_lvl > 4)
     syslog(LOG_DEBUG, MAC_ADDR_S " to " MAC_ADDR_S,
           MAC_ADDR_V(vp.data[0]), MAC_ADDR_V(vp.data[6]));