てきとうなメモ

本の感想とか技術メモとか

2016-01-31から1日間の記事一覧

gethostbynameの引数にipアドレスを指定した場合の動作

#include <stdio.h> #include <netdb.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> int main(int argc, char **argv) { struct hostent *host = gethostbyname(argv[1]); printf("h_name = %s\n", host->h_name); printf("ip = "); for (char **addrp = host->h_addr_list; *addrp != NUL</arpa/inet.h></netinet/in.h></sys/socket.h></netdb.h></stdio.h>…