chiark / gitweb /
Set unet devices to be point-to-point.
authormdw <mdw>
Mon, 19 Feb 2001 19:10:45 +0000 (19:10 +0000)
committermdw <mdw>
Mon, 19 Feb 2001 19:10:45 +0000 (19:10 +0000)
tun-unet.c

index cc1e40720dc3fa791365819762ca8e865588741f..99359d7a0d7a33e580ff2be8b3c981689903d28e 100644 (file)
@@ -1,6 +1,6 @@
 /* -*-c-*-
  *
- * $Id: tun-unet.c,v 1.3 2001/02/05 19:55:00 mdw Exp $
+ * $Id: tun-unet.c,v 1.4 2001/02/19 19:10:45 mdw Exp $
  *
  * Tunnel interface based on Linux Usernet
  *
@@ -29,6 +29,9 @@
 /*----- Revision history --------------------------------------------------* 
  *
  * $Log: tun-unet.c,v $
+ * Revision 1.4  2001/02/19 19:10:45  mdw
+ * Set unet devices to be point-to-point.
+ *
  * Revision 1.3  2001/02/05 19:55:00  mdw
  * Guard against inappropriate compilation.
  *
@@ -45,6 +48,7 @@
 #include "tripe.h"
 
 #include <sys/ioctl.h>
+#include <net/if.h>
 #include <unet.h>
 
 /*----- Main code ---------------------------------------------------------*/
@@ -111,12 +115,19 @@ void tun_init(void)
 int tun_create(tunnel *t, peer *p)
 {
   int fd;
+  int f;
 
   if ((fd = open("/dev/unet", O_RDWR)) < 0) {
     a_warn("open `/dev/unet' failed: %s", strerror(errno));
     return (-1);
   }
   fdflags(fd, O_NONBLOCK, O_NONBLOCK, FD_CLOEXEC, FD_CLOEXEC);
+  if ((f = ioctl(fd, UNIOCGIFFLAGS)) < 0 ||
+      ioctl(fd, UNIOCSIFFLAGS, f | IFF_POINTOPOINT)) {
+    a_warn("couldn't set point-to-point flag: %s", strerror(errno));
+    close(fd);
+    return (-1);
+  }
   t->p = p;
   sel_initfile(&sel, &t->f, fd, SEL_READ, t_read, t);
   sel_addfile(&t->f);