2 This file is part of GNUnet.
3 (C) 2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
22 * @file nat/nat_mini.c
23 * @brief functions for interaction with miniupnp
24 * @author Christian Grothoff
27 #include "gnunet_util_lib.h"
28 #include "gnunet_nat_lib.h"
33 * Try to get the external IPv4 address of this peer.
34 * Note: calling this function may block this process
35 * for a few seconds (!).
37 * @param addr address to set
38 * @return GNUNET_OK on success,
39 * GNUNET_NO if the result is questionable,
40 * GNUNET_SYSERR on error
43 GNUNET_NAT_mini_get_external_ipv4 (struct in_addr *addr)
45 struct GNUNET_OS_Process *eip;
46 struct GNUNET_DISK_PipeHandle *opipe;
47 const struct GNUNET_DISK_FileHandle *r;
53 opipe = GNUNET_DISK_pipe (GNUNET_YES,
56 eip = GNUNET_OS_start_process (NULL,
62 GNUNET_DISK_pipe_close (opipe);
65 GNUNET_DISK_pipe_close_end (opipe, GNUNET_DISK_PIPE_END_WRITE);
67 r = GNUNET_DISK_pipe_handle (opipe,
68 GNUNET_DISK_PIPE_END_READ);
70 while (0 < (ret = GNUNET_DISK_file_read (r, &buf[off], sizeof (buf)-off)))
73 (buf[off-1] == '\n') )
76 if (1 == inet_pton (AF_INET, buf, addr))
78 if (addr->s_addr == 0)
79 iret = GNUNET_NO; /* got 0.0.0.0 */
83 (void) GNUNET_OS_process_kill (eip, SIGKILL);
84 GNUNET_OS_process_close (eip);
85 GNUNET_DISK_pipe_close (opipe);
89 /* end of nat_mini.c */