diff options
author | Trumeet <yuuta@yuuta.moe> | 2022-07-26 17:17:09 -0700 |
---|---|---|
committer | Trumeet <yuuta@yuuta.moe> | 2022-07-26 17:17:09 -0700 |
commit | 8b07bf593e54dd876e30d0cb1c7c7226d0d1b1e2 (patch) | |
tree | fa39391ea1eef6e87a563ee417ba709a33dae596 /client/libacron/apps/acronc/helpers.c | |
parent | 219e4bb54375995fa377a1bcf9601a77cf6f1fee (diff) | |
download | acron-8b07bf593e54dd876e30d0cb1c7c7226d0d1b1e2.tar acron-8b07bf593e54dd876e30d0cb1c7c7226d0d1b1e2.tar.gz acron-8b07bf593e54dd876e30d0cb1c7c7226d0d1b1e2.tar.bz2 acron-8b07bf593e54dd876e30d0cb1c7c7226d0d1b1e2.zip |
feat(acronc): add acronc(1), the Acron cli
Still in early development, Windows support is incomplete.
Signed-off-by: Trumeet <yuuta@yuuta.moe>
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"; + } +} |