summaryrefslogtreecommitdiff
path: root/dev.c
diff options
context:
space:
mode:
Diffstat (limited to 'dev.c')
-rw-r--r--dev.c182
1 files changed, 182 insertions, 0 deletions
diff --git a/dev.c b/dev.c
index 2b3a7a5..a29b4c1 100644
--- a/dev.c
+++ b/dev.c
@@ -5,6 +5,7 @@
#include <sys/socket.h>
#include <linux/if_arp.h>
#include <ifaddrs.h>
+#include <arpa/inet.h>
#include "dev.h"
#include "str.h"
@@ -221,3 +222,184 @@ void device_leave_promiscuous_mode(const char *ifname, short oldflags)
device_set_flags(ifname, oldflags);
}
+
+const char *device_type2str(uint16_t type)
+{
+ switch (type) {
+ case ARPHRD_ETHER:
+ return "ether";
+ case ARPHRD_EETHER:
+ return "eether";
+ case ARPHRD_AX25:
+ return "ax25";
+ case ARPHRD_PRONET:
+ return "pronet";
+ case ARPHRD_CHAOS:
+ return "chaos";
+ case ARPHRD_IEEE802:
+ return "ieee802";
+ case ARPHRD_ARCNET:
+ return "arcnet";
+ case ARPHRD_APPLETLK:
+ return "appletlk";
+ case ARPHRD_DLCI:
+ return "dlci";
+ case ARPHRD_ATM:
+ return "atm";
+ case ARPHRD_METRICOM:
+ return "metricom";
+ case ARPHRD_IEEE1394:
+ return "ieee1394";
+ case ARPHRD_INFINIBAND:
+ return "infiniband";
+ case ARPHRD_SLIP:
+ return "slip";
+ case ARPHRD_CSLIP:
+ return "cslip";
+ case ARPHRD_SLIP6:
+ return "slip6";
+ case ARPHRD_CSLIP6:
+ return "cslip6";
+ case ARPHRD_RSRVD:
+ return "RSRVD";
+ case ARPHRD_ADAPT:
+ return "adapt";
+ case ARPHRD_ROSE:
+ return "rose";
+ case ARPHRD_X25:
+ return "x25";
+ case ARPHRD_HWX25:
+ return "hwx25";
+ case ARPHRD_CAN:
+ return "can";
+ case ARPHRD_PPP:
+ return "ppp";
+ case ARPHRD_HDLC:
+ return "hdlc";
+ case ARPHRD_LAPB:
+ return "lapb";
+ case ARPHRD_DDCMP:
+ return "ddcmp";
+ case ARPHRD_RAWHDLC:
+ return "rawhdlc";
+ case ARPHRD_TUNNEL:
+ return "tunnel";
+ case ARPHRD_TUNNEL6:
+ return "tunnel6";
+ case ARPHRD_FRAD:
+ return "frad";
+ case ARPHRD_SKIP:
+ return "skip";
+ case ARPHRD_LOOPBACK:
+ return "loopback";
+ case ARPHRD_LOCALTLK:
+ return "localtlk";
+ case ARPHRD_FDDI:
+ return "fddi";
+ case ARPHRD_BIF:
+ return "bif";
+ case ARPHRD_SIT:
+ return "sit";
+ case ARPHRD_IPDDP:
+ return "ipddp";
+ case ARPHRD_IPGRE:
+ return "ipgre";
+ case ARPHRD_PIMREG:
+ return "pimreg";
+ case ARPHRD_HIPPI:
+ return "hippi";
+ case ARPHRD_ASH:
+ return "ash";
+ case ARPHRD_ECONET:
+ return "econet";
+ case ARPHRD_IRDA:
+ return "irda";
+ case ARPHRD_FCPP:
+ return "fcpp";
+ case ARPHRD_FCAL:
+ return "fcal";
+ case ARPHRD_FCPL:
+ return "fcpl";
+ case ARPHRD_FCFABRIC:
+ return "fcfb0";
+ case ARPHRD_FCFABRIC + 1:
+ return "fcfb1";
+ case ARPHRD_FCFABRIC + 2:
+ return "fcfb2";
+ case ARPHRD_FCFABRIC + 3:
+ return "fcfb3";
+ case ARPHRD_FCFABRIC + 4:
+ return "fcfb4";
+ case ARPHRD_FCFABRIC + 5:
+ return "fcfb5";
+ case ARPHRD_FCFABRIC + 6:
+ return "fcfb6";
+ case ARPHRD_FCFABRIC + 7:
+ return "fcfb7";
+ case ARPHRD_FCFABRIC + 8:
+ return "fcfb8";
+ case ARPHRD_FCFABRIC + 9:
+ return "fcfb9";
+ case ARPHRD_FCFABRIC + 10:
+ return "fcfb10";
+ case ARPHRD_FCFABRIC + 11:
+ return "fcfb11";
+ case ARPHRD_FCFABRIC + 12:
+ return "fcfb12";
+ case ARPHRD_IEEE802_TR:
+ return "ieee802_tr";
+ case ARPHRD_IEEE80211:
+ return "ieee80211";
+ case ARPHRD_IEEE80211_PRISM:
+ return "ieee80211_prism";
+ case ARPHRD_IEEE80211_RADIOTAP:
+ return "ieee80211_radiotap";
+ case ARPHRD_IEEE802154:
+ return "ieee802154";
+ case ARPHRD_PHONET:
+ return "phonet";
+ case ARPHRD_PHONET_PIPE:
+ return "phonet_pipe";
+ case ARPHRD_CAIF:
+ return "caif";
+ case ARPHRD_IP6GRE:
+ return "ip6gre";
+ case ARPHRD_NETLINK:
+ return "netlink";
+ case ARPHRD_NONE:
+ return "none";
+ case ARPHRD_VOID:
+ return "void";
+ default:
+ return "Unknown";
+ }
+}
+
+/* Taken from iproute2 ll_addr_n2a func */
+const char *device_addr2str(const char *addr, int alen, int type,
+ char *buf, int blen)
+{
+ int i, l;
+
+ if (alen == 4 &&
+ (type == ARPHRD_TUNNEL || type == ARPHRD_SIT ||
+ type == ARPHRD_IPGRE))
+ return inet_ntop(AF_INET, addr, buf, blen);
+
+ if (alen == 16 && type == ARPHRD_TUNNEL6)
+ return inet_ntop(AF_INET6, addr, buf, blen);
+
+ for (l = 0, i = 0; i < alen; i++) {
+ if (i == 0) {
+ snprintf(buf + l, blen, "%02x", addr[i]);
+ blen -= 2;
+ l += 2;
+ } else {
+ snprintf(buf + l, blen, ":%02x", addr[i]);
+ blen -= 3;
+ l += 3;
+ }
+ }
+
+ return buf;
+}