1
2
3
4
5
6
7
8
9#include "libbb.h"
10#include <net/if_arp.h>
11#include <net/ethernet.h>
12
13
14
15
16int FAST_FUNC in_ether(const char *bufp, struct sockaddr *sap)
17{
18 char *ptr;
19 int i, j;
20 unsigned char val;
21 unsigned char c;
22
23 sap->sa_family = ARPHRD_ETHER;
24 ptr = (char *) sap->sa_data;
25
26 i = ETH_ALEN;
27 goto first;
28 do {
29
30 if (*bufp == ':')
31 bufp++;
32 first:
33 j = val = 0;
34 do {
35 c = *bufp;
36 if (((unsigned char)(c - '0')) <= 9) {
37 c -= '0';
38 } else if ((unsigned char)((c|0x20) - 'a') <= 5) {
39 c = (unsigned char)((c|0x20) - 'a') + 10;
40 } else {
41 if (j && (c == ':' || c == '\0'))
42
43 break;
44 return -1;
45 }
46 ++bufp;
47 val <<= 4;
48 val += c;
49 j ^= 1;
50 } while (j);
51
52 *ptr++ = val;
53 } while (--i);
54
55
56 return *bufp;
57}
58