mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed portablity problems.
struct in6_addr member names can differ per platform.
This commit is contained in:
parent
dde98eb345
commit
8c41244627
|
@ -564,7 +564,7 @@ static int sendnodes(DHT *dht, IP_Port ip_port, uint8_t *public_key, uint8_t *cl
|
|||
|
||||
if ((node_ip->family == AF_INET6) && IN6_IS_ADDR_V4MAPPED(&node_ip->ip6))
|
||||
/* embedded IPv4-in-IPv6 address: return it in regular sendnodes packet */
|
||||
nodes4_list[num_nodes_ok].ip_port.ip.uint32 = node_ip->ip6.s6_addr32[3];
|
||||
nodes4_list[num_nodes_ok].ip_port.ip.uint32 = node_ip->ip6.uint32[3];
|
||||
else if (node_ip->family == AF_INET)
|
||||
nodes4_list[num_nodes_ok].ip_port.ip.uint32 = node_ip->ip4.uint32;
|
||||
else /* shouldn't happen */
|
||||
|
|
|
@ -99,15 +99,15 @@ static IP broadcast_ip(sa_family_t family_socket, sa_family_t family_broadcast)
|
|||
/* FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */
|
||||
/* FE80::*: MUST be exact, for that we would need to look over all
|
||||
* interfaces and check in which status they are */
|
||||
ip.ip6.s6_addr[ 0] = 0xFF;
|
||||
ip.ip6.s6_addr[ 1] = 0x02;
|
||||
ip.ip6.s6_addr[15] = 0x01;
|
||||
ip.ip6.uint8[ 0] = 0xFF;
|
||||
ip.ip6.uint8[ 1] = 0x02;
|
||||
ip.ip6.uint8[15] = 0x01;
|
||||
} else if (family_broadcast == AF_INET) {
|
||||
ip.family = AF_INET6;
|
||||
ip.ip6.s6_addr32[0] = 0;
|
||||
ip.ip6.s6_addr32[1] = 0;
|
||||
ip.ip6.s6_addr32[2] = htonl(0xFFFF);
|
||||
ip.ip6.s6_addr32[3] = INADDR_BROADCAST;
|
||||
ip.ip6.uint32[0] = 0;
|
||||
ip.ip6.uint32[1] = 0;
|
||||
ip.ip6.uint32[2] = htonl(0xFFFF);
|
||||
ip.ip6.uint32[3] = INADDR_BROADCAST;
|
||||
}
|
||||
} else if (family_socket == AF_INET) {
|
||||
if (family_broadcast == AF_INET) {
|
||||
|
@ -166,15 +166,15 @@ static int LAN_ip(IP ip)
|
|||
{
|
||||
/* autogenerated for each interface: FE80::* (up to FEBF::*)
|
||||
FF02::1 is - according to RFC 4291 - multicast all-nodes link-local */
|
||||
if (((ip.ip6.s6_addr[0] == 0xFF) && (ip.ip6.s6_addr[1] < 3) && (ip.ip6.s6_addr[15] == 1)) ||
|
||||
((ip.ip6.s6_addr[0] == 0xFE) && ((ip.ip6.s6_addr[1] & 0xC0) == 0x80)))
|
||||
if (((ip.ip6.uint8[0] == 0xFF) && (ip.ip6.uint8[1] < 3) && (ip.ip6.uint8[15] == 1)) ||
|
||||
((ip.ip6.uint8[0] == 0xFE) && ((ip.ip6.uint8[1] & 0xC0) == 0x80)))
|
||||
return 0;
|
||||
|
||||
/* embedded IPv4-in-IPv6 */
|
||||
if (IN6_IS_ADDR_V4MAPPED(&ip.ip6)) {
|
||||
IP ip4;
|
||||
ip4.family = AF_INET;
|
||||
ip4.ip4.uint32 = ip.ip6.s6_addr32[3];
|
||||
ip4.ip4.uint32 = ip.ip6.uint32[3];
|
||||
return LAN_ip(ip4);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -100,7 +100,7 @@ static uint32_t handshake_id(Lossless_UDP *ludp, IP_Port source)
|
|||
int k;
|
||||
|
||||
for (k = 0; k < 16; k++) {
|
||||
id ^= randtable_initget(ludp, i++, source.ip.ip6.s6_addr[k]);
|
||||
id ^= randtable_initget(ludp, i++, source.ip.ip6.uint8[k]);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -120,7 +120,7 @@ int sendpacket(Networking_Core *net, IP_Port ip_port, uint8_t *data, uint32_t le
|
|||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr;
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = ip_port.port;
|
||||
addr6->sin6_addr = ip_port.ip.ip6;
|
||||
addr6->sin6_addr = ip_port.ip.ip6.in6_addr;
|
||||
|
||||
addr6->sin6_flowinfo = 0;
|
||||
addr6->sin6_scope_id = 0;
|
||||
|
@ -177,7 +177,7 @@ static int receivepacket(sock_t sock, IP_Port *ip_port, uint8_t *data, uint32_t
|
|||
} else if (addr.ss_family == AF_INET6) {
|
||||
struct sockaddr_in6 *addr_in6 = (struct sockaddr_in6 *)&addr;
|
||||
ip_port->ip.family = addr_in6->sin6_family;
|
||||
ip_port->ip.ip6 = addr_in6->sin6_addr;
|
||||
ip_port->ip.ip6.in6_addr = addr_in6->sin6_addr;
|
||||
ip_port->port = addr_in6->sin6_port;
|
||||
} else
|
||||
return -1;
|
||||
|
@ -371,7 +371,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
|||
struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)&addr;
|
||||
addr6->sin6_family = AF_INET6;
|
||||
addr6->sin6_port = 0;
|
||||
addr6->sin6_addr = ip.ip6;
|
||||
addr6->sin6_addr = ip.ip6.in6_addr;
|
||||
|
||||
addr6->sin6_flowinfo = 0;
|
||||
addr6->sin6_scope_id = 0;
|
||||
|
@ -672,7 +672,7 @@ int addr_parse_ip(const char *address, IP *to)
|
|||
|
||||
if (1 == inet_pton(AF_INET6, address, &addr6)) {
|
||||
to->family = AF_INET6;
|
||||
to->ip6 = addr6;
|
||||
to->ip6.in6_addr = addr6;
|
||||
return 1;
|
||||
};
|
||||
|
||||
|
@ -773,13 +773,13 @@ int addr_resolve(const char *address, IP *to, IP *extra)
|
|||
if (walker->ai_family == family) {
|
||||
if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) {
|
||||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr;
|
||||
to->ip6 = addr->sin6_addr;
|
||||
to->ip6.in6_addr = addr->sin6_addr;
|
||||
rc = 3;
|
||||
}
|
||||
} else if (!(rc & 2)) {
|
||||
if (walker->ai_addrlen == sizeof(struct sockaddr_in6)) {
|
||||
struct sockaddr_in6 *addr = (struct sockaddr_in6 *)walker->ai_addr;
|
||||
ip6 = addr->sin6_addr;
|
||||
ip6.in6_addr = addr->sin6_addr;
|
||||
rc |= 2;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -96,7 +96,12 @@ typedef union {
|
|||
struct in_addr in_addr;
|
||||
} IP4;
|
||||
|
||||
typedef struct in6_addr IP6;
|
||||
typedef union {
|
||||
uint8_t uint8[16];
|
||||
uint16_t uint16[8];
|
||||
uint32_t uint32[4];
|
||||
struct in6_addr in6_addr;
|
||||
} IP6;
|
||||
|
||||
typedef struct {
|
||||
sa_family_t family;
|
||||
|
|
|
@ -63,7 +63,12 @@ typedef union {
|
|||
} tox_IP4;
|
||||
|
||||
|
||||
typedef struct in6_addr tox_IP6;
|
||||
typedef union {
|
||||
uint8_t uint8[16];
|
||||
uint16_t uint16[8];
|
||||
uint32_t uint32[4];
|
||||
struct in6_addr in6_addr;
|
||||
} tox_IP6;
|
||||
|
||||
typedef struct {
|
||||
sa_family_t family;
|
||||
|
|
Loading…
Reference in New Issue
Block a user