diff options
Diffstat (limited to 'client/libacron/apps/acronc/helpers.c')
-rw-r--r-- | client/libacron/apps/acronc/helpers.c | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/client/libacron/apps/acronc/helpers.c b/client/libacron/apps/acronc/helpers.c new file mode 100644 index 0000000..9e141d4 --- /dev/null +++ b/client/libacron/apps/acronc/helpers.c @@ -0,0 +1,58 @@ +/* + * Created by yuuta on 7/24/22. + */ + +#include "helpers.h" + +#include <libac.h> +#include <string.h> +#include <errno.h> + +#ifdef WIN32 +#include <winsock2.h> +#include <ws2tcpip.h> +#include <ws2ipdef.h> + +#define errno_sock WSAGetLastError() + +#else + +#include <arpa/inet.h> +#include <sys/socket.h> + +#define errno_sock errno + +#endif + +const char *ntop(const struct sockaddr *sa) { + static char buf[INET6_ADDRSTRLEN]; + const char *retval; + switch (sa->sa_family) { + case AF_INET: { + retval = inet_ntop(AF_INET, &((struct sockaddr_in *) sa)->sin_addr, buf, sizeof(buf)); + break; + } + case AF_INET6: { + retval = inet_ntop(AF_INET6, &((struct sockaddr_in6 *) sa)->sin6_addr, buf, sizeof(buf)); + break; + } + default: { + return "Unknown address family"; + } + } + if (retval) return retval; + return strerror(errno_sock); +} + +const char *world_name(const enum ac_world world) { + switch (world) { + case overworld: + return "overworld"; + case nether: + return "nether"; + case end: + return "end"; + default: + return "unknown world"; + } +} |