diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-04-05 23:39:41 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-04-05 23:39:49 +0200 |
commit | c0d08bbdeed4523cf89bf55b64ce2c16476c3e26 (patch) | |
tree | 185c69641c5ec3aaa022a9ecfb43495c8467687f /src/util | |
parent | 53969c9d9a95234ee845fa0542a330f788ad2a2c (diff) | |
download | gnunet-c0d08bbdeed4523cf89bf55b64ce2c16476c3e26.tar.gz gnunet-c0d08bbdeed4523cf89bf55b64ce2c16476c3e26.zip |
fix #5352
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/os_network.c | 52 | ||||
-rw-r--r-- | src/util/test_os_network.c | 30 |
2 files changed, 65 insertions, 17 deletions
diff --git a/src/util/os_network.c b/src/util/os_network.c index dba61f1e4..9008c5c5a 100644 --- a/src/util/os_network.c +++ b/src/util/os_network.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -67,15 +67,29 @@ try_ifconfig (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
67 | struct sockaddr *pass_bcaddr; | 67 | struct sockaddr *pass_bcaddr; |
68 | struct sockaddr *pass_netmask; | 68 | struct sockaddr *pass_netmask; |
69 | int prefixlen; | 69 | int prefixlen; |
70 | static char *pcall; | ||
71 | |||
72 | if (NULL == pcall) | ||
73 | { | ||
74 | const char *sbin_ifconfig; | ||
70 | 75 | ||
71 | if (system ("ifconfig -a > /dev/null 2> /dev/null")) | 76 | #ifdef IFCONFIG |
72 | if (0 == system ("/sbin/ifconfig -a > /dev/null 2> /dev/null")) | 77 | if (0 == access (IFCONFIG, X_OK)) |
73 | f = popen ("/sbin/ifconfig -a 2> /dev/null", "r"); | 78 | sbin_ifconfig = IFCONFIG; |
74 | else | 79 | else |
75 | f = NULL; | 80 | #endif |
76 | else | 81 | if (0 == access ("/sbin/ifconfig", X_OK)) |
77 | f = popen ("ifconfig -a 2> /dev/null", "r"); | 82 | sbin_ifconfig = "/sbin/ifconfig"; |
78 | if (! f) | 83 | else if (0 == access ("/usr/sbin/ifconfig", X_OK)) |
84 | sbin_ifconfig = "/usr/sbin/ifconfig"; | ||
85 | else | ||
86 | sbin_ifconfig = "ifconfig"; | ||
87 | GNUNET_asprintf (&pcall, | ||
88 | "%s -a 2> /dev/null", | ||
89 | sbin_ifconfig); | ||
90 | } | ||
91 | f = popen (pcall, "r"); | ||
92 | if (NULL == f) | ||
79 | { | 93 | { |
80 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 94 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
81 | "popen", | 95 | "popen", |
@@ -238,8 +252,28 @@ try_ip (GNUNET_OS_NetworkInterfaceProcessor proc, | |||
238 | struct sockaddr_in6 netmask6; | 252 | struct sockaddr_in6 netmask6; |
239 | unsigned int i; | 253 | unsigned int i; |
240 | unsigned int prefixlen; | 254 | unsigned int prefixlen; |
255 | static char *pcall; | ||
241 | 256 | ||
242 | f = popen ("ip -o add 2> /dev/null", "r"); | 257 | if (NULL == pcall) |
258 | { | ||
259 | const char *sbin_ip; | ||
260 | |||
261 | #ifdef IFCONFIG | ||
262 | if (0 == access (PATH_TO_IP, X_OK)) | ||
263 | sbin_ip = PATH_TO_IP; | ||
264 | else | ||
265 | #endif | ||
266 | if (0 == access ("/sbin/ip", X_OK)) | ||
267 | sbin_ip = "/sbin/ip"; | ||
268 | else if (0 == access ("/usr/sbin/ip", X_OK)) | ||
269 | sbin_ip = "/usr/sbin/ip"; | ||
270 | else | ||
271 | sbin_ip = "if"; | ||
272 | GNUNET_asprintf (&pcall, | ||
273 | "%s -o add 2> /dev/null", | ||
274 | sbin_ip); | ||
275 | } | ||
276 | f = popen (pcall, "r"); | ||
243 | if (! f) | 277 | if (! f) |
244 | { | 278 | { |
245 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, | 279 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING | GNUNET_ERROR_TYPE_BULK, |
diff --git a/src/util/test_os_network.c b/src/util/test_os_network.c index b6e981bc3..fa769de6f 100644 --- a/src/util/test_os_network.c +++ b/src/util/test_os_network.c | |||
@@ -11,7 +11,7 @@ | |||
11 | WITHOUT ANY WARRANTY; without even the implied warranty of | 11 | WITHOUT ANY WARRANTY; without even the implied warranty of |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
13 | Affero General Public License for more details. | 13 | Affero General Public License for more details. |
14 | 14 | ||
15 | You should have received a copy of the GNU Affero General Public License | 15 | You should have received a copy of the GNU Affero General Public License |
16 | along with this program. If not, see <http://www.gnu.org/licenses/>. | 16 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 | ||
@@ -31,8 +31,12 @@ | |||
31 | * (success). | 31 | * (success). |
32 | */ | 32 | */ |
33 | static int | 33 | static int |
34 | proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | 34 | proc (void *cls, |
35 | const struct sockaddr *broadcast_addr, const struct sockaddr *netmask, | 35 | const char *name, |
36 | int isDefault, | ||
37 | const struct sockaddr *addr, | ||
38 | const struct sockaddr *broadcast_addr, | ||
39 | const struct sockaddr *netmask, | ||
36 | socklen_t addrlen) | 40 | socklen_t addrlen) |
37 | { | 41 | { |
38 | int *ok = cls; | 42 | int *ok = cls; |
@@ -46,11 +50,18 @@ proc (void *cls, const char *name, int isDefault, const struct sockaddr *addr, | |||
46 | else | 50 | else |
47 | protocol = "IPv6"; | 51 | protocol = "IPv6"; |
48 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 52 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
49 | "%s Address `%s'\n", protocol, GNUNET_a2s ((const struct sockaddr *) addr,addrlen) ); | 53 | "%s Address `%s'\n", |
54 | protocol, | ||
55 | GNUNET_a2s ((const struct sockaddr *) addr, | ||
56 | addrlen) ); | ||
50 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 57 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
51 | "Netmask `%s'\n", GNUNET_a2s ((const struct sockaddr *) netmask, addrlen) ); | 58 | "Netmask `%s'\n", |
59 | GNUNET_a2s ((const struct sockaddr *) netmask, | ||
60 | addrlen) ); | ||
52 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 61 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
53 | "`%s'\n", GNUNET_a2s ((const struct sockaddr *) broadcast_addr,addrlen) ); | 62 | "`%s'\n", |
63 | GNUNET_a2s ((const struct sockaddr *) broadcast_addr, | ||
64 | addrlen) ); | ||
54 | inet_ntop (addr->sa_family, | 65 | inet_ntop (addr->sa_family, |
55 | (addr->sa_family == | 66 | (addr->sa_family == |
56 | AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr | 67 | AF_INET) ? (void *) &((struct sockaddr_in *) addr)->sin_addr |
@@ -67,9 +78,12 @@ main (int argc, char *argv[]) | |||
67 | { | 78 | { |
68 | int ret; | 79 | int ret; |
69 | 80 | ||
70 | GNUNET_log_setup ("test-os-network", "WARNING", NULL); | 81 | GNUNET_log_setup ("test-os-network", |
82 | "WARNING", | ||
83 | NULL); | ||
71 | ret = 1; | 84 | ret = 1; |
72 | GNUNET_OS_network_interfaces_list (&proc, &ret); | 85 | GNUNET_OS_network_interfaces_list (&proc, |
86 | &ret); | ||
73 | return ret; | 87 | return ret; |
74 | } | 88 | } |
75 | 89 | ||