generated from AfonsoCMSousa/CPP-Template
43 lines
918 B
C
43 lines
918 B
C
#ifndef SOCKET_H
|
|
#define SOCKET_H
|
|
|
|
#ifdef __cplusplus
|
|
extern "C" {
|
|
#endif
|
|
|
|
#ifdef _WIN32
|
|
#include <winsock2.h>
|
|
#include <ws2tcpip.h>
|
|
#pragma comment(lib, "ws2_32.lib") // link Winsock
|
|
#else
|
|
#include <arpa/inet.h>
|
|
#include <netinet/in.h>
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <stdlib.h>
|
|
#include <string.h>
|
|
#include <sys/socket.h>
|
|
#include <sys/types.h>
|
|
#include <unistd.h>
|
|
#endif
|
|
|
|
// =========================
|
|
// UDP SOCKET FUCNTIONS
|
|
// =========================
|
|
// Server hosts a UDP socket at 127.0.0.1:12000
|
|
// Client sends a message to the server at 11000
|
|
|
|
// UDP socket creation & management
|
|
int create_udp_socket(void);
|
|
int connect_udp_socket(const char *ip, uint16_t port);
|
|
int create_bound_udp_socket(const char *ip, uint16_t port);
|
|
|
|
// UDP messaging
|
|
ssize_t send_udp_message(int sockfd, const char *message, const char *dest_ip, uint16_t dest_port);
|
|
|
|
#ifdef __cplusplus
|
|
}
|
|
#endif
|
|
|
|
#endif // SOCKET_H
|