#include "gnunet_nat_lib.h"
#include "nat.h"
-#define DEBUG_NAT GNUNET_NO
+#define LOG(kind,...) GNUNET_log_from (kind, "nat", __VA_ARGS__)
/**
* How long do we give upnpc to create a mapping?
{
struct GNUNET_NAT_ExternalHandle *eh;
+ if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("external-ip", GNUNET_NO, NULL))
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("`external-ip' command not found\n"));
+ return NULL;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Running `external-ip' to determine our external IP\n");
eh = GNUNET_malloc (sizeof (struct GNUNET_NAT_ExternalHandle));
eh->cb = cb;
eh->cb_cls = cb_cls;
- eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_NO, GNUNET_YES);
+ eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == eh->opipe)
{
GNUNET_free (eh);
return NULL;
}
eh->eip =
- GNUNET_OS_start_process (NULL, eh->opipe, "external-ip", "external-ip",
+ GNUNET_OS_start_process (GNUNET_NO, 0, NULL, eh->opipe, "external-ip", "external-ip",
NULL);
if (NULL == eh->eip)
{
GNUNET_NAT_mini_get_external_ipv4_cancel (struct GNUNET_NAT_ExternalHandle *eh)
{
(void) GNUNET_OS_process_kill (eh->eip, SIGKILL);
- GNUNET_OS_process_close (eh->eip);
+ GNUNET_OS_process_destroy (eh->eip);
GNUNET_DISK_pipe_close (eh->opipe);
if (GNUNET_SCHEDULER_NO_TASK != eh->task)
GNUNET_SCHEDULER_cancel (eh->task);
* @param cls the 'struct GNUNET_NAT_MiniHandle'
* @param tc scheduler context
*/
-static void do_refresh (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+static void
+do_refresh (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
/**
* @param cls the 'struct GNUNET_NAT_MiniHandle'
* @param line line of output, NULL at the end
*/
-static void process_map_output (void *cls, const char *line);
+static void
+process_map_output (void *cls, const char *line);
/**
}
/*
* we're looking for output of the form:
- *
+ *
* "0 TCP 3000->192.168.2.150:3000 'libminiupnpc' ''"
* "1 UDP 3001->192.168.2.150:3001 'libminiupnpc' ''"
- *
+ *
* the pattern we look for is:
- *
+ *
* "%s TCP PORT->STRING:OURPORT *" or
* "%s UDP PORT->STRING:OURPORT *"
*/
if (NULL == strstr (s, pstr))
return; /* skip */
if (1 !=
- sscanf (line,
- (mini->
- is_tcp) ? "%*u TCP %u->%*s:%*u %*s" :
+ SSCANF (line,
+ (mini->is_tcp) ? "%*u TCP %u->%*s:%*u %*s" :
"%*u UDP %u->%*s:%*u %*s", &nport))
return; /* skip */
mini->found = GNUNET_YES;
{
struct GNUNET_NAT_MiniHandle *mini = cls;
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Running `upnpc' to check if our mapping still exists\n");
mini->refresh_task = GNUNET_SCHEDULER_NO_TASK;
mini->found = GNUNET_NO;
mini->refresh_cmd =
}
/*
* The upnpc output we're after looks like this:
- *
+ *
* "external 87.123.42.204:3000 TCP is redirected to internal 192.168.2.150:3000"
*/
if ((NULL == (ipaddr = strstr (line, " "))) ||
(NULL == (pstr = strstr (ipaddr, ":"))) ||
- (1 != sscanf (pstr + 1, "%u", &port)))
+ (1 != SSCANF (pstr + 1, "%u", &port)))
{
return; /* skip line */
}
* general-purpose 'GNUNET_NAT_register' code). However, it can be
* used if specifically UPnP-based NAT traversal is to be used or
* tested.
- *
+ *
* @param port port to map
* @param is_tcp GNUNET_YES to map TCP, GNUNET_NO for UDP
* @param ac function to call with mapping result
struct GNUNET_NAT_MiniHandle *ret;
char pstr[6];
- if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("upnpc"))
+ if (GNUNET_SYSERR == GNUNET_OS_check_helper_binary ("upnpc", GNUNET_NO, NULL))
+ {
+ LOG (GNUNET_ERROR_TYPE_INFO,
+ _("`upnpc' command not found\n"));
return NULL;
+ }
+ LOG (GNUNET_ERROR_TYPE_DEBUG,
+ "Running `upnpc' to install mapping\n");
ret = GNUNET_malloc (sizeof (struct GNUNET_NAT_MiniHandle));
ret->ac = ac;
ret->ac_cls = ac_cls;
if (NULL == line)
{
-#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat", "UPnP unmap done\n");
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "UPnP unmap done\n");
GNUNET_OS_command_stop (mini->unmap_cmd);
mini->unmap_cmd = NULL;
GNUNET_free (mini);
* this function will give 'upnpc' 1s to remove tha mapping,
* so while this function is non-blocking, a task will be
* left with the scheduler for up to 1s past this call.
- *
+ *
* @param mini the handle
*/
void
* often are the same, but it might... */
GNUNET_snprintf (pstr, sizeof (pstr), "%u",
(unsigned int) ntohs (mini->current_addr.sin_port));
-#if DEBUG_NAT
- GNUNET_log_from (GNUNET_ERROR_TYPE_DEBUG, "nat",
- "Unmapping port %u with UPnP\n",
- ntohs (mini->current_addr.sin_port));
-#endif
+ LOG (GNUNET_ERROR_TYPE_DEBUG, "Unmapping port %u with UPnP\n",
+ ntohs (mini->current_addr.sin_port));
mini->unmap_cmd =
GNUNET_OS_command_run (&process_unmap_output, mini, UNMAP_TIMEOUT,
"upnpc", "upnpc", "-d", pstr,