mirror of
https://github.com/irungentoo/toxcore.git
synced 2024-03-22 13:30:51 +08:00
Fixed build error on windows.
This commit is contained in:
parent
d83abccf0e
commit
a82ad576a2
|
@ -278,7 +278,7 @@ void networking_registerhandler(Networking_Core *net, uint8_t byte, packet_handl
|
||||||
void networking_poll(Networking_Core *net)
|
void networking_poll(Networking_Core *net)
|
||||||
{
|
{
|
||||||
unix_time_update();
|
unix_time_update();
|
||||||
|
|
||||||
IP_Port ip_port;
|
IP_Port ip_port;
|
||||||
uint8_t data[MAX_UDP_PACKET_SIZE];
|
uint8_t data[MAX_UDP_PACKET_SIZE];
|
||||||
uint32_t length;
|
uint32_t length;
|
||||||
|
@ -373,13 +373,15 @@ int networking_wait_execute(uint8_t *data, uint16_t len, uint16_t milliseconds)
|
||||||
/* returns -1 on error, 0 on timeout, the socket on activity */
|
/* returns -1 on error, 0 on timeout, the socket on activity */
|
||||||
int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
|
int res = select(nfds, &readfds, &writefds, &exceptfds, &timeout);
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
|
|
||||||
/* only dump if not timeout */
|
/* only dump if not timeout */
|
||||||
if (res) {
|
if (res) {
|
||||||
sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno,
|
sprintf(logbuffer, "select(%d): %d (%d, %s) - %d %d %d\n", milliseconds, res, errno,
|
||||||
strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
|
strerror(errno), FD_ISSET(s->sock, &readfds), FD_ISSET(s->sock, &writefds),
|
||||||
FD_ISSET(s->sock, &exceptfds));
|
FD_ISSET(s->sock, &exceptfds));
|
||||||
loglog(logbuffer);
|
loglog(logbuffer);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (FD_ISSET(s->sock, &writefds))
|
if (FD_ISSET(s->sock, &writefds))
|
||||||
|
@ -527,14 +529,14 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
||||||
} else
|
} else
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ip.family == AF_INET6)
|
if (ip.family == AF_INET6) {
|
||||||
{
|
|
||||||
char ipv6only = 0;
|
char ipv6only = 0;
|
||||||
socklen_t optsize = sizeof(ipv6only);
|
socklen_t optsize = sizeof(ipv6only);
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
errno = 0;
|
errno = 0;
|
||||||
#endif
|
#endif
|
||||||
int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize);
|
int res = getsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6only, &optsize);
|
||||||
|
|
||||||
if ((res == 0) && (ipv6only == 0)) {
|
if ((res == 0) && (ipv6only == 0)) {
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
loglog("Dual-stack socket: enabled per default.\n");
|
loglog("Dual-stack socket: enabled per default.\n");
|
||||||
|
@ -542,6 +544,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
||||||
} else {
|
} else {
|
||||||
ipv6only = 0;
|
ipv6only = 0;
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n",
|
sprintf(logbuffer, "Dual-stack socket: Failed to query default. (%d, %s)\n",
|
||||||
errno, strerror(errno));
|
errno, strerror(errno));
|
||||||
|
@ -551,8 +554,9 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
||||||
errno = 0;
|
errno = 0;
|
||||||
res =
|
res =
|
||||||
#endif
|
#endif
|
||||||
setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only));
|
setsockopt(temp->sock, IPPROTO_IPV6, IPV6_V6ONLY, (char *)&ipv6only, sizeof(ipv6only));
|
||||||
#ifdef LOGGING
|
#ifdef LOGGING
|
||||||
|
|
||||||
if (res < 0) {
|
if (res < 0) {
|
||||||
sprintf(logbuffer,
|
sprintf(logbuffer,
|
||||||
"Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n",
|
"Dual-stack socket: Failed to enable, won't be able to receive from/send to IPv4 addresses. (%u, %s)\n",
|
||||||
|
@ -560,6 +564,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
||||||
loglog(logbuffer);
|
loglog(logbuffer);
|
||||||
} else
|
} else
|
||||||
loglog("Dual-stack socket: Enabled successfully.\n");
|
loglog("Dual-stack socket: Enabled successfully.\n");
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,8 +612,7 @@ Networking_Core *new_networking(IP ip, uint16_t port)
|
||||||
*portptr = htons(port_to_try);
|
*portptr = htons(port_to_try);
|
||||||
int tries, res;
|
int tries, res;
|
||||||
|
|
||||||
for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++)
|
for (tries = TOX_PORTRANGE_FROM; tries <= TOX_PORTRANGE_TO; tries++) {
|
||||||
{
|
|
||||||
res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
|
res = bind(temp->sock, (struct sockaddr *)&addr, addrsize);
|
||||||
|
|
||||||
if (!res) {
|
if (!res) {
|
||||||
|
@ -674,11 +678,7 @@ int ip_equal(IP *a, IP *b)
|
||||||
if (a->family == AF_INET)
|
if (a->family == AF_INET)
|
||||||
return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
|
return (a->ip4.in_addr.s_addr == b->ip4.in_addr.s_addr);
|
||||||
else if (a->family == AF_INET6)
|
else if (a->family == AF_INET6)
|
||||||
#ifdef WIN32
|
|
||||||
return IN6_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
|
|
||||||
#else
|
|
||||||
return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
|
return IN6_ARE_ADDR_EQUAL(&a->ip6.in6_addr, &b->ip6.in6_addr);
|
||||||
#endif
|
|
||||||
else
|
else
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,6 +43,18 @@ typedef unsigned int sock_t;
|
||||||
/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */
|
/* sa_family_t is the sockaddr_in / sockaddr_in6 family field */
|
||||||
typedef short sa_family_t;
|
typedef short sa_family_t;
|
||||||
|
|
||||||
|
#ifndef IN6_ARE_ADDR_EQUAL
|
||||||
|
#ifdef IN6_ADDR_EQUAL
|
||||||
|
#define IN6_ARE_ADDR_EQUAL(a,b) IN6_ADDR_EQUAL(a,b)
|
||||||
|
#else
|
||||||
|
#define IN6_ARE_ADDR_EQUAL(a,b) \
|
||||||
|
((((__const uint32_t *) (a))[0] == ((__const uint32_t *) (b))[0]) \
|
||||||
|
&& (((__const uint32_t *) (a))[1] == ((__const uint32_t *) (b))[1]) \
|
||||||
|
&& (((__const uint32_t *) (a))[2] == ((__const uint32_t *) (b))[2]) \
|
||||||
|
&& (((__const uint32_t *) (a))[3] == ((__const uint32_t *) (b))[3]))
|
||||||
|
#endif
|
||||||
|
#endif
|
||||||
|
|
||||||
#ifndef EWOULDBLOCK
|
#ifndef EWOULDBLOCK
|
||||||
#define EWOULDBLOCK WSAEWOULDBLOCK
|
#define EWOULDBLOCK WSAEWOULDBLOCK
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue
Block a user