diff options
Diffstat (limited to 'toxcore/LAN_discovery.c')
-rw-r--r-- | toxcore/LAN_discovery.c | 34 |
1 files changed, 24 insertions, 10 deletions
diff --git a/toxcore/LAN_discovery.c b/toxcore/LAN_discovery.c index 70b71fea..0bb96926 100644 --- a/toxcore/LAN_discovery.c +++ b/toxcore/LAN_discovery.c | |||
@@ -27,6 +27,8 @@ | |||
27 | 27 | ||
28 | #include "LAN_discovery.h" | 28 | #include "LAN_discovery.h" |
29 | 29 | ||
30 | #include <string.h> | ||
31 | |||
30 | #include "util.h" | 32 | #include "util.h" |
31 | 33 | ||
32 | #define MAX_INTERFACES 16 | 34 | #define MAX_INTERFACES 16 |
@@ -37,7 +39,15 @@ | |||
37 | static int broadcast_count = -1; | 39 | static int broadcast_count = -1; |
38 | static IP_Port broadcast_ip_ports[MAX_INTERFACES]; | 40 | static IP_Port broadcast_ip_ports[MAX_INTERFACES]; |
39 | 41 | ||
40 | #if defined(_WIN32) || defined(__WIN32__) || defined (WIN32) | 42 | #if defined(_WIN32) || defined(__WIN32__) || defined(WIN32) |
43 | |||
44 | // The mingw32/64 Windows library warns about including winsock2.h after | ||
45 | // windows.h even though with the above it's a valid thing to do. So, to make | ||
46 | // mingw32 headers happy, we include winsock2.h first. | ||
47 | #include <winsock2.h> | ||
48 | |||
49 | #include <windows.h> | ||
50 | #include <ws2tcpip.h> | ||
41 | 51 | ||
42 | #include <iphlpapi.h> | 52 | #include <iphlpapi.h> |
43 | 53 | ||
@@ -108,6 +118,12 @@ static void fetch_broadcast_info(uint16_t port) | |||
108 | 118 | ||
109 | #elif defined(__linux__) || defined(__FreeBSD__) | 119 | #elif defined(__linux__) || defined(__FreeBSD__) |
110 | 120 | ||
121 | #include <netinet/in.h> | ||
122 | #include <sys/ioctl.h> | ||
123 | #include <sys/socket.h> | ||
124 | #include <sys/types.h> | ||
125 | #include <unistd.h> | ||
126 | |||
111 | #ifdef __linux__ | 127 | #ifdef __linux__ |
112 | #include <linux/netdevice.h> | 128 | #include <linux/netdevice.h> |
113 | #endif | 129 | #endif |
@@ -116,8 +132,6 @@ static void fetch_broadcast_info(uint16_t port) | |||
116 | #include <net/if.h> | 132 | #include <net/if.h> |
117 | #endif | 133 | #endif |
118 | 134 | ||
119 | #include <sys/ioctl.h> | ||
120 | |||
121 | static void fetch_broadcast_info(uint16_t port) | 135 | static void fetch_broadcast_info(uint16_t port) |
122 | { | 136 | { |
123 | /* Not sure how many platforms this will run on, | 137 | /* Not sure how many platforms this will run on, |
@@ -127,7 +141,7 @@ static void fetch_broadcast_info(uint16_t port) | |||
127 | broadcast_count = 0; | 141 | broadcast_count = 0; |
128 | const Socket sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0); | 142 | const Socket sock = net_socket(TOX_AF_INET, TOX_SOCK_STREAM, 0); |
129 | 143 | ||
130 | if (sock < 0) { | 144 | if (!sock_valid(sock)) { |
131 | return; | 145 | return; |
132 | } | 146 | } |
133 | 147 | ||
@@ -139,8 +153,8 @@ static void fetch_broadcast_info(uint16_t port) | |||
139 | ifconf.ifc_buf = (char *)i_faces; | 153 | ifconf.ifc_buf = (char *)i_faces; |
140 | ifconf.ifc_len = sizeof(i_faces); | 154 | ifconf.ifc_len = sizeof(i_faces); |
141 | 155 | ||
142 | if (ioctl(sock, SIOCGIFCONF, &ifconf) < 0) { | 156 | if (ioctl(sock.socket, SIOCGIFCONF, &ifconf) < 0) { |
143 | close(sock); | 157 | kill_sock(sock); |
144 | return; | 158 | return; |
145 | } | 159 | } |
146 | 160 | ||
@@ -160,12 +174,12 @@ static void fetch_broadcast_info(uint16_t port) | |||
160 | 174 | ||
161 | for (int i = 0; i < n; i++) { | 175 | for (int i = 0; i < n; i++) { |
162 | /* there are interfaces with are incapable of broadcast */ | 176 | /* there are interfaces with are incapable of broadcast */ |
163 | if (ioctl(sock, SIOCGIFBRDADDR, &i_faces[i]) < 0) { | 177 | if (ioctl(sock.socket, SIOCGIFBRDADDR, &i_faces[i]) < 0) { |
164 | continue; | 178 | continue; |
165 | } | 179 | } |
166 | 180 | ||
167 | /* moot check: only TOX_AF_INET returned (backwards compat.) */ | 181 | /* moot check: only AF_INET returned (backwards compat.) */ |
168 | if (i_faces[i].ifr_broadaddr.sa_family != TOX_AF_INET) { | 182 | if (i_faces[i].ifr_broadaddr.sa_family != AF_INET) { |
169 | continue; | 183 | continue; |
170 | } | 184 | } |
171 | 185 | ||
@@ -187,7 +201,7 @@ static void fetch_broadcast_info(uint16_t port) | |||
187 | count++; | 201 | count++; |
188 | } | 202 | } |
189 | 203 | ||
190 | close(sock); | 204 | kill_sock(sock); |
191 | 205 | ||
192 | broadcast_count = count; | 206 | broadcast_count = count; |
193 | 207 | ||