A single header wrapper library for linux socket programming
Copy the header file cxsock.h into your project and you are good to go.
useful documented functions are given below:
int make_socket(const char *host_str, const char *port_str, int socktype, int flags, struct addrinfo **res_out)Creates a socket using the given host, port, socket type and address flags to create a socket, and sets theres_outpointer(if it's notNULL) to the utilized address info(this is allocated)
Returns negative number if failure occured
-
ssize_t sendall(int sockfd, const void *buf, size_t len, int flags)blocks the caller thread until it sends all the data -
ssize_t recvall(int sockfd, void *buf, size_t len, int flags)blocks the caller thread until it reads everything from the net socket -
void pack32(const void *data, char *out)packs the 32 bit data 0 -> LSB to 4 -> MSB(little endian) -
void unpack32(const char *packed, void *out)unpacks the 32 bit data from 0 -> LSB to 4 -> MSB(little endian) -
void pack64(const void *data, char *out)packs the 64 bit data 0 -> LSB to 8 -> MSB(little endian) -
void unpack64(const char *packed, void *out)unpacks the 64 bit data from 0 -> LSB to 8 -> MSB(little endian) -
int is_big_endian()as the name suggests, returns whether or not this system is big endian, otherwise little endian. (THIS FUNCTION IS NOT COMPILE TIME) -
pack32_inplace(...)a macro that callspack32but packs the given data in the same memory location -
unpack32_inplace(...)a macro that callsunpack32but unpacks the given data in the same memory location
Licensed under MIT