version 1.6.4.2, 2013/07/08 11:45:01
|
version 1.10.10.4, 2014/11/26 00:30:37
|
Line 12 terms:
|
Line 12 terms:
|
All of the documentation and software included in the ELWIX and AITNET |
All of the documentation and software included in the ELWIX and AITNET |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
Releases is copyrighted by ELWIX - Sofia/Bulgaria <info@elwix.org> |
|
|
Copyright 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012, 2013 | Copyright 2004 - 2014 |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
by Michael Pounov <misho@elwix.org>. All rights reserved. |
|
|
Redistribution and use in source and binary forms, with or without |
Redistribution and use in source and binary forms, with or without |
Line 76 e_link_ntoa(const struct sockaddr_dl *sdl)
|
Line 76 e_link_ntoa(const struct sockaddr_dl *sdl)
|
firsttime ^= firsttime; |
firsttime ^= firsttime; |
else |
else |
*out++ = ':'; |
*out++ = ':'; |
|
|
i = *in++; |
i = *in++; |
if (i > 0xf) { |
if (i > 0xf) { |
out[1] = hexlist[i & 0xf]; |
out[1] = hexlist[i & 0xf]; |
i >>= 4; |
i >>= 4; |
} else | } else { |
out[1] = hexlist[0]; | out[1] = hexlist[i]; |
| i = 0; |
| } |
|
|
out[0] = hexlist[i]; |
out[0] = hexlist[i]; |
out += 2; |
out += 2; |
Line 92 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 106 e_ether_ntoa(const ether_addr_t * __restrict n, char *
|
Line 128 e_ether_ntoa(const ether_addr_t * __restrict n, char *
|
return NULL; |
return NULL; |
|
|
memset(a, 0, len); |
memset(a, 0, len); |
if (snprintf(a, len, "%02x:%02x:%02x:%02x:%02x:%02x", | if (snprintf(a, len, "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx", |
n->ether_addr_octet[0], n->ether_addr_octet[1], |
n->ether_addr_octet[0], n->ether_addr_octet[1], |
n->ether_addr_octet[2], n->ether_addr_octet[3], |
n->ether_addr_octet[2], n->ether_addr_octet[3], |
n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17) |
n->ether_addr_octet[4], n->ether_addr_octet[5]) < 17) |
Line 126 ether_addr_t *
|
Line 148 ether_addr_t *
|
e_ether_aton(const char *a, ether_addr_t * __restrict e) |
e_ether_aton(const char *a, ether_addr_t * __restrict e) |
{ |
{ |
int i; |
int i; |
u_int o0, o1, o2, o3, o4, o5; |
|
|
|
if (!a || !e) |
if (!a || !e) |
return NULL; |
return NULL; |
|
|
i = sscanf(a, "%x:%x:%x:%x:%x:%x", &o0, &o1, &o2, &o3, &o4, &o5); | i = sscanf(a, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx", |
| &e->ether_addr_octet[0], |
| &e->ether_addr_octet[1], |
| &e->ether_addr_octet[2], |
| &e->ether_addr_octet[3], |
| &e->ether_addr_octet[4], |
| &e->ether_addr_octet[5]); |
if (i != 6) |
if (i != 6) |
return NULL; |
return NULL; |
|
|
e->ether_addr_octet[0] = o0; |
|
e->ether_addr_octet[1] = o1; |
|
e->ether_addr_octet[2] = o2; |
|
e->ether_addr_octet[3] = o3; |
|
e->ether_addr_octet[4] = o4; |
|
e->ether_addr_octet[5] = o5; |
|
|
|
return e; |
return e; |
} |
} |
|
|
Line 241 e_gethostbyname(const char *psHost, u_short port, sock
|
Line 261 e_gethostbyname(const char *psHost, u_short port, sock
|
|
|
if (*psHost != '/') { |
if (*psHost != '/') { |
/* resolver */ |
/* resolver */ |
if (!addr->sa.sa_family) | host = gethostbyname2(psHost, !strchr(psHost, ':') ? AF_INET : AF_INET6); |
host = gethostbyname(psHost); | |
else | |
host = gethostbyname2(psHost, addr->sa.sa_family); | |
if (!host) { |
if (!host) { |
elwix_SetErr(EINVAL, "Resolver #%d - %s", h_errno, hstrerror(h_errno)); |
elwix_SetErr(EINVAL, "Resolver #%d - %s", h_errno, hstrerror(h_errno)); |
return NULL; |
return NULL; |
Line 444 e_getnet(const char *net)
|
Line 461 e_getnet(const char *net)
|
* |
* |
* @ifname = interface name |
* @ifname = interface name |
* @addr = if addr is !=NULL then set this for new address |
* @addr = if addr is !=NULL then set this for new address |
* return: NULL error or !=NULL get ethernet address | * return: NULL error or !=NULL get ethernet address should be e_free() |
*/ |
*/ |
ether_addr_t * |
ether_addr_t * |
e_ether_addr(const char *ifname, ether_addr_t * __restrict addr) |
e_ether_addr(const char *ifname, ether_addr_t * __restrict addr) |
Line 471 e_ether_addr(const char *ifname, ether_addr_t * __rest
|
Line 488 e_ether_addr(const char *ifname, ether_addr_t * __rest
|
freeifaddrs(ifa); |
freeifaddrs(ifa); |
|
|
return a; |
return a; |
|
} |
|
|
|
/* |
|
* e_get1stiface() - Get first interface of host |
|
* |
|
* @szIface = interface string buffer |
|
* @iflen = size of interface buffer |
|
* return: -1 error or 0 ok |
|
*/ |
|
int |
|
e_get1stiface(char *szIface, int iflen) |
|
{ |
|
struct ifaddrs *ifa; |
|
|
|
if (!szIface || !iflen) |
|
return -1; |
|
|
|
getifaddrs(&ifa); |
|
strlcpy(szIface, ifa->ifa_name, iflen); |
|
freeifaddrs(ifa); |
|
return 0; |
|
} |
|
|
|
/* |
|
* e_getifacebyname() - Get interface and make network structure |
|
* |
|
* @psIface = Interface, if =NULL first interface |
|
* @addr = Network address structure |
|
* return: NULL error or !=NULL network structure |
|
*/ |
|
sockaddr_t * |
|
e_getifacebyname(const char *psIface, sockaddr_t * __restrict addr) |
|
{ |
|
char szIface[64] = { [0 ... 63] = 0 }; |
|
struct ifaddrs *p, *ifa = NULL; |
|
|
|
if (!addr) |
|
return NULL; |
|
|
|
memset(addr, 0, sizeof(sockaddr_t)); |
|
getifaddrs(&ifa); |
|
strlcpy(szIface, psIface ? psIface : ifa->ifa_name, sizeof szIface); |
|
for (p = ifa; p && p->ifa_name; p++) |
|
if (p->ifa_name && !strcmp(p->ifa_name, szIface) && p->ifa_addr && |
|
p->ifa_addr->sa_family == AF_LINK) { |
|
memcpy(&addr->sdl, p->ifa_addr, sizeof(struct sockaddr_dl)); |
|
break; |
|
} |
|
freeifaddrs(ifa); |
|
|
|
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) |
|
{ |
|
if (!addr) |
|
return NULL; |
|
else |
|
memset(addr, 0, sizeof(sockaddr_t)); |
|
|
|
addr->sdl.sdl_len = sizeof(struct sockaddr_dl); |
|
e_link_addr(psHost, &addr->sdl); |
|
|
|
return addr; |
} |
} |