ifconfig.c 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  1. /* vi: set sw=4 ts=4: */
  2. /* ifconfig
  3. *
  4. * Similar to the standard Unix ifconfig, but with only the necessary
  5. * parts for AF_INET, and without any printing of if info (for now).
  6. *
  7. * Bjorn Wesen, Axis Communications AB
  8. *
  9. *
  10. * Authors of the original ifconfig was:
  11. * Fred N. van Kempen, <waltje@uwalt.nl.mugnet.org>
  12. *
  13. * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
  14. */
  15. /*
  16. * Heavily modified by Manuel Novoa III Mar 6, 2001
  17. *
  18. * From initial port to busybox, removed most of the redundancy by
  19. * converting to a table-driven approach. Added several (optional)
  20. * args missing from initial port.
  21. *
  22. * Still missing: media, tunnel.
  23. *
  24. * 2002-04-20
  25. * IPV6 support added by Bart Visscher <magick@linux-fan.com>
  26. */
  27. #include <net/if.h>
  28. #include <net/if_arp.h>
  29. #include <netinet/in.h>
  30. #if defined(__GLIBC__) && __GLIBC__ >=2 && __GLIBC_MINOR__ >= 1
  31. #include <netpacket/packet.h>
  32. #include <net/ethernet.h>
  33. #else
  34. #include <sys/types.h>
  35. #include <netinet/if_ether.h>
  36. #endif
  37. #include "inet_common.h"
  38. #include "libbb.h"
  39. #if ENABLE_FEATURE_IFCONFIG_SLIP
  40. # include <net/if_slip.h>
  41. #endif
  42. /* I don't know if this is needed for busybox or not. Anyone? */
  43. #define QUESTIONABLE_ALIAS_CASE
  44. /* Defines for glibc2.0 users. */
  45. #ifndef SIOCSIFTXQLEN
  46. # define SIOCSIFTXQLEN 0x8943
  47. # define SIOCGIFTXQLEN 0x8942
  48. #endif
  49. /* ifr_qlen is ifru_ivalue, but it isn't present in 2.0 kernel headers */
  50. #ifndef ifr_qlen
  51. # define ifr_qlen ifr_ifru.ifru_mtu
  52. #endif
  53. #ifndef IFF_DYNAMIC
  54. # define IFF_DYNAMIC 0x8000 /* dialup device with changing addresses */
  55. #endif
  56. #if ENABLE_FEATURE_IPV6
  57. struct in6_ifreq {
  58. struct in6_addr ifr6_addr;
  59. uint32_t ifr6_prefixlen;
  60. int ifr6_ifindex;
  61. };
  62. #endif
  63. /*
  64. * Here are the bit masks for the "flags" member of struct options below.
  65. * N_ signifies no arg prefix; M_ signifies arg prefixed by '-'.
  66. * CLR clears the flag; SET sets the flag; ARG signifies (optional) arg.
  67. */
  68. #define N_CLR 0x01
  69. #define M_CLR 0x02
  70. #define N_SET 0x04
  71. #define M_SET 0x08
  72. #define N_ARG 0x10
  73. #define M_ARG 0x20
  74. #define M_MASK (M_CLR | M_SET | M_ARG)
  75. #define N_MASK (N_CLR | N_SET | N_ARG)
  76. #define SET_MASK (N_SET | M_SET)
  77. #define CLR_MASK (N_CLR | M_CLR)
  78. #define SET_CLR_MASK (SET_MASK | CLR_MASK)
  79. #define ARG_MASK (M_ARG | N_ARG)
  80. /*
  81. * Here are the bit masks for the "arg_flags" member of struct options below.
  82. */
  83. /*
  84. * cast type:
  85. * 00 int
  86. * 01 char *
  87. * 02 HOST_COPY in_ether
  88. * 03 HOST_COPY INET_resolve
  89. */
  90. #define A_CAST_TYPE 0x03
  91. /*
  92. * map type:
  93. * 00 not a map type (mem_start, io_addr, irq)
  94. * 04 memstart (unsigned long)
  95. * 08 io_addr (unsigned short)
  96. * 0C irq (unsigned char)
  97. */
  98. #define A_MAP_TYPE 0x0C
  99. #define A_ARG_REQ 0x10 /* Set if an arg is required. */
  100. #define A_NETMASK 0x20 /* Set if netmask (check for multiple sets). */
  101. #define A_SET_AFTER 0x40 /* Set a flag at the end. */
  102. #define A_COLON_CHK 0x80 /* Is this needed? See below. */
  103. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  104. #define A_HOSTNAME 0x100 /* Set if it is ip addr. */
  105. #define A_BROADCAST 0x200 /* Set if it is broadcast addr. */
  106. #else
  107. #define A_HOSTNAME 0
  108. #define A_BROADCAST 0
  109. #endif
  110. /*
  111. * These defines are for dealing with the A_CAST_TYPE field.
  112. */
  113. #define A_CAST_CHAR_PTR 0x01
  114. #define A_CAST_RESOLVE 0x01
  115. #define A_CAST_HOST_COPY 0x02
  116. #define A_CAST_HOST_COPY_IN_ETHER A_CAST_HOST_COPY
  117. #define A_CAST_HOST_COPY_RESOLVE (A_CAST_HOST_COPY | A_CAST_RESOLVE)
  118. /*
  119. * These defines are for dealing with the A_MAP_TYPE field.
  120. */
  121. #define A_MAP_ULONG 0x04 /* memstart */
  122. #define A_MAP_USHORT 0x08 /* io_addr */
  123. #define A_MAP_UCHAR 0x0C /* irq */
  124. /*
  125. * Define the bit masks signifying which operations to perform for each arg.
  126. */
  127. #define ARG_METRIC (A_ARG_REQ /*| A_CAST_INT*/)
  128. #define ARG_MTU (A_ARG_REQ /*| A_CAST_INT*/)
  129. #define ARG_TXQUEUELEN (A_ARG_REQ /*| A_CAST_INT*/)
  130. #define ARG_MEM_START (A_ARG_REQ | A_MAP_ULONG)
  131. #define ARG_IO_ADDR (A_ARG_REQ | A_MAP_ULONG)
  132. #define ARG_IRQ (A_ARG_REQ | A_MAP_UCHAR)
  133. #define ARG_DSTADDR (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE)
  134. #define ARG_NETMASK (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_NETMASK)
  135. #define ARG_BROADCAST (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_BROADCAST)
  136. #define ARG_HW (A_ARG_REQ | A_CAST_HOST_COPY_IN_ETHER)
  137. #define ARG_POINTOPOINT (A_ARG_REQ | A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
  138. #define ARG_KEEPALIVE (A_ARG_REQ | A_CAST_CHAR_PTR)
  139. #define ARG_OUTFILL (A_ARG_REQ | A_CAST_CHAR_PTR)
  140. #define ARG_HOSTNAME (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER | A_COLON_CHK | A_HOSTNAME)
  141. #define ARG_ADD_DEL (A_CAST_HOST_COPY_RESOLVE | A_SET_AFTER)
  142. /*
  143. * Set up the tables. Warning! They must have corresponding order!
  144. */
  145. struct arg1opt {
  146. const char *name;
  147. unsigned short selector;
  148. unsigned short ifr_offset;
  149. };
  150. struct options {
  151. const char *name;
  152. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  153. const unsigned int flags:6;
  154. const unsigned int arg_flags:10;
  155. #else
  156. const unsigned char flags;
  157. const unsigned char arg_flags;
  158. #endif
  159. const unsigned short selector;
  160. };
  161. #define ifreq_offsetof(x) offsetof(struct ifreq, x)
  162. static const struct arg1opt Arg1Opt[] = {
  163. { "SIFMETRIC", SIOCSIFMETRIC, ifreq_offsetof(ifr_metric) },
  164. { "SIFMTU", SIOCSIFMTU, ifreq_offsetof(ifr_mtu) },
  165. { "SIFTXQLEN", SIOCSIFTXQLEN, ifreq_offsetof(ifr_qlen) },
  166. { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
  167. { "SIFNETMASK", SIOCSIFNETMASK, ifreq_offsetof(ifr_netmask) },
  168. { "SIFBRDADDR", SIOCSIFBRDADDR, ifreq_offsetof(ifr_broadaddr) },
  169. #if ENABLE_FEATURE_IFCONFIG_HW
  170. { "SIFHWADDR", SIOCSIFHWADDR, ifreq_offsetof(ifr_hwaddr) },
  171. #endif
  172. { "SIFDSTADDR", SIOCSIFDSTADDR, ifreq_offsetof(ifr_dstaddr) },
  173. #ifdef SIOCSKEEPALIVE
  174. { "SKEEPALIVE", SIOCSKEEPALIVE, ifreq_offsetof(ifr_data) },
  175. #endif
  176. #ifdef SIOCSOUTFILL
  177. { "SOUTFILL", SIOCSOUTFILL, ifreq_offsetof(ifr_data) },
  178. #endif
  179. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  180. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.mem_start) },
  181. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.base_addr) },
  182. { "SIFMAP", SIOCSIFMAP, ifreq_offsetof(ifr_map.irq) },
  183. #endif
  184. /* Last entry if for unmatched (possibly hostname) arg. */
  185. #if ENABLE_FEATURE_IPV6
  186. { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
  187. { "DIFADDR", SIOCDIFADDR, ifreq_offsetof(ifr_addr) }, /* IPv6 version ignores the offset */
  188. #endif
  189. { "SIFADDR", SIOCSIFADDR, ifreq_offsetof(ifr_addr) },
  190. };
  191. static const struct options OptArray[] = {
  192. { "metric", N_ARG, ARG_METRIC, 0 },
  193. { "mtu", N_ARG, ARG_MTU, 0 },
  194. { "txqueuelen", N_ARG, ARG_TXQUEUELEN, 0 },
  195. { "dstaddr", N_ARG, ARG_DSTADDR, 0 },
  196. { "netmask", N_ARG, ARG_NETMASK, 0 },
  197. { "broadcast", N_ARG | M_CLR, ARG_BROADCAST, IFF_BROADCAST },
  198. #if ENABLE_FEATURE_IFCONFIG_HW
  199. { "hw", N_ARG, ARG_HW, 0 },
  200. #endif
  201. { "pointopoint", N_ARG | M_CLR, ARG_POINTOPOINT, IFF_POINTOPOINT },
  202. #ifdef SIOCSKEEPALIVE
  203. { "keepalive", N_ARG, ARG_KEEPALIVE, 0 },
  204. #endif
  205. #ifdef SIOCSOUTFILL
  206. { "outfill", N_ARG, ARG_OUTFILL, 0 },
  207. #endif
  208. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  209. { "mem_start", N_ARG, ARG_MEM_START, 0 },
  210. { "io_addr", N_ARG, ARG_IO_ADDR, 0 },
  211. { "irq", N_ARG, ARG_IRQ, 0 },
  212. #endif
  213. #if ENABLE_FEATURE_IPV6
  214. { "add", N_ARG, ARG_ADD_DEL, 0 },
  215. { "del", N_ARG, ARG_ADD_DEL, 0 },
  216. #endif
  217. { "arp", N_CLR | M_SET, 0, IFF_NOARP },
  218. { "trailers", N_CLR | M_SET, 0, IFF_NOTRAILERS },
  219. { "promisc", N_SET | M_CLR, 0, IFF_PROMISC },
  220. { "multicast", N_SET | M_CLR, 0, IFF_MULTICAST },
  221. { "allmulti", N_SET | M_CLR, 0, IFF_ALLMULTI },
  222. { "dynamic", N_SET | M_CLR, 0, IFF_DYNAMIC },
  223. { "up", N_SET, 0, (IFF_UP | IFF_RUNNING) },
  224. { "down", N_CLR, 0, IFF_UP },
  225. { NULL, 0, ARG_HOSTNAME, (IFF_UP | IFF_RUNNING) }
  226. };
  227. /*
  228. * A couple of prototypes.
  229. */
  230. #if ENABLE_FEATURE_IFCONFIG_HW
  231. static int in_ether(const char *bufp, struct sockaddr *sap);
  232. #endif
  233. /*
  234. * Our main function.
  235. */
  236. int ifconfig_main(int argc, char **argv) MAIN_EXTERNALLY_VISIBLE;
  237. int ifconfig_main(int argc, char **argv)
  238. {
  239. struct ifreq ifr;
  240. struct sockaddr_in sai;
  241. #if ENABLE_FEATURE_IFCONFIG_HW
  242. struct sockaddr sa;
  243. #endif
  244. const struct arg1opt *a1op;
  245. const struct options *op;
  246. int sockfd; /* socket fd we use to manipulate stuff with */
  247. int selector;
  248. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  249. unsigned int mask;
  250. unsigned int did_flags;
  251. unsigned int sai_hostname, sai_netmask;
  252. #else
  253. unsigned char mask;
  254. unsigned char did_flags;
  255. #endif
  256. char *p;
  257. /*char host[128];*/
  258. const char *host = NULL; /* make gcc happy */
  259. did_flags = 0;
  260. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  261. sai_hostname = 0;
  262. sai_netmask = 0;
  263. #endif
  264. /* skip argv[0] */
  265. ++argv;
  266. --argc;
  267. #if ENABLE_FEATURE_IFCONFIG_STATUS
  268. if (argc > 0 && (argv[0][0] == '-' && argv[0][1] == 'a' && !argv[0][2])) {
  269. interface_opt_a = 1;
  270. --argc;
  271. ++argv;
  272. }
  273. #endif
  274. if (argc <= 1) {
  275. #if ENABLE_FEATURE_IFCONFIG_STATUS
  276. return display_interfaces(argc ? *argv : NULL);
  277. #else
  278. bb_error_msg_and_die("no support for status display");
  279. #endif
  280. }
  281. /* Create a channel to the NET kernel. */
  282. sockfd = xsocket(AF_INET, SOCK_DGRAM, 0);
  283. /* get interface name */
  284. safe_strncpy(ifr.ifr_name, *argv, IFNAMSIZ);
  285. /* Process the remaining arguments. */
  286. while (*++argv != (char *) NULL) {
  287. p = *argv;
  288. mask = N_MASK;
  289. if (*p == '-') { /* If the arg starts with '-'... */
  290. ++p; /* advance past it and */
  291. mask = M_MASK; /* set the appropriate mask. */
  292. }
  293. for (op = OptArray; op->name; op++) { /* Find table entry. */
  294. if (strcmp(p, op->name) == 0) { /* If name matches... */
  295. mask &= op->flags;
  296. if (mask) /* set the mask and go. */
  297. goto FOUND_ARG;
  298. /* If we get here, there was a valid arg with an */
  299. /* invalid '-' prefix. */
  300. bb_error_msg_and_die("bad: '%s'", p-1);
  301. }
  302. }
  303. /* We fell through, so treat as possible hostname. */
  304. a1op = Arg1Opt + ARRAY_SIZE(Arg1Opt) - 1;
  305. mask = op->arg_flags;
  306. goto HOSTNAME;
  307. FOUND_ARG:
  308. if (mask & ARG_MASK) {
  309. mask = op->arg_flags;
  310. a1op = Arg1Opt + (op - OptArray);
  311. if (mask & A_NETMASK & did_flags)
  312. bb_show_usage();
  313. if (*++argv == NULL) {
  314. if (mask & A_ARG_REQ)
  315. bb_show_usage();
  316. --argv;
  317. mask &= A_SET_AFTER; /* just for broadcast */
  318. } else { /* got an arg so process it */
  319. HOSTNAME:
  320. did_flags |= (mask & (A_NETMASK|A_HOSTNAME));
  321. if (mask & A_CAST_HOST_COPY) {
  322. #if ENABLE_FEATURE_IFCONFIG_HW
  323. if (mask & A_CAST_RESOLVE) {
  324. #endif
  325. #if ENABLE_FEATURE_IPV6
  326. char *prefix;
  327. int prefix_len = 0;
  328. #endif
  329. /*safe_strncpy(host, *argv, (sizeof host));*/
  330. host = *argv;
  331. #if ENABLE_FEATURE_IPV6
  332. prefix = strchr(host, '/');
  333. if (prefix) {
  334. prefix_len = xatou_range(prefix + 1, 0, 128);
  335. *prefix = '\0';
  336. }
  337. #endif
  338. sai.sin_family = AF_INET;
  339. sai.sin_port = 0;
  340. if (!strcmp(host, bb_str_default)) {
  341. /* Default is special, meaning 0.0.0.0. */
  342. sai.sin_addr.s_addr = INADDR_ANY;
  343. }
  344. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  345. else if ((host[0] == '+' && !host[1]) && (mask & A_BROADCAST)
  346. && (did_flags & (A_NETMASK|A_HOSTNAME)) == (A_NETMASK|A_HOSTNAME)
  347. ) {
  348. /* + is special, meaning broadcast is derived. */
  349. sai.sin_addr.s_addr = (~sai_netmask) | (sai_hostname & sai_netmask);
  350. }
  351. #endif
  352. else {
  353. len_and_sockaddr *lsa;
  354. if (strcmp(host, "inet") == 0)
  355. continue; /* compat stuff */
  356. lsa = xhost2sockaddr(host, 0);
  357. #if ENABLE_FEATURE_IPV6
  358. if (lsa->u.sa.sa_family == AF_INET6) {
  359. int sockfd6;
  360. struct in6_ifreq ifr6;
  361. memcpy((char *) &ifr6.ifr6_addr,
  362. (char *) &(lsa->u.sin6.sin6_addr),
  363. sizeof(struct in6_addr));
  364. /* Create a channel to the NET kernel. */
  365. sockfd6 = xsocket(AF_INET6, SOCK_DGRAM, 0);
  366. xioctl(sockfd6, SIOGIFINDEX, &ifr);
  367. ifr6.ifr6_ifindex = ifr.ifr_ifindex;
  368. ifr6.ifr6_prefixlen = prefix_len;
  369. ioctl_or_perror_and_die(sockfd6, a1op->selector, &ifr6, "SIOC%s", a1op->name);
  370. if (ENABLE_FEATURE_CLEAN_UP)
  371. free(lsa);
  372. continue;
  373. }
  374. #endif
  375. sai.sin_addr = lsa->u.sin.sin_addr;
  376. if (ENABLE_FEATURE_CLEAN_UP)
  377. free(lsa);
  378. }
  379. #if ENABLE_FEATURE_IFCONFIG_BROADCAST_PLUS
  380. if (mask & A_HOSTNAME)
  381. sai_hostname = sai.sin_addr.s_addr;
  382. if (mask & A_NETMASK)
  383. sai_netmask = sai.sin_addr.s_addr;
  384. #endif
  385. p = (char *) &sai;
  386. #if ENABLE_FEATURE_IFCONFIG_HW
  387. } else { /* A_CAST_HOST_COPY_IN_ETHER */
  388. /* This is the "hw" arg case. */
  389. if (strcmp("ether", *argv) || !*++argv)
  390. bb_show_usage();
  391. /*safe_strncpy(host, *argv, sizeof(host));*/
  392. host = *argv;
  393. if (in_ether(host, &sa))
  394. bb_error_msg_and_die("invalid hw-addr %s", host);
  395. p = (char *) &sa;
  396. }
  397. #endif
  398. memcpy( (((char *)&ifr) + a1op->ifr_offset),
  399. p, sizeof(struct sockaddr));
  400. } else {
  401. /* FIXME: error check?? */
  402. unsigned long i = strtoul(*argv, NULL, 0);
  403. p = ((char *)&ifr) + a1op->ifr_offset;
  404. #if ENABLE_FEATURE_IFCONFIG_MEMSTART_IOADDR_IRQ
  405. if (mask & A_MAP_TYPE) {
  406. xioctl(sockfd, SIOCGIFMAP, &ifr);
  407. if ((mask & A_MAP_UCHAR) == A_MAP_UCHAR)
  408. *((unsigned char *) p) = i;
  409. else if (mask & A_MAP_USHORT)
  410. *((unsigned short *) p) = i;
  411. else
  412. *((unsigned long *) p) = i;
  413. } else
  414. #endif
  415. if (mask & A_CAST_CHAR_PTR)
  416. *((caddr_t *) p) = (caddr_t) i;
  417. else /* A_CAST_INT */
  418. *((int *) p) = i;
  419. }
  420. ioctl_or_perror_and_die(sockfd, a1op->selector, &ifr, "SIOC%s", a1op->name);
  421. #ifdef QUESTIONABLE_ALIAS_CASE
  422. if (mask & A_COLON_CHK) {
  423. /*
  424. * Don't do the set_flag() if the address is an alias with
  425. * a '-' at the end, since it's deleted already! - Roman
  426. *
  427. * Should really use regex.h here, not sure though how well
  428. * it'll go with the cross-platform support etc.
  429. */
  430. char *ptr;
  431. short int found_colon = 0;
  432. for (ptr = ifr.ifr_name; *ptr; ptr++)
  433. if (*ptr == ':')
  434. found_colon++;
  435. if (found_colon && ptr[-1] == '-')
  436. continue;
  437. }
  438. #endif
  439. }
  440. if (!(mask & A_SET_AFTER))
  441. continue;
  442. mask = N_SET;
  443. }
  444. xioctl(sockfd, SIOCGIFFLAGS, &ifr);
  445. selector = op->selector;
  446. if (mask & SET_MASK)
  447. ifr.ifr_flags |= selector;
  448. else
  449. ifr.ifr_flags &= ~selector;
  450. xioctl(sockfd, SIOCSIFFLAGS, &ifr);
  451. } /* while () */
  452. if (ENABLE_FEATURE_CLEAN_UP)
  453. close(sockfd);
  454. return 0;
  455. }
  456. #if ENABLE_FEATURE_IFCONFIG_HW
  457. /* Input an Ethernet address and convert to binary. */
  458. static int in_ether(const char *bufp, struct sockaddr *sap)
  459. {
  460. char *ptr;
  461. int i, j;
  462. unsigned char val;
  463. unsigned char c;
  464. sap->sa_family = ARPHRD_ETHER;
  465. ptr = sap->sa_data;
  466. i = 0;
  467. do {
  468. j = val = 0;
  469. /* We might get a semicolon here - not required. */
  470. if (i && (*bufp == ':')) {
  471. bufp++;
  472. }
  473. do {
  474. c = *bufp;
  475. if (((unsigned char)(c - '0')) <= 9) {
  476. c -= '0';
  477. } else if (((unsigned char)((c|0x20) - 'a')) <= 5) {
  478. c = (c|0x20) - ('a'-10);
  479. } else if (j && (c == ':' || c == 0)) {
  480. break;
  481. } else {
  482. return -1;
  483. }
  484. ++bufp;
  485. val <<= 4;
  486. val += c;
  487. } while (++j < 2);
  488. *ptr++ = val;
  489. } while (++i < ETH_ALEN);
  490. return *bufp; /* Error if we don't end at end of string. */
  491. }
  492. #endif