>

libsocket

#Overview

libsocket is meant to work exactly the same as the regular socket APIs when using it under IPv4 and UDP. However, under the hood, it uses UNIX sockets to communicate. As such, the only supported address is 127.0.0.1 (or localhost). Placing any other address in s_sendto does nothing. s_recvfrom will always return an address from 127.0.0.1.

If you follow the Socket Programming Tips for UDP, the only change you’ll need to make is to replace the socket, bind, recvfrom, sendto calls with ones prepended with s_.

#s_socket

int s_socket(int domain, int type, int protocol);

#Parameters

#Returns

int: Returns the file descriptor of the created socket or -1 if an error occured. Check errno for the specific error.

#s_bind

int s_bind(int sock, const struct sockaddr* addr, socklen_t len);

#Parameters

#Returns

int: Returns 0 on success or -1 if an error occured. Check errno for the specific error.

#s_recvfrom

ssize_t s_recvfrom(int sock, void* buf, size_t len, int flags, struct sockaddr* addr, socklen_t* addrlen);

#Parameters

#Returns

ssize_t: Returns the number of bytes received or -1 if an error occured. Check errno for the specific error.

#s_sendto

ssize_t s_sendto(int sock, const void* buf, size_t len, int flags, const struct sockaddr* addr, socklen_t addrlen);

#Parameters

#Returns

ssize_t: Returns the number of bytes sent or -1 if an error occured. Check errno for the specific error.