made tunslip6 take an argument for TAP/TUN

This commit is contained in:
joxe 2010-04-16 12:39:46 +00:00
parent 75690c3399
commit 9f00170c59

View file

@ -1,6 +1,6 @@
/* /*
* Copyright (c) 2001, Adam Dunkels. * Copyright (c) 2001, Adam Dunkels.
* Copyright (c) 2009, Joakim Eriksson, Niclas Finne. * Copyright (c) 2009, 2010 Joakim Eriksson, Niclas Finne.
* All rights reserved. * All rights reserved.
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@ -29,7 +29,7 @@
* *
* This file is part of the uIP TCP/IP stack. * This file is part of the uIP TCP/IP stack.
* *
* $Id: tunslip6.c,v 1.1 2010/04/02 18:17:20 joxe Exp $ * $Id: tunslip6.c,v 1.2 2010/04/16 12:39:46 joxe Exp $
* *
*/ */
@ -363,7 +363,7 @@ devopen(const char *dev, int flags)
#include <linux/if_tun.h> #include <linux/if_tun.h>
int int
tun_alloc(char *dev) tun_alloc(char *dev, int tap)
{ {
struct ifreq ifr; struct ifreq ifr;
int fd, err; int fd, err;
@ -378,7 +378,7 @@ tun_alloc(char *dev)
* *
* IFF_NO_PI - Do not provide packet information * IFF_NO_PI - Do not provide packet information
*/ */
ifr.ifr_flags = IFF_TUN | IFF_NO_PI; ifr.ifr_flags = (tap ? IFF_TAP : IFF_TUN) | IFF_NO_PI;
if(*dev != 0) if(*dev != 0)
strncpy(ifr.ifr_name, dev, IFNAMSIZ); strncpy(ifr.ifr_name, dev, IFNAMSIZ);
@ -391,7 +391,7 @@ tun_alloc(char *dev)
} }
#else #else
int int
tun_alloc(char *dev) tun_alloc(char *dev, int tap)
{ {
return devopen(dev, O_RDWR); return devopen(dev, O_RDWR);
} }
@ -406,7 +406,6 @@ cleanup(void)
ssystem("ifconfig %s down", tundev); ssystem("ifconfig %s down", tundev);
#ifndef linux #ifndef linux
ssystem("sysctl -w net.ipv6.conf.all.forwarding=1"); ssystem("sysctl -w net.ipv6.conf.all.forwarding=1");
Adam Dunkels.
#endif #endif
/* ssystem("arp -d %s", ipaddr); */ /* ssystem("arp -d %s", ipaddr); */
ssystem("netstat -nr" ssystem("netstat -nr"
@ -467,10 +466,11 @@ main(int argc, char **argv)
FILE *inslip; FILE *inslip;
const char *siodev = NULL; const char *siodev = NULL;
int baudrate = -2; int baudrate = -2;
int tap = 0;
setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */ setvbuf(stdout, NULL, _IOLBF, 0); /* Line buffered output. */
while((c = getopt(argc, argv, "B:D:hs:t:v:")) != -1) { while((c = getopt(argc, argv, "B:D:hs:t:v:T")) != -1) {
switch (c) { switch (c) {
case 'B': case 'B':
baudrate = atoi(optarg); baudrate = atoi(optarg);
@ -494,10 +494,14 @@ main(int argc, char **argv)
case 'v': case 'v':
verbose = 1; verbose = 1;
break; break;
case 'T':
printf("TAP");
tap = 1;
break;
case '?': case '?':
case 'h': case 'h':
default: default:
err(1, "usage: tunslip6 [-B baudrate] [-s siodev] [-t tundev] ipaddress"); err(1, "usage: tunslip6 [-B baudrate] [-s siodev] [-t tundev] [-T] ipaddress");
break; break;
} }
} }
@ -505,7 +509,7 @@ main(int argc, char **argv)
argv += (optind - 1); argv += (optind - 1);
if(argc != 2 && argc != 3) { if(argc != 2 && argc != 3) {
err(1, "usage: tunslip6 [-B baudrate] [-s siodev] [-t tundev] ipaddress "); err(1, "usage: tunslip6 [-B baudrate] [-s siodev] [-t tundev] [-T] ipaddress ");
} }
ipaddr = argv[1]; ipaddr = argv[1];
@ -559,7 +563,7 @@ main(int argc, char **argv)
inslip = fdopen(slipfd, "r"); inslip = fdopen(slipfd, "r");
if(inslip == NULL) err(1, "main: fdopen"); if(inslip == NULL) err(1, "main: fdopen");
tunfd = tun_alloc(tundev); tunfd = tun_alloc(tundev, tap);
if(tunfd == -1) err(1, "main: open"); if(tunfd == -1) err(1, "main: open");
fprintf(stderr, "opened device ``/dev/%s''\n", tundev); fprintf(stderr, "opened device ``/dev/%s''\n", tundev);