godot/thirdparty/miniupnpc/src/minissdpc.c

/* $Id: minissdpc.c,v 1.51 2024/05/16 00:12:05 nanard Exp $ */
/* vim: tabstop=4 shiftwidth=4 noexpandtab
 * Project : miniupnp
 * Web : http://miniupnp.free.fr/ or https://miniupnp.tuxfamily.org/
 * Author : Thomas BERNARD
 * copyright (c) 2005-2024 Thomas Bernard
 * This software is subjet to the conditions detailed in the
 * provided LICENCE file. */
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <sys/types.h>
#if defined (__NetBSD__)
#include <net/if.h>
#endif
#if defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__)
#ifdef _WIN32
#include <winsock2.h>
#include <ws2tcpip.h>
#include <io.h>
#include <iphlpapi.h>
#include "win32_snprintf.h"
#if !defined(_MSC_VER)
#include <stdint.h>
#else /* !defined(_MSC_VER) */
typedef unsigned short uint16_t;
#endif /* !defined(_MSC_VER) */
#ifndef strncasecmp
#if defined(_MSC_VER) && (_MSC_VER >= 1400)
#define strncasecmp
#else /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
#define strncasecmp
#endif /* defined(_MSC_VER) && (_MSC_VER >= 1400) */
#endif /* #ifndef strncasecmp */
#if defined(WINAPI_FAMILY) && defined(WINAPI_FAMILY_PARTITION)
#if WINAPI_FAMILY_PARTITION(WINAPI_PARTITION_APP) && WINAPI_FAMILY != WINAPI_FAMILY_DESKTOP_APP
#define in6addr_any
static const IN6_ADDR in6addr_any_init = {0};
#endif
#endif
#endif /* _WIN32 */
#if defined(__amigaos__) || defined(__amigaos4__)
#include <sys/socket.h>
#endif /* defined(__amigaos__) || defined(__amigaos4__) */
#if defined(__amigaos__)
#define uint16_t
#endif /* defined(__amigaos__) */
/* Hack */
#define UNIX_PATH_LEN
struct sockaddr_un {
  uint16_t sun_family;
  char     sun_path[UNIX_PATH_LEN];
};
#else /* defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__) */
#include <strings.h>
#include <unistd.h>
#include <sys/socket.h>
#include <sys/param.h>
#include <sys/time.h>
#include <sys/un.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <net/if.h>
#define closesocket
#endif

#include "miniupnpc_socketdef.h"

#if !defined(__DragonFly__) && !defined(__OpenBSD__) && !defined(__NetBSD__) && !defined(__APPLE__) && !defined(_WIN32) && !defined(__CYGWIN__) && !defined(__sun) && !defined(__GNU__) && !defined(__FreeBSD_kernel__) && !defined(__HAIKU__)
#define HAS_IP_MREQN
#endif

#ifndef _WIN32
#include <sys/ioctl.h>
#if defined(__sun) || defined(__HAIKU__)
#include <sys/sockio.h>
#endif
#endif

#if defined(HAS_IP_MREQN) && defined(NEED_STRUCT_IP_MREQN)
/* Several versions of glibc don't define this structure,
 * define it here and compile with CFLAGS NEED_STRUCT_IP_MREQN */
struct ip_mreqn
{
	struct in_addr	imr_multiaddr;		/* IP multicast address of group */
	struct in_addr	imr_address;		/* local IP address of interface */
	int		imr_ifindex;		/* Interface index */
};
#endif

#if defined(__amigaos__) || defined(__amigaos4__)
/* Amiga OS specific stuff */
#define TIMEVAL
#endif

#include "minissdpc.h"
#include "miniupnpc.h"
#include "receivedata.h"

#if !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__))

#include "codelength.h"

struct UPNPDev *
getDevicesFromMiniSSDPD(const char * devtype, const char * socketpath, int * error)
{}

/* macros used to read from unix socket */
#define READ_BYTE_BUFFER(c)

#ifndef MIN
#define MIN
#endif /* MIN */

#define READ_COPY_BUFFER(dst, len)

#define READ_DISCARD_BUFFER(len)

int
connectToMiniSSDPD(const char * socketpath)
{}

int
disconnectFromMiniSSDPD(int s)
{}

int
requestDevicesFromMiniSSDPD(int s, const char * devtype)
{}

struct UPNPDev *
receiveDevicesFromMiniSSDPD(int s, int * error)
{}

#endif /* !(defined(_WIN32) || defined(__amigaos__) || defined(__amigaos4__)) */

/* parseMSEARCHReply()
 * the last 4 arguments are filled during the parsing :
 *    - location/locationsize : "location:" field of the SSDP reply packet
 *    - st/stsize : "st:" field of the SSDP reply packet.
 *    - usn/usnsize : "usn:" filed of the SSDP reply packet
 * The strings are NOT null terminated */
static void
parseMSEARCHReply(const char * reply, int size,
                  const char * * location, int * locationsize,
			      const char * * st, int * stsize,
			      const char * * usn, int * usnsize)
{}

#if defined(CLOCK_MONOTONIC_FAST)
#define UPNP_CLOCKID
#elif defined(CLOCK_MONOTONIC)
#define UPNP_CLOCKID
#endif

static int upnp_gettimeofday(struct timeval * tv)
{}
/* port upnp discover : SSDP protocol */
#define SSDP_PORT
#define XSTR(s)
#define STR(s)
#define UPNP_MCAST_ADDR
/* for IPv6 */
#define UPNP_MCAST_LL_ADDR
#define UPNP_MCAST_SL_ADDR

/* direct discovery if minissdpd responses are not sufficient */
/* ssdpDiscoverDevices() :
 * return a chained list of all devices found or NULL if
 * no devices was found.
 * It is up to the caller to free the chained list
 * delay is in millisecond (poll).
 * UDA v1.1 says :
 *   The TTL for the IP packet SHOULD default to 2 and
 *   SHOULD be configurable. */
struct UPNPDev *
ssdpDiscoverDevices(const char * const deviceTypes[],
                    int delay, const char * multicastif,
                    int localport,
                    int ipv6, unsigned char ttl,
                    int * error,
                    int searchalltypes)
{}