-
Notifications
You must be signed in to change notification settings - Fork 0
/
comm.cpp
32 lines (25 loc) · 871 Bytes
/
comm.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
/**
* @file comm.cpp
* @author Jayson Sho Toma
* @brief Supports UDP socket transmission behind the logical network configuration.
* @version 0.1
* @date 2022-05-04
*/
#include "comm.hpp"
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <unistd.h>
char recv_buffer[MAX_PACKET_BUFFER_SIZE];
char send_buffer[MAX_PACKET_BUFFER_SIZE];
int sendPacketOut(int sock_fd, char *pkt_data, uint32_t pkt_size, uint32_t dst_udp_port_no)
{
sockaddr_in dest_addr;
hostent *host = reinterpret_cast<hostent *>(gethostbyname("127.0.0.1"));
dest_addr.sin_family = AF_INET;
dest_addr.sin_port = dst_udp_port_no;
dest_addr.sin_addr = *(reinterpret_cast<in_addr *>(host->h_addr));
int rc = sendto(sock_fd, pkt_data, pkt_size, 0, reinterpret_cast<sockaddr *>(&dest_addr), sizeof(sockaddr));
return rc;
}