QNet/include/qnet/network.h

37 lines
1 KiB
C
Raw Permalink Normal View History

/*
* Copyright (C) Tristan Franssen, <tristanfranssen@strawhats.nl>.
*
* This software is licensed under the Apache License, Version 2.0 (the "License");
* You may not use this file except in compliance with the License.
* You may obtain a copy of the License in the file LICENSE or at
* http://www.apache.org/licenses/LICENSE-2.0
*/
#ifndef QNET_NETWORK
#define QNET_NETWORK
#if defined(__linux__)
#include <arpa/inet.h>
#define QNET_INVALID_SOCKET -1
typedef int qnet_socket_type;
#elif defined(_WIN32)
#include <winsock2.h>
#include <ws2tcpip.h>
#define QNET_INVALID_SOCKET INVALID_SOCKET
typedef SOCKET qnet_socket_type;
#endif
typedef enum {
QNET_NETWORK_ERROR_OK = 0,
QNET_NETWORK_ERROR_INVALID_IP = -1
} QNetNetworkError;
inline void qnet_socket_init(qnet_socket_type *socket) { *socket = 0; }
QNetNetworkError qnet_ip4_address(const char *ip, unsigned short port, struct sockaddr_in *address);
QNetNetworkError qnet_ip6_address(const char *ip, unsigned short port, struct sockaddr_in6 *address);
#endif /* QNET_NETWORK */