summaryrefslogtreecommitdiffstats
path: root/network/in_addr-show.c
diff options
context:
space:
mode:
Diffstat (limited to 'network/in_addr-show.c')
-rw-r--r--network/in_addr-show.c23
1 files changed, 23 insertions, 0 deletions
diff --git a/network/in_addr-show.c b/network/in_addr-show.c
new file mode 100644
index 0000000..e8dd01b
--- /dev/null
+++ b/network/in_addr-show.c
@@ -0,0 +1,23 @@
+#include <arpa/inet.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <netinet/in.h>
+#include <sys/socket.h>
+
+int main (int argc, char *argv[]) {
+ char ipstr[INET_ADDRSTRLEN];
+ unsigned long ipbin;
+
+ for (int i = 1; i < argc; i++) {
+ if (sscanf (argv[i], "%lx", &ipbin) <= 0) {
+ return 1;
+ }
+ struct in_addr ipaddr = { .s_addr = ipbin };
+ if (inet_ntop (AF_INET, &ipaddr, ipstr, INET_ADDRSTRLEN) == NULL) {
+ return 2;
+ }
+ puts (ipstr);
+ }
+
+ return 0;
+}