2 * Copyright (C)2006 USAGI/WIDE Project
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * split from ip_tunnel.c
23 * Masahide NAKAMURA @USAGI
29 #include <sys/types.h>
30 #include <sys/socket.h>
31 #include <sys/ioctl.h>
32 #include <netinet/in.h>
35 #include <linux/if_tunnel.h>
40 const char *tnl_strproto(__u8 proto)
58 strcpy(buf, "unknown");
65 int tnl_ioctl_get_ifindex(const char *dev)
71 strncpy(ifr.ifr_name, dev, IFNAMSIZ);
72 fd = socket(preferred_family, SOCK_DGRAM, 0);
73 err = ioctl(fd, SIOCGIFINDEX, &ifr);
79 return ifr.ifr_ifindex;
82 int tnl_ioctl_get_iftype(const char *dev)
88 strncpy(ifr.ifr_name, dev, IFNAMSIZ);
89 fd = socket(preferred_family, SOCK_DGRAM, 0);
90 err = ioctl(fd, SIOCGIFHWADDR, &ifr);
96 return ifr.ifr_addr.sa_family;
100 char * tnl_ioctl_get_ifname(int idx)
102 static struct ifreq ifr;
106 ifr.ifr_ifindex = idx;
107 fd = socket(preferred_family, SOCK_DGRAM, 0);
108 err = ioctl(fd, SIOCGIFNAME, &ifr);
117 int tnl_get_ioctl(const char *basedev, void *p)
123 strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
124 ifr.ifr_ifru.ifru_data = (void*)p;
125 fd = socket(preferred_family, SOCK_DGRAM, 0);
126 err = ioctl(fd, SIOCGETTUNNEL, &ifr);
133 int tnl_add_ioctl(int cmd, const char *basedev, const char *name, void *p)
139 if (cmd == SIOCCHGTUNNEL && name[0])
140 strncpy(ifr.ifr_name, name, IFNAMSIZ);
142 strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
143 ifr.ifr_ifru.ifru_data = p;
144 fd = socket(preferred_family, SOCK_DGRAM, 0);
145 err = ioctl(fd, cmd, &ifr);
152 int tnl_del_ioctl(const char *basedev, const char *name, void *p)
159 strncpy(ifr.ifr_name, name, IFNAMSIZ);
161 strncpy(ifr.ifr_name, basedev, IFNAMSIZ);
162 ifr.ifr_ifru.ifru_data = p;
163 fd = socket(preferred_family, SOCK_DGRAM, 0);
164 err = ioctl(fd, SIOCDELTUNNEL, &ifr);