Commit 52f45446 authored by Martti Mela's avatar Martti Mela

stun: get_nattype works partially

At least OPEN Internet case is now handled properly. More modifications to follow.

darcs-hash:20060104131334-34f17-01293336fe6de3f504754f60af1d5b2c231b6429.gz
parent 3a923186
This diff is collapsed.
...@@ -61,6 +61,8 @@ extern char const stun_version[]; /**< Name and version of STUN software */ ...@@ -61,6 +61,8 @@ extern char const stun_version[]; /**< Name and version of STUN software */
* States of the STUN client->server query process. * States of the STUN client->server query process.
*/ */
typedef enum stun_states_e { typedef enum stun_states_e {
stun_no_assigned_event,
/* TLS events */ /* TLS events */
stun_tls_connecting, stun_tls_connecting,
...@@ -79,6 +81,8 @@ typedef enum stun_states_e { ...@@ -79,6 +81,8 @@ typedef enum stun_states_e {
stun_bind_processing, /**< Processing server reply */ stun_bind_processing, /**< Processing server reply */
stun_bind_done, /**< Initial state */ stun_bind_done, /**< Initial state */
stun_request_not_found, /**< Response without matching request */
/* STUN errors */ /* STUN errors */
/* Do not change the order! */ /* Do not change the order! */
...@@ -133,11 +137,11 @@ int stun_handle_bind(stun_handle_t *se, ...@@ -133,11 +137,11 @@ int stun_handle_bind(stun_handle_t *se,
tag_type_t tag, tag_value_t value, tag_type_t tag, tag_value_t value,
...); ...);
su_localinfo_t *stun_handle_get_local_addr(stun_handle_t *en); su_localinfo_t *stun_request_get_localinfo(stun_request_t *req);
int stun_handle_get_nattype(stun_handle_t *se, int stun_handle_get_nattype(stun_handle_t *se,
/* su_localinfo_t *my_addr, */ tag_type_t tag, tag_value_t value,
int *addrlen); ...);
int stun_handle_get_lifetime(stun_handle_t *se, int stun_handle_get_lifetime(stun_handle_t *se,
su_localinfo_t *my_addr, su_localinfo_t *my_addr,
......
...@@ -104,16 +104,6 @@ SOFIA_BEGIN_DECLS ...@@ -104,16 +104,6 @@ SOFIA_BEGIN_DECLS
#define RAND_MAX_16 65535 #define RAND_MAX_16 65535
/* NAT TYPES */
#define STUN_NAT_UNKNOWN 0
#define STUN_OPEN_INTERNET 1
#define STUN_UDP_BLOCKED 2
#define STUN_SYM_UDP_FW 3
#define STUN_NAT_FULL_CONE 4
#define STUN_NAT_SYM 5
#define STUN_NAT_RES_CONE 6
#define STUN_NAT_PORT_RES_CONE 7
/* other protocol specific parameters */ /* other protocol specific parameters */
#define STUN_MAX_RETRX 5 /* should be 8? */ #define STUN_MAX_RETRX 5 /* should be 8? */
#define STUN_MAX_RETRX_INT 1600 /**< max retrx interval in #define STUN_MAX_RETRX_INT 1600 /**< max retrx interval in
......
...@@ -78,9 +78,11 @@ int stun_set_uname_pwd(stun_handle_t *se, const char *uname, int len_uname, ...@@ -78,9 +78,11 @@ int stun_set_uname_pwd(stun_handle_t *se, const char *uname, int len_uname,
/* internal functions declaration */ /* internal functions declaration */
int stun_make_sharedsecret_req(stun_msg_t *msg); int stun_make_sharedsecret_req(stun_msg_t *msg);
int stun_send_message(su_socket_t ss, su_sockaddr_t *srvr, stun_msg_t *msg, stun_buffer_t *pwd); int stun_send_message(su_socket_t ss, su_sockaddr_t *srvr,
stun_msg_t *msg, stun_buffer_t *pwd);
int stun_make_binding_req(stun_handle_t *se, stun_msg_t *msg, int chg_ip, int chg_port); int stun_make_binding_req(stun_handle_t *se, stun_request_t *req,
stun_msg_t *msg, int chg_ip, int chg_port);
int stun_process_response(stun_msg_t *msg); int stun_process_response(stun_msg_t *msg);
int stun_process_binding_response(stun_msg_t *msg); int stun_process_binding_response(stun_msg_t *msg);
......
...@@ -90,3 +90,20 @@ tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(srtp_integrity); ...@@ -90,3 +90,20 @@ tag_typedef_t stuntag_integrity = BOOLTAG_TYPEDEF(srtp_integrity);
* Corresponding tag taking reference parameter is STUNTAG_SOCKET_REF() * Corresponding tag taking reference parameter is STUNTAG_SOCKET_REF()
*/ */
tag_typedef_t stuntag_socket = INTTAG_TYPEDEF(socket); tag_typedef_t stuntag_socket = INTTAG_TYPEDEF(socket);
/**@def STUNTAG_ACTION(x)
*
* Command action for STUN request.
*
* @par Used with
* stun_handle_bind() \n
*
* @par Parameter type
* int (stun_action_t)
*
* @par Values
* See types for stun_action_t in stun.h
*
* Corresponding tag taking reference parameter is STUNTAG_ACTION_REF()
*/
tag_typedef_t stuntag_action = INTTAG_TYPEDEF(action);
...@@ -52,6 +52,11 @@ extern tag_typedef_t stuntag_socket; ...@@ -52,6 +52,11 @@ extern tag_typedef_t stuntag_socket;
#define STUNTAG_SOCKET_REF(x) stuntag_socket_ref, tag_int_vr(&(x)) #define STUNTAG_SOCKET_REF(x) stuntag_socket_ref, tag_int_vr(&(x))
extern tag_typedef_t stuntag_socket_ref; extern tag_typedef_t stuntag_socket_ref;
#define STUNTAG_ACTION(x) stuntag_action, tag_int_v(x)
extern tag_typedef_t stuntag_action;
#define STUNTAG_ACTION_REF(x) stuntag_action_ref, tag_int_vr(&(x))
extern tag_typedef_t stuntag_action_ref;
SOFIA_END_DECLS SOFIA_END_DECLS
#endif /* STUN_TAG_H */ #endif /* STUN_TAG_H */
...@@ -76,7 +76,7 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_request_t *req, stun ...@@ -76,7 +76,7 @@ void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_request_t *req, stun
break; break;
case stun_bind_done: case stun_bind_done:
li = stun_handle_get_local_addr(en); li = stun_request_get_localinfo(req);
inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)), inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)),
SU_DEBUG_3(("%s: local address NATed as %s:%u\n", __func__, SU_DEBUG_3(("%s: local address NATed as %s:%u\n", __func__,
ipaddr, (unsigned) ntohs(li->li_addr->su_port))); ipaddr, (unsigned) ntohs(li->li_addr->su_port)));
...@@ -159,6 +159,13 @@ int main(int argc, char *argv[]) ...@@ -159,6 +159,13 @@ int main(int argc, char *argv[])
su_root_run(root); su_root_run(root);
if (stun_handle_get_nattype(se, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_get_nattype()"));
return -1;
}
su_root_run(root);
stun_handle_destroy(se); stun_handle_destroy(se);
return 0; return 0;
......
...@@ -178,7 +178,7 @@ void torture_callback(torture_t *torturer, stun_handle_t *en, stun_states_t ev) ...@@ -178,7 +178,7 @@ void torture_callback(torture_t *torturer, stun_handle_t *en, stun_states_t ev)
SU_DEBUG_3(("%s: called by event \"%s\"\n", __func__, stun_str_state(ev))); SU_DEBUG_3(("%s: called by event \"%s\"\n", __func__, stun_str_state(ev)));
if (ev == stun_bind_done) { if (ev == stun_bind_done) {
li = stun_handle_get_local_addr(en); li = stun_request_get_localinfo(en);
s = stun_handle_get_bind_socket(en); s = stun_handle_get_bind_socket(en);
inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)), inet_ntop(li->li_family, SU_ADDR(li->li_addr), ipaddr, sizeof(ipaddr)),
......
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