Small fixes to allow correct compilation under FreeBSD (tested with 4.3)
[tinc] / src / net.c
index c3f89ca..b0d3cd1 100644 (file)
--- a/src/net.c
+++ b/src/net.c
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
-    $Id: net.c,v 1.35.4.105 2001/05/07 19:08:43 guus Exp $
+    $Id: net.c,v 1.35.4.109 2001/05/28 08:21:43 guus Exp $
 */
 
 #include "config.h"
 #include <fcntl.h>
 #include <netdb.h>
 #include <netinet/in.h>
-#include <netinet/ip.h>
-#include <netinet/tcp.h>
+#ifndef HAVE_FREEBSD
+ #include <netinet/ip.h>
+ #include <netinet/tcp.h>
+#endif
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
@@ -184,6 +186,17 @@ cp
 cp
 }
 
+void receive_tcppacket(connection_t *cl, char *buffer, int len)
+{
+  vpn_packet_t outpkt;
+cp
+  outpkt.len = len;
+  memcpy(outpkt.data, buffer, len);
+
+  receive_packet(cl, &outpkt);
+cp
+}
+
 void accept_packet(vpn_packet_t *packet)
 {
 cp
@@ -203,7 +216,7 @@ cp
       if(write(tap_fd, packet->data - 2, packet->len + 2) < 0)
         syslog(LOG_ERR, _("Can't write to ethertap device: %m"));
       else
-        total_tap_out += packet->len + 2;
+        total_tap_out += packet->len;
     }
 cp
 }
@@ -285,7 +298,7 @@ cp
    {
 #ifdef HAVE_LINUX
 # ifdef HAVE_TUNTAP
-      tapfname = "/dev/misc/net/tun";
+      tapfname = "/dev/net/tun";
 # else
       tapfname = "/dev/tap0";
 # endif
@@ -372,6 +385,7 @@ cp
   option = 1;
   setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option));
   setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
+#ifndef HAVE_FREEBSD
   setsockopt(nfd, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
 
   option = IPTOS_LOWDELAY;
@@ -386,6 +400,7 @@ cp
           return -1;
         }
     }
+#endif
 
   memset(&a, 0, sizeof(a));
   a.sin_family = AF_INET;
@@ -500,11 +515,12 @@ cp
 
   option = 1;
   setsockopt(cl->meta_socket, SOL_SOCKET, SO_KEEPALIVE, &option, sizeof(option));
+#ifndef HAVE_FREEBSD
   setsockopt(cl->meta_socket, SOL_TCP, TCP_NODELAY, &option, sizeof(option));
 
   option = IPTOS_LOWDELAY;
   setsockopt(cl->meta_socket, SOL_IP, IP_TOS, &option, sizeof(option));
-
+#endif
   /* Connect */
 
   a.sin_family = AF_INET;
@@ -848,11 +864,13 @@ cp
   cfg = get_config_val(upstreamcfg, config_connectto);
 
   if(!cfg)
-    if(upstreamcfg == config)
     {
-      /* No upstream IP given, we're listen only. */
-      signal(SIGALRM, SIG_IGN);
-      return;
+      if(upstreamcfg == config)
+      {
+        /* No upstream IP given, we're listen only. */
+        signal(SIGALRM, SIG_IGN);
+        return;
+      }
     }
   else
     {
@@ -1075,6 +1093,8 @@ cp
       return;
     }
 
+  cl->last_ping_time = time(NULL);
+
   receive_udppacket(cl, &pkt);
 cp
 }
@@ -1147,7 +1167,7 @@ cp
       syslog(LOG_NOTICE, _("Trying to re-establish outgoing connection in 5 seconds"));
     }
 
-  /* Inactivate */
+  /* Deactivate */
 
   cl->status.active = 0;
 cp
@@ -1286,7 +1306,7 @@ cp
       vp.len = lenin - 2;
     }
 
-  total_tap_in += lenin;
+  total_tap_in += vp.len;
 
   if(lenin < 32)
     {