#include <sys/socket.h>
#include <arpa/inet.h>
#include <sys/ioctl.h>
-#include <linux/if.h>
-#include <linux/if_arp.h>
+#include <net/if.h>
+#include <net/if_arp.h>
#include <linux/ip.h>
#include <linux/if_tunnel.h>
}
if (medium[0]) {
- p->link = tnl_ioctl_get_ifindex(medium);
+ p->link = if_nametoindex(medium);
if (p->link == 0)
return -1;
}
struct ip_tunnel_6rd ip6rd;
char s1[1024];
char s2[1024];
- char s3[64];
- char s4[64];
memset(&ip6rd, 0, sizeof(ip6rd));
- inet_ntop(AF_INET, &p->i_key, s3, sizeof(s3));
- inet_ntop(AF_INET, &p->o_key, s4, sizeof(s4));
/* Do not use format_host() for local addr,
* symbolic name will not be useful.
}
if (p->link) {
- char *n = tnl_ioctl_get_ifname(p->link);
+ const char *n = ll_index_to_name(p->link);
if (n)
printf(" dev %s ", n);
}
if (!(p->iph.frag_off&htons(IP_DF)))
printf(" nopmtudisc");
- if (!tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
+ if (p->iph.protocol == IPPROTO_IPV6 && !tnl_ioctl_get_6rd(p->name, &ip6rd) && ip6rd.prefixlen) {
printf(" 6rd-prefix %s/%u ",
inet_ntop(AF_INET6, &ip6rd.prefix, s1, sizeof(s1)),
ip6rd.prefixlen);
}
if ((p->i_flags&GRE_KEY) && (p->o_flags&GRE_KEY) && p->o_key == p->i_key)
- printf(" key %s", s3);
+ printf(" key %u", ntohl(p->i_key));
else if ((p->i_flags|p->o_flags)&GRE_KEY) {
if (p->i_flags&GRE_KEY)
- printf(" ikey %s ", s3);
+ printf(" ikey %u ", ntohl(p->i_key));
if (p->o_flags&GRE_KEY)
- printf(" okey %s ", s4);
+ printf(" okey %u ", ntohl(p->o_key));
}
if (p->i_flags&GRE_SEQ)
rx_fifo, rx_frame,
tx_bytes, tx_packets, tx_errs, tx_drops,
tx_fifo, tx_colls, tx_carrier, rx_multi;
- int type;
struct ip_tunnel_parm p1;
char buf[512];
return -1;
}
- fgets(buf, sizeof(buf), fp);
- fgets(buf, sizeof(buf), fp);
+ /* skip header lines */
+ if (!fgets(buf, sizeof(buf), fp) ||
+ !fgets(buf, sizeof(buf), fp)) {
+ fprintf(stderr, "/proc/net/dev read error\n");
+ fclose(fp);
+ return -1;
+ }
while (fgets(buf, sizeof(buf), fp) != NULL) {
+ int index, type;
char *ptr;
buf[sizeof(buf) - 1] = 0;
if ((ptr = strchr(buf, ':')) == NULL ||
(*ptr++ = 0, sscanf(buf, "%s", name) != 1)) {
fprintf(stderr, "Wrong format of /proc/net/dev. Sorry.\n");
+ fclose(fp);
return -1;
}
if (sscanf(ptr, "%ld%ld%ld%ld%ld%ld%ld%*d%ld%ld%ld%ld%ld%ld%ld",
continue;
if (p->name[0] && strcmp(p->name, name))
continue;
- type = tnl_ioctl_get_iftype(name);
+ index = ll_name_to_index(name);
+ if (index == 0)
+ continue;
+ type = ll_index_to_type(index);
if (type == -1) {
fprintf(stderr, "Failed to get type of [%s]\n", name);
continue;
}
printf("\n");
}
+ fclose(fp);
return 0;
}
int err;
struct ip_tunnel_parm p;
+ ll_init_map(&rth);
if (parse_args(argc, argv, SIOCGETTUNNEL, &p) < 0)
return -1;
return do_add(SIOCADDTUNNEL, argc-1, argv+1);
if (matches(*argv, "change") == 0)
return do_add(SIOCCHGTUNNEL, argc-1, argv+1);
- if (matches(*argv, "del") == 0)
+ if (matches(*argv, "delete") == 0)
return do_del(argc-1, argv+1);
if (matches(*argv, "show") == 0 ||
matches(*argv, "lst") == 0 ||