-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.c
More file actions
42 lines (35 loc) · 724 Bytes
/
Copy pathmain.c
File metadata and controls
42 lines (35 loc) · 724 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/* The contents of this file is in the public domain. */
#include <ipify.h>
#include <string.h>
#include <stdio.h>
#include <sys/socket.h>
int main(int argc, char *argv[])
{
char *host = IPIFY_HOST;
int family = AF_UNSPEC;
char addr[256];
int i, sd;
for (i = 1; i < argc; i++) {
if (!strcmp(argv[i], "-h")) {
printf("ipify [-46h] [HOST]\n");
return 0;
}
if (!strcmp(argv[i], "-4")) {
family = AF_INET;
continue;
}
if (!strcmp(argv[i], "-6")) {
family = AF_INET6;
continue;
}
break;
}
if (i < argc)
host = argv[i++];
sd = ipify_connect2(host, family);
if (sd < 0)
return 1;
if (!ipify_query(sd, addr, sizeof(addr)))
printf("%s\n", addr);
return ipify_disconnect(sd);
}