Last active
July 28, 2020 07:30
-
-
Save GunjiD/9fadd1e83e40892c1ad03821407c7081 to your computer and use it in GitHub Desktop.
簡易ntop実装
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <string.h> | |
#include <arpa/inet.h> | |
#include <stdio.h> | |
#include <stdlib.h> | |
/* | |
https://code.woboq.org/userspace/glibc/resolv/inet_ntop.c.html#15tmp | |
*/ | |
void ip_ntop(uint32_t src, char *dest){ | |
u_char addr[16]; | |
sprintf(addr,"%u.%u.%u.%u",(src >> 0) & 0xFF,(src >> 8) & 0xFF,(src >> 16) & 0xFF,(src >> 24) & 0xFF); | |
strcpy(dest, addr); | |
} | |
int main(int argc, char *argv[]){ | |
uint32_t address = 2600511680; //IP 想定 | |
char ip[16]; | |
ip_ntop(address, ip); | |
printf("%s\n", ip); | |
return 0; | |
} | |
/* | |
printf("%ld", sizeof "255.255.255.255"); | |
結果 | |
16 | |
255.255.255.255 は 16バイト | |
*/ |
Author
GunjiD
commented
Jul 28, 2020
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment