Files
Event-Loop-in-C/asyncproject/network_utils.h
2024-10-19 15:45:40 +05:30

48 lines
987 B
C

#ifndef __NETWORK_UTILS__
#define __NETWORK_UTILS__
#include <stdint.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
#include <pthread.h>
#include <memory.h>
#include <netdb.h>
#include <errno.h>
#include <sys/socket.h>
#include <sys/select.h>
#include <netinet/in.h>
#include <unistd.h>
#include <assert.h>
#define MAX_PACKET_BUFFER_SIZE 1024
typedef void (*recv_fn_cb)(char*, /* msg recvd */
uint32_t, /* recvd msg size */
char*, /* Sender's IP address */
uint32_t, /* Sender's Port number */
uint32_t); /* Sender Communication FD , only for tcp*/
void
udp_server_create_and_start(
char* ip_addr,
uint32_t udp_port_no,
recv_fn_cb recv_fn);
int
send_udp_msg(char* dest_ip_addr,
uint32_t udp_port_no,
char* msg,
uint32_t msg_size,
int sock_fd);
/* General Nw utilities */
char*
network_covert_ip_n_to_p(uint32_t ip_addr,
char* output_buffer);
uint32_t
network_covert_ip_p_to_n(char* ip_addr);
#endif /* __NETWORK_UTILS__ */