mirror of
https://github.com/brmlab/osmo-tetra.git
synced 2025-08-02 21:03:44 +02:00
modify tunctl to allow cration of TUN (ip) devices, not just TAP (ethernet)
This adds a '-U' command line argument to select TUN mode. Default remains the TAP case.
This commit is contained in:
parent
ceaf34016a
commit
24177bce48
1 changed files with 7 additions and 3 deletions
10
src/tunctl.c
10
src/tunctl.c
|
@ -22,7 +22,7 @@
|
||||||
static void Usage(char *name)
|
static void Usage(char *name)
|
||||||
{
|
{
|
||||||
fprintf(stderr, "Create: %s [-b] [-u owner] [-g group] [-t device-name] "
|
fprintf(stderr, "Create: %s [-b] [-u owner] [-g group] [-t device-name] "
|
||||||
"[-f tun-clone-device]\n", name);
|
"[-f tun-clone-device] [ -U ]\n", name);
|
||||||
fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n",
|
fprintf(stderr, "Delete: %s -d device-name [-f tun-clone-device]\n\n",
|
||||||
name);
|
name);
|
||||||
fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems"
|
fprintf(stderr, "The default tun clone device is /dev/net/tun - some systems"
|
||||||
|
@ -40,8 +40,9 @@ int main(int argc, char **argv)
|
||||||
gid_t group = -1;
|
gid_t group = -1;
|
||||||
int tap_fd, opt, delete = 0, brief = 0;
|
int tap_fd, opt, delete = 0, brief = 0;
|
||||||
char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
|
char *tun = "", *file = "/dev/net/tun", *name = argv[0], *end;
|
||||||
|
unsigned int iff_type = IFF_TAP;
|
||||||
|
|
||||||
while((opt = getopt(argc, argv, "bd:f:t:u:g:")) > 0){
|
while((opt = getopt(argc, argv, "bd:f:t:u:g:U")) > 0){
|
||||||
switch(opt) {
|
switch(opt) {
|
||||||
case 'b':
|
case 'b':
|
||||||
brief = 1;
|
brief = 1;
|
||||||
|
@ -83,6 +84,9 @@ int main(int argc, char **argv)
|
||||||
case 't':
|
case 't':
|
||||||
tun = optarg;
|
tun = optarg;
|
||||||
break;
|
break;
|
||||||
|
case 'U':
|
||||||
|
iff_type = IFF_TUN;
|
||||||
|
break;
|
||||||
case 'h':
|
case 'h':
|
||||||
default:
|
default:
|
||||||
Usage(name);
|
Usage(name);
|
||||||
|
@ -103,7 +107,7 @@ int main(int argc, char **argv)
|
||||||
|
|
||||||
memset(&ifr, 0, sizeof(ifr));
|
memset(&ifr, 0, sizeof(ifr));
|
||||||
|
|
||||||
ifr.ifr_flags = IFF_TAP | IFF_NO_PI;
|
ifr.ifr_flags = iff_type | IFF_NO_PI;
|
||||||
strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
|
strncpy(ifr.ifr_name, tun, sizeof(ifr.ifr_name) - 1);
|
||||||
if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){
|
if(ioctl(tap_fd, TUNSETIFF, (void *) &ifr) < 0){
|
||||||
perror("TUNSETIFF");
|
perror("TUNSETIFF");
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue