|
|
| version 1.10.10.3, 2014/11/17 23:00:36 | version 1.10.10.7, 2014/12/17 01:12:34 |
|---|---|
| Line 95 e_link_ntoa(const struct sockaddr_dl *sdl) | Line 95 e_link_ntoa(const struct sockaddr_dl *sdl) |
| } | } |
| /* | /* |
| * e_link_addr() - String ethernet address to link address | |
| * | |
| * @mac = ethernet address | |
| * @sdl = link address | |
| * return: -1 error or 0 ok | |
| */ | |
| int | |
| e_link_addr(const char *mac, struct sockaddr_dl * __restrict sdl) | |
| { | |
| if (!mac || !sdl) | |
| return -1; | |
| if (!sdl->sdl_len) | |
| sdl->sdl_len = sizeof(struct sockaddr_dl); | |
| link_addr(mac, sdl); | |
| return 0; | |
| } | |
| /* | |
| * e_ether_ntoa() - Convert ethernet address to string | * e_ether_ntoa() - Convert ethernet address to string |
| * | * |
| * @n = ethernet address structure, like struct ether_addr | * @n = ethernet address structure, like struct ether_addr |
| Line 110 e_ether_ntoa(const ether_addr_t * __restrict n, char * | Line 129 e_ether_ntoa(const ether_addr_t * __restrict n, char * |
| memset(a, 0, len); | memset(a, 0, len); |
| if (snprintf(a, len, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", | if (snprintf(a, len, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
| n->ether_addr_octet[0], n->ether_addr_octet[1], | n->octet[0], n->octet[1], |
| n->ether_addr_octet[2], n->ether_addr_octet[3], | n->octet[2], n->octet[3], |
| n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17) | n->octet[4], n->octet[5]) < 17) |
| return NULL; | return NULL; |
| return a; | return a; |
| Line 134 e_ether_aton(const char *a, ether_addr_t * __restrict | Line 153 e_ether_aton(const char *a, ether_addr_t * __restrict |
| return NULL; | return NULL; |
| i = sscanf(a, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", | i = sscanf(a, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
| &e->ether_addr_octet[0], | &e->octet[0], |
| &e->ether_addr_octet[1], | &e->octet[1], |
| &e->ether_addr_octet[2], | &e->octet[2], |
| &e->ether_addr_octet[3], | &e->octet[3], |
| &e->ether_addr_octet[4], | &e->octet[4], |
| &e->ether_addr_octet[5]); | &e->octet[5]); |
| if (i != 6) | if (i != 6) |
| return NULL; | return NULL; |
| Line 520 e_getifacebyname(const char *psIface, sockaddr_t * __r | Line 539 e_getifacebyname(const char *psIface, sockaddr_t * __r |
| freeifaddrs(ifa); | freeifaddrs(ifa); |
| return addr; | return addr; |
| } | |
| /* | |
| * e_getlinkbyname() - Get host ethernet address and make network structure | |
| * | |
| * @psHost = Host ethernet address | |
| * @addr = Network address structure | |
| * return: NULL error or !=NULL network structure | |
| */ | |
| sockaddr_t * | |
| e_getlinkbyname(const char *psHost, sockaddr_t * __restrict addr) | |
| { | |
| ait_val_t v; | |
| sockaddr_t *a = addr; | |
| if (!psHost || !addr) | |
| return NULL; | |
| else | |
| memset(addr, 0, sizeof(sockaddr_t)); | |
| AIT_INIT_VAL2(&v, string); | |
| if (!strchr(psHost, '.')) | |
| AIT_SET_STR(&v, ":"); | |
| AIT_SET_STRCAT(&v, psHost); | |
| addr->sdl.sdl_len = sizeof(struct sockaddr_dl); | |
| if (e_link_addr(AIT_GET_STR(&v), &addr->sdl)) | |
| a = NULL; | |
| AIT_FREE_VAL(&v); | |
| return a; | |
| } | |
| /* | |
| * e_getlinkbyether() - Get ethernet address and make network structure | |
| * | |
| * @mac = Ethernet address | |
| * @idx = Interface index | |
| * @type = Interface type | |
| * @iface = Interface name | |
| * @addr = Network address structure | |
| * return: NULL error or !=NULL network structure | |
| */ | |
| sockaddr_t * | |
| e_getlinkbyether(const ether_addr_t * __restrict mac, u_short idx, u_char type, | |
| const char *iface, sockaddr_t * __restrict addr) | |
| { | |
| sockaddr_t *a = addr; | |
| if (!addr) | |
| return NULL; | |
| else | |
| memset(addr, 0, sizeof(sockaddr_t)); | |
| addr->sdl.sdl_len = sizeof(struct sockaddr_dl); | |
| addr->sdl.sdl_family = AF_LINK; | |
| addr->sdl.sdl_index = idx; | |
| addr->sdl.sdl_type = type; | |
| if (iface && *iface) { | |
| addr->sdl.sdl_nlen = strlen(iface); | |
| memcpy(addr->sdl.sdl_data, iface, addr->sdl.sdl_nlen); | |
| } | |
| addr->sdl.sdl_alen = sizeof(ether_addr_t); | |
| memcpy(LLADDR(&addr->sdl), mac, addr->sdl.sdl_alen); | |
| return a; | |
| } | } |