version 1.13.2.1, 2016/08/02 11:23:31
|
version 1.18.2.1, 2018/04/04 01:22:15
|
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 - 2016 | Copyright 2004 - 2018 |
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 49 SUCH DAMAGE.
|
Line 49 SUCH DAMAGE.
|
#ifndef __linux__ |
#ifndef __linux__ |
static char hexlist[] = "0123456789abcdef"; |
static char hexlist[] = "0123456789abcdef"; |
|
|
|
#ifndef HAVE_LINK_ADDR |
|
|
|
/* States*/ |
|
#define NAMING 0 |
|
#define GOTONE 1 |
|
#define GOTTWO 2 |
|
#define RESET 3 |
|
/* Inputs */ |
|
#define DIGIT (4*0) |
|
#define END (4*1) |
|
#define DELIM (4*2) |
|
#define LETTER (4*3) |
|
|
|
void |
|
link_addr(const char *addr, struct sockaddr_dl *sdl) |
|
{ |
|
char *cp = sdl->sdl_data; |
|
char *cplim = sdl->sdl_len + (char *)sdl; |
|
int byte = 0, state = NAMING, new; |
|
|
|
bzero((char *)&sdl->sdl_family, sdl->sdl_len - 1); |
|
sdl->sdl_family = AF_LINK; |
|
do { |
|
state &= ~LETTER; |
|
if ((*addr >= '0') && (*addr <= '9')) { |
|
new = *addr - '0'; |
|
} else if ((*addr >= 'a') && (*addr <= 'f')) { |
|
new = *addr - 'a' + 10; |
|
} else if ((*addr >= 'A') && (*addr <= 'F')) { |
|
new = *addr - 'A' + 10; |
|
} else if (*addr == 0) { |
|
state |= END; |
|
} else if (state == NAMING && |
|
(((*addr >= 'A') && (*addr <= 'Z')) || |
|
((*addr >= 'a') && (*addr <= 'z')))) |
|
state |= LETTER; |
|
else |
|
state |= DELIM; |
|
addr++; |
|
switch (state /* | INPUT */) { |
|
case NAMING | DIGIT: |
|
case NAMING | LETTER: |
|
*cp++ = addr[-1]; |
|
continue; |
|
case NAMING | DELIM: |
|
state = RESET; |
|
sdl->sdl_nlen = cp - sdl->sdl_data; |
|
continue; |
|
case GOTTWO | DIGIT: |
|
*cp++ = byte; |
|
/* FALLTHROUGH */ |
|
case RESET | DIGIT: |
|
state = GOTONE; |
|
byte = new; |
|
continue; |
|
case GOTONE | DIGIT: |
|
state = GOTTWO; |
|
byte = new + (byte << 4); |
|
continue; |
|
default: /* | DELIM */ |
|
state = RESET; |
|
*cp++ = byte; |
|
byte = 0; |
|
continue; |
|
case GOTONE | END: |
|
case GOTTWO | END: |
|
*cp++ = byte; |
|
/* FALLTHROUGH */ |
|
case RESET | END: |
|
break; |
|
} |
|
break; |
|
} while (cp < cplim); |
|
sdl->sdl_alen = cp - LLADDR(sdl); |
|
new = cp - (char *)sdl; |
|
if (new > sizeof(*sdl)) |
|
sdl->sdl_len = new; |
|
return; |
|
} |
|
#endif |
|
|
|
|
/* |
/* |
* e_link_ntoa() - String ethernet address from link address |
* e_link_ntoa() - String ethernet address from link address |
* |
* |
Line 256 e_n2addr(sockaddr_t * __restrict addr, ait_val_t * __r
|
Line 338 e_n2addr(sockaddr_t * __restrict addr, ait_val_t * __r
|
* @psHost = Hostname |
* @psHost = Hostname |
* @port = Port |
* @port = Port |
* @addr = Network address structure |
* @addr = Network address structure |
* return: 0 error or >0 network structure length | * return: 0 is error or >0 length of network structure |
*/ |
*/ |
socklen_t |
socklen_t |
e_gethostbyname(const char *psHost, u_short port, sockaddr_t * __restrict addr) |
e_gethostbyname(const char *psHost, u_short port, sockaddr_t * __restrict addr) |
Line 316 e_gethostbyname(const char *psHost, u_short port, sock
|
Line 398 e_gethostbyname(const char *psHost, u_short port, sock
|
} |
} |
|
|
/* |
/* |
|
* e_addrlen() - Get address length from network structure |
|
* |
|
* @addr = address |
|
* return: 0 is error or >0 length of network structure |
|
*/ |
|
socklen_t |
|
e_addrlen(const sockaddr_t *addr) |
|
{ |
|
if (!addr) |
|
return 0; |
|
|
|
switch (addr->sa.sa_family) { |
|
case AF_INET: |
|
return sizeof addr->sin; |
|
case AF_INET6: |
|
return sizeof addr->sin6; |
|
case AF_LOCAL: |
|
return sizeof addr->sun; |
|
#ifndef __linux__ |
|
case AF_LINK: |
|
return sizeof addr->sdl; |
|
#endif |
|
} |
|
|
|
return E_SOCKADDR_MAX; |
|
} |
|
|
|
/* |
* e_addrcmp() - Compare network addresses |
* e_addrcmp() - Compare network addresses |
* |
* |
* @a = 1st address |
* @a = 1st address |
Line 388 e_innet(netaddr_t * __restrict net, inaddr_t * __restr
|
Line 498 e_innet(netaddr_t * __restrict net, inaddr_t * __restr
|
case AF_INET: |
case AF_INET: |
for (i = 0; i < sizeof(struct in_addr); i++) { |
for (i = 0; i < sizeof(struct in_addr); i++) { |
ret = ((caddr_t) &net->addr.sin.sin_addr.s_addr)[i] & |
ret = ((caddr_t) &net->addr.sin.sin_addr.s_addr)[i] & |
net->mask.in.s4_addr[i]; | net->mask.in4.s4_addr[i]; |
ret -= addr->in.s4_addr[i] & net->mask.in.s4_addr[i]; | ret -= addr->in4.s4_addr[i] & net->mask.in4.s4_addr[i]; |
if (ret) |
if (ret) |
break; |
break; |
} |
} |
Line 453 e_getnet(const char *net)
|
Line 563 e_getnet(const char *net)
|
#endif |
#endif |
n->addr.sin.sin_family = host->h_addrtype; |
n->addr.sin.sin_family = host->h_addrtype; |
memcpy(&n->addr.sin.sin_addr, host->h_addr, sizeof n->addr.sin.sin_addr); |
memcpy(&n->addr.sin.sin_addr, host->h_addr, sizeof n->addr.sin.sin_addr); |
if (wrk) | if (wrk && strtol(wrk, NULL, 10) != 32) |
n->mask.in.s_addr = E_CIDRMASK(strtol(wrk, NULL, 10)); |
n->mask.in.s_addr = E_CIDRMASK(strtol(wrk, NULL, 10)); |
else |
else |
n->mask.in.s_addr = 0xFFFFFFFF; |
n->mask.in.s_addr = 0xFFFFFFFF; |