#pragma once #include #include #include #include #include #include #include #include /* * man 7 udp about receive operation on UDP sockets: * * > All receive operations return only one packet. When the packet is smaller than the passed * > buffer, only that much data is returned; when it is bigger, the packet is truncated and the * > MSG_TRUNC flag is set. MSG_WAITALL is not supported. */ enum FD_STATE { FDS_READY, FDS_AGAIN, FDS_ERR }; enum BP_MODE { BP_READING, BP_WRITING }; union abstract_packet { char raw; struct { uint16_t size; char payload; } str; }; struct internet_packet { union abstract_packet ap; char rest[1499]; // MTU = 1500, 1 byte in the union }; struct buffer_packet { uint8_t mode; uint16_t aread; uint16_t awrite; struct internet_packet ip; }; enum FD_STATE read_packet_from_tcp(int fd, struct buffer_packet* bp); enum FD_STATE write_packet_to_tcp(int fd, struct buffer_packet* bp); enum FD_STATE write_packet_to_udp(int fd, struct buffer_packet* bp, struct sockaddr* addr, socklen_t addrlen); enum FD_STATE read_packet_from_udp (int fd, struct buffer_packet* bp, struct sockaddr* addr, socklen_t* addrlen);