busybox/networking/libiproute/ll_types.c
<<
>>
Prefs
   1/* vi: set sw=4 ts=4: */
   2/*
   3 * This program is free software; you can redistribute it and/or
   4 * modify it under the terms of the GNU General Public License
   5 * as published by the Free Software Foundation; either version
   6 * 2 of the License, or (at your option) any later version.
   7 *
   8 * Authors: Alexey Kuznetsov, <kuznet@ms2.inr.ac.ru>
   9 */
  10#include <sys/socket.h> /* linux/if_arp.h needs it on some systems */
  11#include <arpa/inet.h>
  12#include <linux/if_arp.h>
  13
  14#include "libbb.h"
  15#include "rt_names.h"
  16
  17const char* FAST_FUNC ll_type_n2a(int type, char *buf)
  18{
  19        static const char arphrd_name[] ALIGN1 =
  20        /* 0,                  */ "generic" "\0"
  21        /* ARPHRD_LOOPBACK,    */ "loopback" "\0"
  22        /* ARPHRD_ETHER,       */ "ether" "\0"
  23#ifdef ARPHRD_INFINIBAND
  24        /* ARPHRD_INFINIBAND,  */ "infiniband" "\0"
  25#endif
  26#ifdef ARPHRD_IEEE802_TR
  27        /* ARPHRD_IEEE802,     */ "ieee802" "\0"
  28        /* ARPHRD_IEEE802_TR,  */ "tr" "\0"
  29#else
  30        /* ARPHRD_IEEE802,     */ "tr" "\0"
  31#endif
  32#ifdef ARPHRD_IEEE80211
  33        /* ARPHRD_IEEE80211,   */ "ieee802.11" "\0"
  34#endif
  35#ifdef ARPHRD_IEEE1394
  36        /* ARPHRD_IEEE1394,    */ "ieee1394" "\0"
  37#endif
  38        /* ARPHRD_IRDA,        */ "irda" "\0"
  39        /* ARPHRD_SLIP,        */ "slip" "\0"
  40        /* ARPHRD_CSLIP,       */ "cslip" "\0"
  41        /* ARPHRD_SLIP6,       */ "slip6" "\0"
  42        /* ARPHRD_CSLIP6,      */ "cslip6" "\0"
  43        /* ARPHRD_PPP,         */ "ppp" "\0"
  44        /* ARPHRD_TUNNEL,      */ "ipip" "\0"
  45        /* ARPHRD_TUNNEL6,     */ "tunnel6" "\0"
  46        /* ARPHRD_SIT,         */ "sit" "\0"
  47        /* ARPHRD_IPGRE,       */ "gre" "\0"
  48#ifdef ARPHRD_VOID
  49        /* ARPHRD_VOID,        */ "void" "\0"
  50#endif
  51
  52#if ENABLE_FEATURE_IP_RARE_PROTOCOLS
  53        /* ARPHRD_EETHER,      */ "eether" "\0"
  54        /* ARPHRD_AX25,        */ "ax25" "\0"
  55        /* ARPHRD_PRONET,      */ "pronet" "\0"
  56        /* ARPHRD_CHAOS,       */ "chaos" "\0"
  57        /* ARPHRD_ARCNET,      */ "arcnet" "\0"
  58        /* ARPHRD_APPLETLK,    */ "atalk" "\0"
  59        /* ARPHRD_DLCI,        */ "dlci" "\0"
  60#ifdef ARPHRD_ATM
  61        /* ARPHRD_ATM,         */ "atm" "\0"
  62#endif
  63        /* ARPHRD_METRICOM,    */ "metricom" "\0"
  64        /* ARPHRD_RSRVD,       */ "rsrvd" "\0"
  65        /* ARPHRD_ADAPT,       */ "adapt" "\0"
  66        /* ARPHRD_ROSE,        */ "rose" "\0"
  67        /* ARPHRD_X25,         */ "x25" "\0"
  68#ifdef ARPHRD_HWX25
  69        /* ARPHRD_HWX25,       */ "hwx25" "\0"
  70#endif
  71        /* ARPHRD_HDLC,        */ "hdlc" "\0"
  72        /* ARPHRD_LAPB,        */ "lapb" "\0"
  73#ifdef ARPHRD_DDCMP
  74        /* ARPHRD_DDCMP,       */ "ddcmp" "\0"
  75        /* ARPHRD_RAWHDLC,     */ "rawhdlc" "\0"
  76#endif
  77        /* ARPHRD_FRAD,        */ "frad" "\0"
  78        /* ARPHRD_SKIP,        */ "skip" "\0"
  79        /* ARPHRD_LOCALTLK,    */ "ltalk" "\0"
  80        /* ARPHRD_FDDI,        */ "fddi" "\0"
  81        /* ARPHRD_BIF,         */ "bif" "\0"
  82        /* ARPHRD_IPDDP,       */ "ip/ddp" "\0"
  83        /* ARPHRD_PIMREG,      */ "pimreg" "\0"
  84        /* ARPHRD_HIPPI,       */ "hippi" "\0"
  85        /* ARPHRD_ASH,         */ "ash" "\0"
  86        /* ARPHRD_ECONET,      */ "econet" "\0"
  87        /* ARPHRD_FCPP,        */ "fcpp" "\0"
  88        /* ARPHRD_FCAL,        */ "fcal" "\0"
  89        /* ARPHRD_FCPL,        */ "fcpl" "\0"
  90        /* ARPHRD_FCFABRIC,    */ "fcfb0" "\0"
  91        /* ARPHRD_FCFABRIC+1,  */ "fcfb1" "\0"
  92        /* ARPHRD_FCFABRIC+2,  */ "fcfb2" "\0"
  93        /* ARPHRD_FCFABRIC+3,  */ "fcfb3" "\0"
  94        /* ARPHRD_FCFABRIC+4,  */ "fcfb4" "\0"
  95        /* ARPHRD_FCFABRIC+5,  */ "fcfb5" "\0"
  96        /* ARPHRD_FCFABRIC+6,  */ "fcfb6" "\0"
  97        /* ARPHRD_FCFABRIC+7,  */ "fcfb7" "\0"
  98        /* ARPHRD_FCFABRIC+8,  */ "fcfb8" "\0"
  99        /* ARPHRD_FCFABRIC+9,  */ "fcfb9" "\0"
 100        /* ARPHRD_FCFABRIC+10, */ "fcfb10" "\0"
 101        /* ARPHRD_FCFABRIC+11, */ "fcfb11" "\0"
 102        /* ARPHRD_FCFABRIC+12, */ "fcfb12" "\0"
 103#endif /* FEATURE_IP_RARE_PROTOCOLS */
 104        ;
 105
 106        /* Keep these arrays in sync! */
 107
 108        static const uint16_t arphrd_type[] ALIGN2 = {
 109        0,                  /* "generic" "\0" */
 110        ARPHRD_LOOPBACK,    /* "loopback" "\0" */
 111        ARPHRD_ETHER,       /* "ether" "\0" */
 112#ifdef ARPHRD_INFINIBAND
 113        ARPHRD_INFINIBAND,  /* "infiniband" "\0" */
 114#endif
 115#ifdef ARPHRD_IEEE802_TR
 116        ARPHRD_IEEE802,     /* "ieee802" "\0" */
 117        ARPHRD_IEEE802_TR,  /* "tr" "\0" */
 118#else
 119        ARPHRD_IEEE802,     /* "tr" "\0" */
 120#endif
 121#ifdef ARPHRD_IEEE80211
 122        ARPHRD_IEEE80211,   /* "ieee802.11" "\0" */
 123#endif
 124#ifdef ARPHRD_IEEE1394
 125        ARPHRD_IEEE1394,    /* "ieee1394" "\0" */
 126#endif
 127        ARPHRD_IRDA,        /* "irda" "\0" */
 128        ARPHRD_SLIP,        /* "slip" "\0" */
 129        ARPHRD_CSLIP,       /* "cslip" "\0" */
 130        ARPHRD_SLIP6,       /* "slip6" "\0" */
 131        ARPHRD_CSLIP6,      /* "cslip6" "\0" */
 132        ARPHRD_PPP,         /* "ppp" "\0" */
 133        ARPHRD_TUNNEL,      /* "ipip" "\0" */
 134        ARPHRD_TUNNEL6,     /* "tunnel6" "\0" */
 135        ARPHRD_SIT,         /* "sit" "\0" */
 136        ARPHRD_IPGRE,       /* "gre" "\0" */
 137#ifdef ARPHRD_VOID
 138        ARPHRD_VOID,        /* "void" "\0" */
 139#endif
 140
 141#if ENABLE_FEATURE_IP_RARE_PROTOCOLS
 142        ARPHRD_EETHER,      /* "eether" "\0" */
 143        ARPHRD_AX25,        /* "ax25" "\0" */
 144        ARPHRD_PRONET,      /* "pronet" "\0" */
 145        ARPHRD_CHAOS,       /* "chaos" "\0" */
 146        ARPHRD_ARCNET,      /* "arcnet" "\0" */
 147        ARPHRD_APPLETLK,    /* "atalk" "\0" */
 148        ARPHRD_DLCI,        /* "dlci" "\0" */
 149#ifdef ARPHRD_ATM
 150        ARPHRD_ATM,         /* "atm" "\0" */
 151#endif
 152        ARPHRD_METRICOM,    /* "metricom" "\0" */
 153        ARPHRD_RSRVD,       /* "rsrvd" "\0" */
 154        ARPHRD_ADAPT,       /* "adapt" "\0" */
 155        ARPHRD_ROSE,        /* "rose" "\0" */
 156        ARPHRD_X25,         /* "x25" "\0" */
 157#ifdef ARPHRD_HWX25
 158        ARPHRD_HWX25,       /* "hwx25" "\0" */
 159#endif
 160        ARPHRD_HDLC,        /* "hdlc" "\0" */
 161        ARPHRD_LAPB,        /* "lapb" "\0" */
 162#ifdef ARPHRD_DDCMP
 163        ARPHRD_DDCMP,       /* "ddcmp" "\0" */
 164        ARPHRD_RAWHDLC,     /* "rawhdlc" "\0" */
 165#endif
 166        ARPHRD_FRAD,        /* "frad" "\0" */
 167        ARPHRD_SKIP,        /* "skip" "\0" */
 168        ARPHRD_LOCALTLK,    /* "ltalk" "\0" */
 169        ARPHRD_FDDI,        /* "fddi" "\0" */
 170        ARPHRD_BIF,         /* "bif" "\0" */
 171        ARPHRD_IPDDP,       /* "ip/ddp" "\0" */
 172        ARPHRD_PIMREG,      /* "pimreg" "\0" */
 173        ARPHRD_HIPPI,       /* "hippi" "\0" */
 174        ARPHRD_ASH,         /* "ash" "\0" */
 175        ARPHRD_ECONET,      /* "econet" "\0" */
 176        ARPHRD_FCPP,        /* "fcpp" "\0" */
 177        ARPHRD_FCAL,        /* "fcal" "\0" */
 178        ARPHRD_FCPL,        /* "fcpl" "\0" */
 179        ARPHRD_FCFABRIC,    /* "fcfb0" "\0" */
 180        ARPHRD_FCFABRIC+1,  /* "fcfb1" "\0" */
 181        ARPHRD_FCFABRIC+2,  /* "fcfb2" "\0" */
 182        ARPHRD_FCFABRIC+3,  /* "fcfb3" "\0" */
 183        ARPHRD_FCFABRIC+4,  /* "fcfb4" "\0" */
 184        ARPHRD_FCFABRIC+5,  /* "fcfb5" "\0" */
 185        ARPHRD_FCFABRIC+6,  /* "fcfb6" "\0" */
 186        ARPHRD_FCFABRIC+7,  /* "fcfb7" "\0" */
 187        ARPHRD_FCFABRIC+8,  /* "fcfb8" "\0" */
 188        ARPHRD_FCFABRIC+9,  /* "fcfb9" "\0" */
 189        ARPHRD_FCFABRIC+10, /* "fcfb10" "\0" */
 190        ARPHRD_FCFABRIC+11, /* "fcfb11" "\0" */
 191        ARPHRD_FCFABRIC+12, /* "fcfb12" "\0" */
 192#endif /* FEATURE_IP_RARE_PROTOCOLS */
 193        };
 194
 195        unsigned i;
 196        const char *aname = arphrd_name;
 197        for (i = 0; i < ARRAY_SIZE(arphrd_type); i++) {
 198                if (arphrd_type[i] == type)
 199                        return aname;
 200                aname += strlen(aname) + 1;
 201        }
 202        sprintf(buf, "[%d]", type);
 203        return buf;
 204}
 205