Commit a0e18579 authored by Martti Mela's avatar Martti Mela

STUN: get_nattype works (at least for open internet case)

darcs-hash:20060105155913-34f17-128f2a243042af925504b89a45da001b8532e95c.gz
parent 1122a49f
This diff is collapsed.
......@@ -60,9 +60,10 @@ extern char const stun_version[]; /**< Name and version of STUN software */
/**
* States of the STUN client->server query process.
*/
typedef enum stun_states_e {
typedef enum stun_state_e {
stun_no_assigned_event,
stun_dispose_me,
/* TLS events */
stun_tls_connecting,
......@@ -72,6 +73,11 @@ typedef enum stun_states_e {
stun_tls_reading,
stun_tls_done,
/* STUN discovery events */
stun_discovery_init,
stun_discovery_processing,
stun_discovery_done,
/* STUN bind events */
stun_bind_init, /**< Initial state */
stun_bind_started, /**< Discovery process started */
......@@ -84,7 +90,7 @@ typedef enum stun_states_e {
stun_request_not_found, /**< Response without matching request */
/* STUN errors */
/* Do not change the order! */
/* Do not change the order! Errors need to be after stun_error */
stun_error,
stun_tls_connection_timeout,
......@@ -95,18 +101,20 @@ typedef enum stun_states_e {
stun_bind_error,
stun_bind_timeout,
} stun_states_t;
stun_discovery_timeout,
} stun_state_t;
typedef void (*stun_event_f)(stun_magic_t *magic,
stun_handle_t *se,
stun_request_t *req,
stun_states_t event);
stun_state_t event);
/* Return the socket associated with the stun_socket_t structure */
int stun_handle_get_bind_socket(stun_handle_t *se);
char const *stun_str_state(stun_states_t state);
char const *stun_str_state(stun_state_t state);
int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
......@@ -155,7 +163,7 @@ int stun_handle_set_uname_pwd(stun_handle_t *se,
const char *pwd,
int len_pwd);
char const *stun_nattype(stun_handle_t *se);
char const *stun_nattype(stun_request_t *req);
SOFIA_END_DECLS
......
......@@ -63,10 +63,13 @@ struct stunc_s {
};
void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_request_t *req, stun_states_t event)
void stunc_callback(stunc_t *stunc, stun_handle_t *en,
stun_request_t *req,
stun_state_t event)
{
su_localinfo_t *li = NULL;
char ipaddr[48];
char const *nattype;
SU_DEBUG_3(("%s: %s\n", __func__, stun_str_state(event)));
......@@ -75,6 +78,12 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_request_t *req, stun
su_root_break(stun_handle_root(en));
break;
case stun_discovery_done:
nattype = stun_nattype(req);
SU_DEBUG_3(("%s: NAT type: %s\n", __func__, nattype));
su_root_break(stun_handle_root(en));
break;
case stun_bind_done:
li = stun_request_get_localinfo(req);
inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)),
......
......@@ -69,7 +69,7 @@ static int torture_test_get_nattype(char *addr);
static int torture_test_get_lifetime(char *addr);
static void torture_callback(torture_t *torturer,
stun_handle_t *en,
stun_states_t event);
stun_state_t event);
static int test_deinit(void);
......@@ -169,7 +169,7 @@ int main(int argc, char *argv[])
}
void torture_callback(torture_t *torturer, stun_handle_t *en, stun_states_t ev)
void torture_callback(torture_t *torturer, stun_handle_t *en, stun_state_t ev)
{
char ipaddr[48];
int s = -1;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment