1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
| | #include <stdlib.h>
#include <netinet/ether.h>
static struct ether_addr a;
struct ether_addr *ether_aton_r (const char *x, struct ether_addr *p_a) {
for (int ii = 0; ii < 6; ii++) {
unsigned long int n;
if (ii != 0) {
if (x[0] != ':') return 0; /* bad format */
else x++;
}
n = strtoul (x, &x, 16);
if (n > 0xFF) return 0; /* bad byte */
(*p_a).ether_addr_octet[ii] = n;
}
if (x[0] != 0) return 0; /* bad format */
return p_a;
}
struct ether_addr *ether_aton (const char *x) {
return ether_aton_r (x, &a);
}
|