This commit is contained in:
parent
90f0e2dd42
commit
368664d246
2
Makefile
2
Makefile
@ -14,7 +14,7 @@ CFLAGS := $(CFLAGS) -Ik3/src -O2 -fopenmp
|
||||
|
||||
ifneq (,$(findstring mingw,$(CC)))
|
||||
CFLAGS := -static-libgcc -static-libstdc++ -std=gnu99 -march=pentium4 -D_WIN32_WINNT=0x600 -DENET_FEATURE_ADDRESS_MAPPING -fno-pic -no-pie -fms-extensions -fno-pie -Isrc $(CFLAGS)
|
||||
LIBS := -l:libglfw3.a -lopengl32 -pthread -lm -l:libode.a -l:libvorbisfile.a -l:libvorbis.a -l:libogg.a -lportaudio -lgdi32 -lws2_32 -lwinmm -lstdc++ -lole32 -lsetupapi -lhid -l:liblua5.3.a $(LIBS)
|
||||
LIBS := -l:libglfw3.a -lopengl32 -pthread -lm -l:libode.a -l:libvorbisfile.a -l:libvorbis.a -l:libogg.a -lportaudio -lgdi32 -lws2_32 -lwinmm -lstdc++ -lole32 -lsetupapi -lhid -l:liblua5.3.a -liphlpapi $(LIBS)
|
||||
else
|
||||
CFLAGS := -march=opteron $(SAN) -std=gnu99 -DENET_FEATURE_ADDRESS_MAPPING -fms-extensions -fno-pic -no-pie -fno-pie -Isrc $(CFLAGS)
|
||||
LIBS := -lglfw3 -pthread -ldl -lm -lode -lstdc++ -llua5.3 -lvorbis -lvorbisfile -lportaudio $(LIBS)
|
||||
|
19
src/stoon.c
19
src/stoon.c
@ -4,11 +4,13 @@
|
||||
#include<winsock2.h>
|
||||
#include<ws2tcpip.h>
|
||||
#include<ntsecapi.h>
|
||||
#include<iphlpapi.h>
|
||||
#else
|
||||
#include<netdb.h>
|
||||
#include<sys/socket.h>
|
||||
#include<sys/random.h>
|
||||
#include<arpa/inet.h>
|
||||
#include<ifaddrs.h>
|
||||
#endif
|
||||
#include<unistd.h>
|
||||
#include<sys/types.h>
|
||||
@ -17,7 +19,6 @@
|
||||
#include<string.h>
|
||||
#include<stdio.h>
|
||||
#include<errno.h>
|
||||
#include<ifaddrs.h>
|
||||
|
||||
#define STUN_BINDING_REQUEST 0x0001
|
||||
#define STUN_BINDING_INDICATION 0x1100
|
||||
@ -73,9 +74,14 @@ static int stoon_init_mini(struct Stoon *this, struct addrinfo *serv, uint16_t m
|
||||
freeaddrinfo(myaddrinfo);
|
||||
|
||||
#ifdef _WIN32
|
||||
IP_ADAPTER_ADDRESSES *addrs = malloc(1024 * 64);
|
||||
if(GetAdaptersAddresses(serv->ai_family, GAA_FLAG_SKIP_MULTICAST, NULL, &addrs) == NO_ERROR) {
|
||||
size_t sz = 1024 * 64;
|
||||
IP_ADAPTER_ADDRESSES *addrs = malloc(sz);
|
||||
if(GetAdaptersAddresses(serv->ai_family, GAA_FLAG_SKIP_MULTICAST, NULL, addrs, &sz) == NO_ERROR) {
|
||||
for(IP_ADAPTER_ADDRESSES *ifa = addrs; ifa; ifa = ifa->Next) {
|
||||
if(!ifa->FirstUnicastAddress) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(serv->ai_family == AF_INET6) {
|
||||
uint8_t *addr = (void*) &((struct sockaddr_in6*) ifa->FirstUnicastAddress->Address.lpSockaddr)->sin6_addr;
|
||||
if(addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] == 0 && addr[4] == 0 && addr[5] == 0 && addr[6] == 0 && addr[7] == 0 && addr[8] == 0 && addr[9] == 0 && addr[10] == 0 && addr[11] == 0 && addr[12] == 0 && addr[13] == 0 && addr[14] == 0 && (addr[15] == 0 || addr[15] == 1)) {
|
||||
@ -100,7 +106,10 @@ static int stoon_init_mini(struct Stoon *this, struct addrinfo *serv, uint16_t m
|
||||
struct ifaddrs *ifaddr;
|
||||
if(getifaddrs(&ifaddr) >= 0) {
|
||||
for(struct ifaddrs *ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
|
||||
if(ifa->ifa_addr->sa_family == serv->ai_family) {
|
||||
if(!ifa->ifa_addr || ifa->ifa_addr->sa_family != serv->ai_family) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if(serv->ai_family == AF_INET6) {
|
||||
uint8_t *addr = (void*) &((struct sockaddr_in6*) ifa->ifa_addr)->sin6_addr;
|
||||
if(addr[0] == 0 && addr[1] == 0 && addr[2] == 0 && addr[3] == 0 && addr[4] == 0 && addr[5] == 0 && addr[6] == 0 && addr[7] == 0 && addr[8] == 0 && addr[9] == 0 && addr[10] == 0 && addr[11] == 0 && addr[12] == 0 && addr[13] == 0 && addr[14] == 0 && (addr[15] == 0 || addr[15] == 1)) {
|
||||
@ -118,9 +127,9 @@ static int stoon_init_mini(struct Stoon *this, struct addrinfo *serv, uint16_t m
|
||||
memcpy(this->peercode.localV4, addr, 4);
|
||||
memcpy(this->peercode.localP4, &myport, 2);
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
freeifaddrs(ifaddr);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user