Previous fix fixed. Meta protocol should be really flawless from now on!
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 2 May 2000 09:55:34 +0000 (09:55 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 2 May 2000 09:55:34 +0000 (09:55 +0000)
src/net.c
src/net.h
src/protocol.c

index 69616b484740393064e173772b35566c06094382..ebcaeb3652f98db1024229ed81692c4ad8b7ad6d 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -956,19 +956,19 @@ cp
 
   for(;;)
     {
-      p=0;
+      cl->reqlen = 0;
 
       for(i = oldlen; i < cl->buflen; i++)
         {
           if(cl->buffer[i] == '\n')
             {
-              p = i + 1;
-              cl->buffer[p] = 0;  /* add end-of-string so we can use sscanf */
+              cl->buffer[i] = 0;  /* replace end-of-line by end-of-string so we can use sscanf */
+              cl->reqlen = i + 1;
               break;
             }
         }
 
-      if(p)
+      if(cl->reqlen)
         {
           if(sscanf(cl->buffer, "%d", &request) == 1)
             {
@@ -988,8 +988,8 @@ cp
               syslog(LOG_ERR, "Bogus data received: %s", cl->buffer);
             }
 
-          cl->buflen -= p;
-          memmove(cl->buffer, cl->buffer + p, cl->buflen);
+          cl->buflen -= cl->reqlen;
+          memmove(cl->buffer, cl->buffer + cl->reqlen, cl->buflen);
           oldlen = 0;
         }
       else
index 27a16cf8ad5d2457c7038a52a0d418030bc4b831..dffc7cb13b59a79236b39fff58fa5424e6a1e4ff 100644 (file)
--- a/src/net.h
+++ b/src/net.h
@@ -114,6 +114,7 @@ typedef struct conn_list_t {
   enc_key_t *key;                  /* encrypt with this key */
   char buffer[MAXBUFSIZE];         /* metadata input buffer */
   int buflen;                      /* bytes read into buffer */
+  int reqlen;                      /* length of first request in buffer */
   struct conn_list_t *nexthop;     /* nearest meta-hop in this direction */
   struct conn_list_t *next;        /* after all, it's a list of connections */
 } conn_list_t;
index 0a27692e89282f26dd9e95b2a6dc85b3e35d42cc..c6b6fec6660e0ed84c756fa77a21112221acc0e5 100644 (file)
@@ -616,7 +616,9 @@ cp
     syslog(LOG_DEBUG, "Forwarding request for public key to " IP_ADDR_S,
           IP_ADDR_V(fw->nexthop->vpn_ip));
   
-  if(write(fw->nexthop->meta_socket, cl->buffer, strlen(cl->buffer)) < 0)
+  cl->buffer[cl->reqlen-1] = '\n';
+  
+  if(write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen) < 0)
     {
       syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
       return -1;
@@ -711,7 +713,9 @@ cp
     syslog(LOG_DEBUG, "Forwarding public key to " IP_ADDR_S,
           IP_ADDR_V(fw->nexthop->vpn_ip));
 
-  if((write(fw->nexthop->meta_socket, cl->buffer, strlen(cl->buffer))) < 0)
+  cl->buffer[cl->reqlen-1] = '\n';
+
+  if((write(fw->nexthop->meta_socket, cl->buffer, cl->reqlen)) < 0)
     {
       syslog(LOG_ERR, "send failed: %s:%d: %m", __FILE__, __LINE__);
       return -1;