This file contains hidden or 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
// Author : Ouarrak Ayoub | |
#include <netinet/in.h> | |
#include <sys/socket.h> | |
#include <sys/types.h> | |
#include <arpa/inet.h> | |
#include <iostream> | |
#include <netdb.h> | |
#include <cstring> | |
#include <string> |
This file contains hidden or 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
string int2ip(unsigned int ip_num){ | |
struct in_addr in; | |
in.s_addr = ip_num; | |
return inet_ntoa(in); | |
} |
This file contains hidden or 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
/* | |
* Sample C code to obtain the IP address attached to | |
* a selected network interface under Linux. | |
* | |
* Found here: http://www.geekpage.jp/en/programming/linux-network/get-ipaddr.php | |
* | |
* Missing includes added. | |
*/ | |
#include <stdio.h> |
This file contains hidden or 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 <stdio.h> /* 標準入出力 */ | |
#include <sys/types.h> /* 派生型 */ | |
#include <sys/socket.h> /* ソケット */ | |
#include <netinet/in.h> /* AF_INET, AF_INET6アドレス・ファミリー */ | |
#include <arpa/inet.h> /* IPアドレス変換 */ | |
/* main関数の定義 */ | |
int main(void){ |
This file contains hidden or 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 <netdb.h> | |
#include <stdio.h> | |
int main(int argc, char * argv[]) { | |
if(argc > 1) { | |
int i; | |
struct hostent *hent; | |
hent = gethostbyname(argv[1]); | |
printf("Hostname: %s\n", hent->h_name); | |
for(i = 0; hent->h_addr_list[i] != 0; i+=1) { | |
printf("IP: %s\n", inet_ntoa(*((long *)hent->h_addr_list[i])), i); |