*/
char buf[17];
+ /**
+ * Error code for better debugging and user feedback
+ */
+ enum GNUNET_NAT_FailureCode ret;
};
struct GNUNET_NAT_ExternalHandle *eh = cls;
ssize_t ret;
struct in_addr addr;
- int iret;
eh->task = GNUNET_SCHEDULER_NO_TASK;
if (GNUNET_YES == GNUNET_NETWORK_fdset_handle_isset (tc->read_ready, eh->r))
ret =
GNUNET_DISK_file_read (eh->r, &eh->buf[eh->off],
sizeof (eh->buf) - eh->off);
- else
+ else {
+ eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
ret = -1; /* error reading, timeout, etc. */
+ }
if (ret > 0)
{
/* try to read more */
&read_external_ipv4, eh);
return;
}
- iret = GNUNET_NO;
+ eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_OUTPUT_INVALID;
if ((eh->off > 7) && (eh->buf[eh->off - 1] == '\n'))
{
eh->buf[eh->off - 1] = '\0';
if (1 == inet_pton (AF_INET, eh->buf, &addr))
{
- if (0 == addr.s_addr)
- iret = GNUNET_NO; /* got 0.0.0.0 */
+ if (0 != addr.s_addr)
+ eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_ADDRESS_INVALID; /* got 0.0.0.0 */
else
- iret = GNUNET_OK;
+ eh->ret = GNUNET_NAT_ERROR_SUCCESS;
}
}
eh->cb (eh->cb_cls,
- (GNUNET_OK == iret)
- ? &addr :
- NULL,
- (GNUNET_OK == iret)
- ? NULL
- : _("no valid address was returned by `external-ip'"));
+ (GNUNET_NAT_ERROR_SUCCESS == eh->ret) ? &addr : NULL,
+ eh->ret);
GNUNET_NAT_mini_get_external_ipv4_cancel (eh);
}
eh->task = GNUNET_SCHEDULER_NO_TASK;
eh->cb (eh->cb_cls,
NULL,
- _("`external-ip' command not found"));
+ eh->ret);
GNUNET_free (eh);
}
* @param timeout when to fail
* @param cb function to call with result
* @param cb_cls closure for @a cb
- * @return handle for cancellation (can only be used until @a cb is called), NULL on error
+ * @return handle for cancellation (can only be used until @a cb is called), never NULL
*/
struct GNUNET_NAT_ExternalHandle *
GNUNET_NAT_mini_get_external_ipv4 (struct GNUNET_TIME_Relative timeout,
eh = GNUNET_new (struct GNUNET_NAT_ExternalHandle);
eh->cb = cb;
eh->cb_cls = cb_cls;
+ eh->ret = GNUNET_NAT_ERROR_SUCCESS;
if (GNUNET_SYSERR ==
GNUNET_OS_check_helper_binary ("external-ip", GNUNET_NO, NULL))
{
LOG (GNUNET_ERROR_TYPE_INFO,
_("`external-ip' command not found\n"));
+ eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_FOUND;
eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
eh);
return eh;
eh->opipe = GNUNET_DISK_pipe (GNUNET_YES, GNUNET_YES, GNUNET_NO, GNUNET_YES);
if (NULL == eh->opipe)
{
+ eh->ret = GNUNET_NAT_ERROR_IPC_FAILURE;
eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
eh);
return eh;
if (NULL == eh->eip)
{
GNUNET_DISK_pipe_close (eh->opipe);
+ eh->ret = GNUNET_NAT_ERROR_EXTERNAL_IP_UTILITY_NOT_EXECUTEABLE;
eh->task = GNUNET_SCHEDULER_add_now (&signal_external_ip_error,
eh);
return eh;
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL, 0,
- _("Failed to run `upnpc` command"));
+ GNUNET_NAT_ERROR_UPNPC_FAILED);
return;
}
}
GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
mini->did_map = GNUNET_NO;
}
run_upnpc_r (mini);
mini->ac (mini->ac_cls, GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
mini->current_addr.sin_addr = exip;
mini->ac (mini->ac_cls, GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
return;
}
/*
mini->ac (mini->ac_cls, GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
mini->current_addr.sin_port = htons ((uint16_t) nport);
mini->ac (mini->ac_cls, GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
}
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL, 0,
- _("`upnpc' command took too long, process killed"));
+ GNUNET_NAT_ERROR_UPNPC_TIMEOUT);
}
mini->ac (mini->ac_cls,
GNUNET_SYSERR,
NULL, 0,
- _("`upnpc' command failed to establish port mapping"));
+ GNUNET_NAT_ERROR_UPNPC_PORTMAP_FAILED);
if (GNUNET_SCHEDULER_NO_TASK == mini->refresh_task)
mini->refresh_task =
GNUNET_SCHEDULER_add_delayed (MAP_REFRESH_FREQ, &do_refresh, mini);
mini->ac (mini->ac_cls, GNUNET_YES,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
}
ac (ac_cls,
GNUNET_SYSERR,
NULL, 0,
- _("`upnpc` command not found"));
+ GNUNET_NAT_ERROR_UPNPC_NOT_FOUND);
return NULL;
}
LOG (GNUNET_ERROR_TYPE_DEBUG,
/**
* Process output from our 'unmap' command.
*
- * @param cls the 'struct GNUNET_NAT_MiniHandle'
+ * @param cls the `struct GNUNET_NAT_MiniHandle`
* @param line line of output, NULL at the end
*/
static void
mini->ac (mini->ac_cls, GNUNET_NO,
(const struct sockaddr *) &mini->current_addr,
sizeof (mini->current_addr),
- NULL);
+ GNUNET_NAT_ERROR_SUCCESS);
/* Note: oddly enough, deletion uses the external port whereas
* addition uses the internal port; this rarely matters since they
* often are the same, but it might... */