cleanup: Pull #include directives to the beginning of the file.

We won't be allowing includes to appear after other declarations.
This commit is contained in:
iphydf 2021-12-20 01:31:40 +00:00
parent 9e659e6577
commit 3f0ab46229
No known key found for this signature in database
GPG Key ID: 3855DBA2D74403C9

View File

@ -10,6 +10,34 @@
#include <string.h>
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
// The mingw32/64 Windows library warns about including winsock2.h after
// windows.h even though with the above it's a valid thing to do. So, to make
// mingw32 headers happy, we include winsock2.h first.
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
#endif
#if defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#endif
#ifdef __linux__
#include <linux/netdevice.h>
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <net/if.h>
#endif
#include "util.h"
#define MAX_INTERFACES 16
@ -25,16 +53,6 @@ static IP_Port broadcast_ip_ports[MAX_INTERFACES];
#if defined(_WIN32) || defined(__WIN32__) || defined(WIN32)
// The mingw32/64 Windows library warns about including winsock2.h after
// windows.h even though with the above it's a valid thing to do. So, to make
// mingw32 headers happy, we include winsock2.h first.
#include <winsock2.h>
#include <windows.h>
#include <ws2tcpip.h>
#include <iphlpapi.h>
static void fetch_broadcast_info(uint16_t port)
{
IP_ADAPTER_INFO *pAdapterInfo = (IP_ADAPTER_INFO *)malloc(sizeof(IP_ADAPTER_INFO));
@ -104,20 +122,6 @@ static void fetch_broadcast_info(uint16_t port)
#elif defined(__linux__) || defined(__FreeBSD__) || defined(__DragonFly__)
#include <netinet/in.h>
#include <sys/ioctl.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
#ifdef __linux__
#include <linux/netdevice.h>
#endif
#if defined(__FreeBSD__) || defined(__DragonFly__)
#include <net/if.h>
#endif
static void fetch_broadcast_info(uint16_t port)
{
/* Not sure how many platforms this will run on,
@ -204,6 +208,7 @@ static void fetch_broadcast_info(uint16_t port)
}
#endif
/* Send packet to all IPv4 broadcast addresses
*
* return 1 if sent to at least one broadcast target.