equal
deleted
inserted
replaced
17 if (argc < 2) { |
17 if (argc < 2) { |
18 fprintf(stderr, "Usage: %s hostname [service [protocol]]\n", argv[0]); |
18 fprintf(stderr, "Usage: %s hostname [service [protocol]]\n", argv[0]); |
19 exit(1); |
19 exit(1); |
20 } |
20 } |
21 |
21 |
22 node = argc > 1 ? argv[1] : NULL; |
22 node = argc > 1 ? argv[1] : NULL; |
23 service = argc > 2 ? argv[2] : NULL; |
23 service = argc > 2 ? argv[2] : NULL; |
24 proto = argc > 3 ? argv[3] : NULL; |
24 proto = argc > 3 ? argv[3] : NULL; |
25 |
25 |
26 hints.ai_socktype = proto == NULL ? 0 |
26 hints.ai_socktype = proto == NULL ? 0 |
27 : strcmp(proto, "tcp") == 0 ? SOCK_STREAM |
27 : strcmp(proto, "tcp") == 0 ? SOCK_STREAM |
28 : strcmp(proto, "udp") == 0 ? SOCK_DGRAM |
28 : strcmp(proto, "udp") == 0 ? SOCK_DGRAM |
29 : 0; |
29 : 0; |
30 |
30 |
31 e = getaddrinfo(node, service, &hints, &results); |
31 e = getaddrinfo(node, service, &hints, &results); |
32 |
32 |
33 if (e) { |
33 if (e) { |
48 if (e) { |
48 if (e) { |
49 fprintf(stderr, "getnameinfo: %s\n", gai_strerror(e)); |
49 fprintf(stderr, "getnameinfo: %s\n", gai_strerror(e)); |
50 continue; |
50 continue; |
51 } |
51 } |
52 |
52 |
53 printf("%s, %s %d/%d\n", host, service, r->ai_socktype, r->ai_protocol); |
53 printf("%s, %s %d/%d\n", |
|
54 host, |
|
55 service, |
|
56 r->ai_socktype, |
|
57 r->ai_protocol); |
54 } |
58 } |
55 |
59 |
56 |
60 |
57 return 0; |
61 return 0; |
58 |
62 |