|
Lines 31-36
__FBSDID("$FreeBSD$");
Link Here
|
| 31 |
|
31 |
|
| 32 |
#include <sys/types.h> |
32 |
#include <sys/types.h> |
| 33 |
#include <sys/socket.h> |
33 |
#include <sys/socket.h> |
|
|
34 |
#include <sys/sysctl.h> |
| 34 |
|
35 |
|
| 35 |
#include <arpa/inet.h> |
36 |
#include <arpa/inet.h> |
| 36 |
#include <netdb.h> |
37 |
#include <netdb.h> |
|
Lines 126-140
main(int argc, char *argv[])
Link Here
|
| 126 |
else if (ipv4) |
127 |
else if (ipv4) |
| 127 |
hints.ai_family = AF_INET; |
128 |
hints.ai_family = AF_INET; |
| 128 |
else { |
129 |
else { |
| 129 |
struct addrinfo *res; |
130 |
int inet_enabled = 0; |
| 130 |
|
131 |
int inet6_enabled = 0; |
| 131 |
memset(&hints, 0, sizeof(hints)); |
132 |
size_t len = sizeof(int); |
| 132 |
hints.ai_socktype = SOCK_RAW; |
133 |
|
| 133 |
hints.ai_family = AF_UNSPEC; |
134 |
/* Ignore sysctlbyname errors */ |
| 134 |
getaddrinfo(argv[argc - 1], NULL, &hints, &res); |
135 |
sysctlbyname("kern.features.inet", &inet_enabled, &len, |
| 135 |
if (res != NULL) { |
136 |
NULL, 0); |
| 136 |
hints.ai_family = res[0].ai_family; |
137 |
sysctlbyname("kern.features.inet6", &inet6_enabled, &len, |
| 137 |
freeaddrinfo(res); |
138 |
NULL, 0); |
|
|
139 |
|
| 140 |
if (!inet6_enabled) |
| 141 |
hints.ai_family = AF_INET; |
| 142 |
else if (!inet_enabled) |
| 143 |
hints.ai_family = AF_INET6; |
| 144 |
else { |
| 145 |
struct addrinfo *res; |
| 146 |
|
| 147 |
memset(&hints, 0, sizeof(hints)); |
| 148 |
hints.ai_socktype = SOCK_RAW; |
| 149 |
hints.ai_family = AF_UNSPEC; |
| 150 |
getaddrinfo(argv[argc - 1], NULL, &hints, &res); |
| 151 |
if (res != NULL) { |
| 152 |
hints.ai_family = res[0].ai_family; |
| 153 |
freeaddrinfo(res); |
| 154 |
} |
| 138 |
} |
155 |
} |
| 139 |
} |
156 |
} |
| 140 |
#elif defined(INET) |
157 |
#elif defined(INET) |