X-Git-Url: https://git.distorted.org.uk/~mdw/tripe/blobdiff_plain/650a6624cf72fe28e52a29a78de0f1cbfab44d7b..7631176f5c140b9c77fa865ef3b2287fd574e4d7:/tun-unet.c diff --git a/tun-unet.c b/tun-unet.c index 57e1397d..80cf7306 100644 --- a/tun-unet.c +++ b/tun-unet.c @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: tun-unet.c,v 1.2 2001/02/04 17:10:58 mdw Exp $ + * $Id: tun-unet.c,v 1.5 2002/01/13 14:57:05 mdw Exp $ * * Tunnel interface based on Linux Usernet * @@ -29,6 +29,15 @@ /*----- Revision history --------------------------------------------------* * * $Log: tun-unet.c,v $ + * Revision 1.5 2002/01/13 14:57:05 mdw + * Make @t_read@ be static, as it always should have been. + * + * 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. + * * Revision 1.2 2001/02/04 17:10:58 mdw * Make file descriptors be nonblocking and close-on-exec. * @@ -42,10 +51,15 @@ #include "tripe.h" #include +#include #include /*----- Main code ---------------------------------------------------------*/ +#if TUN_TYPE != TUN_UNET +# error "Tunnel type mismatch: fix the Makefile" +#endif + /* --- @t_read@ --- * * * Arguments: @int fd@ = file descriptor to read @@ -57,7 +71,7 @@ * Use: Reads data from the tunnel. */ -void t_read(int fd, unsigned mode, void *v) +static void t_read(int fd, unsigned mode, void *v) { tunnel *t = v; ssize_t n; @@ -104,12 +118,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);