1#include <netinet/ether.h> 2#include <stdio.h> 3#include <stdlib.h> 4 5struct ether_addr* ether_aton_r(const char* x, struct ether_addr* p_a) { 6 struct ether_addr a; 7 char* y; 8 for (int ii = 0; ii < 6; ii++) { 9 unsigned long int n; 10 if (ii != 0) { 11 if (x[0] != ':') 12 return 0; /* bad format */ 13 else 14 x++; 15 } 16 n = strtoul(x, &y, 16); 17 x = y; 18 if (n > 0xFF) 19 return 0; /* bad byte */ 20 a.ether_addr_octet[ii] = n; 21 } 22 if (x[0] != 0) 23 return 0; /* bad format */ 24 *p_a = a; 25 return p_a; 26} 27 28struct ether_addr* ether_aton(const char* x) { 29 static struct ether_addr a; 30 return ether_aton_r(x, &a); 31} 32 33char* ether_ntoa_r(const struct ether_addr* p_a, char* x) { 34 char* y; 35 y = x; 36 for (int ii = 0; ii < 6; ii++) { 37 x += sprintf(x, ii == 0 ? "%.2X" : ":%.2X", p_a->ether_addr_octet[ii]); 38 } 39 return y; 40} 41 42char* ether_ntoa(const struct ether_addr* p_a) { 43 static char x[18]; 44 return ether_ntoa_r(p_a, x); 45} 46 47int ether_line(const char* l, struct ether_addr* e, char* hostname) { 48 return -1; 49} 50 51int ether_ntohost(char* hostname, const struct ether_addr* e) { 52 return -1; 53} 54 55int ether_hostton(const char* hostname, struct ether_addr* e) { 56 return -1; 57} 58