File tree Expand file tree Collapse file tree 2 files changed +45
-3
lines changed
Expand file tree Collapse file tree 2 files changed +45
-3
lines changed Original file line number Diff line number Diff line change 1+ #include <stdio.h>
2+ #include <netdb.h>
3+ #include <arpa/inet.h>
4+
5+
6+ int main (int argc , char * * argv )
7+ {
8+ if (argc < 2 ) {
9+ fprintf (stderr , "need argument\n" );
10+ return 1 ;
11+ }
12+ struct addrinfo hints , * result , * tmp ;
13+ struct sockaddr_in * sock_addr ;
14+ int res ;
15+ hints .ai_flags = AI_PASSIVE ;
16+ hints .ai_family = AF_INET ;
17+ hints .ai_socktype = SOCK_STREAM ;
18+ hints .ai_protocol = 0 ;
19+ hints .ai_addrlen = 0 ;
20+ hints .ai_canonname = NULL ;
21+ hints .ai_addr = NULL ;
22+ hints .ai_next = NULL ;
23+ //hints.ai_protocol = IPPROTO_ICMP;
24+
25+ if ((res = getaddrinfo (argv [1 ], NULL , & hints , & result )) != 0 ) {
26+ fprintf (stderr , "getaddrinfo: %s\n" , gai_strerror (res ));
27+ return 1 ;
28+ }
29+
30+ for (tmp = result ; tmp ; tmp = tmp -> ai_next ) {
31+ /*
32+ sockfd = socket(tmp->ai_family, tmp->ai.socktype, tmp->
33+ ai_protocol);
34+ if (sockfd == -1)
35+ continue;
36+ */
37+ sock_addr = (struct sockaddr_in * )tmp -> ai_addr ;
38+ printf ("address is: %s\n" , inet_ntoa (sock_addr -> sin_addr ));
39+ }
40+ freeaddrinfo (result );
41+ return 0 ;
42+ }
Original file line number Diff line number Diff line change 11/*
22 * ping.c
33 * written by Ivan Ryabtsov ivriabtsov at gmail dot com
4- * compile with: gcc -Wall -Wextra -g -O2 -DDEBUG=2 ping.c for maximum debug
5- * gcc -Wall -Wextra -g -O2 -DDEBUG=1 ping.c for reduce debug
6- * gcc -Wall -Wextra -g -O2 ping.c without debug
4+ * compile with: gcc -Wall -Wextra -pthread - g -O2 -DDEBUG=2 maximum debug
5+ * gcc -Wall -Wextra -pthread - g -O2 -DDEBUG=1 reduce debug
6+ * gcc -Wall -Wextra -pthread - g -O2 -DDEBUG=0 without debug
77 */
88#include <unistd.h>
99#include <stdio.h>
You can’t perform that action at this time.
0 commit comments