Commit 0d764b58 authored by Martti Mela's avatar Martti Mela

first working version of STUN transaction engine

darcs-hash:20051226133201-1b897-5d8f4bc1eaaed11013786363f58e5556eaae3cf6.gz
parent 43cfda9d
This diff is collapsed.
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
/**@file stun.h STUN client interface /**@file stun.h STUN client interface
* *
* @author Tat Chan <Tat.Chan@nokia.com> * @author Tat Chan <Tat.Chan@nokia.com>
* @author Martti Mela <Martti.Mela@nokia.com>
* @author Pekka Pessi <Pekka.Pessi@nokia.com> * @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Kai Vehmanen <kai.vehmanen@nokia.com> * @author Kai Vehmanen <kai.vehmanen@nokia.com>
*/ */
...@@ -41,8 +42,9 @@ ...@@ -41,8 +42,9 @@
#include <su_localinfo.h> #include <su_localinfo.h>
typedef struct stun_handle_s stun_handle_t; typedef struct stun_handle_s stun_handle_t;
typedef struct stun_socket_s stun_socket_t; typedef struct stun_socket_s stun_socket_t;
typedef struct stun_request_s stun_request_t;
#ifndef STUN_MAGIC_T #ifndef STUN_MAGIC_T
#define STUN_MAGIC_T struct stun_magic_t #define STUN_MAGIC_T struct stun_magic_t
...@@ -92,6 +94,7 @@ typedef enum stun_states_e { ...@@ -92,6 +94,7 @@ typedef enum stun_states_e {
typedef void (*stun_event_f)(stun_magic_t *magic, typedef void (*stun_event_f)(stun_magic_t *magic,
stun_handle_t *se, stun_handle_t *se,
stun_request_t *req,
stun_states_t event); stun_states_t event);
/* Return the socket associated with the stun_socket_t structure */ /* Return the socket associated with the stun_socket_t structure */
...@@ -124,7 +127,9 @@ int stun_handle_set_bind_socket(stun_handle_t *se, int sockfd); ...@@ -124,7 +127,9 @@ int stun_handle_set_bind_socket(stun_handle_t *se, int sockfd);
/** Bind a socket using STUN. */ /** Bind a socket using STUN. */
int stun_handle_bind(stun_handle_t *se, int stun_handle_bind(stun_handle_t *se,
/* su_localinfo_t *my_addr, */ /* su_localinfo_t *my_addr, */
int *return_lifetime); int *return_lifetime,
tag_type_t tag, tag_value_t value,
...);
su_localinfo_t *stun_handle_get_local_addr(stun_handle_t *en); su_localinfo_t *stun_handle_get_local_addr(stun_handle_t *en);
......
...@@ -76,12 +76,8 @@ int stun_set_uname_pwd(stun_handle_t *se, const char *uname, int len_uname, ...@@ -76,12 +76,8 @@ 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_binding_request(stun_handle_t *se, int stun_send_message(su_socket_t ss, su_sockaddr_t *srvr, stun_msg_t *msg, stun_buffer_t *pwd);
su_sockaddr_t *srvr_addr,
/* su_localinfo_t *clnt_addr, */
int chg_ip,
int chg_port);
int stun_send_message(su_socket_t ss, su_sockaddr_t *srvr, stun_msg_t *msg, stun_buffer_t *pwd); /* client version */
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_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);
......
...@@ -64,7 +64,7 @@ struct stunc_s { ...@@ -64,7 +64,7 @@ struct stunc_s {
}; };
void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_states_t event) void stunc_callback(stunc_t *stunc, stun_handle_t *en, stun_request_t *req, stun_states_t event)
{ {
su_localinfo_t *li = NULL; su_localinfo_t *li = NULL;
char ipaddr[48]; char ipaddr[48];
...@@ -145,15 +145,15 @@ int main(int argc, char *argv[]) ...@@ -145,15 +145,15 @@ int main(int argc, char *argv[])
} }
#if 0
if (stun_handle_set_bind_socket(se, s) < 0) { if (stun_handle_set_bind_socket(se, s) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_set_bind_socket()")); SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_set_bind_socket()"));
return -1; return -1;
} }
#endif
lifetime = 0; lifetime = 0;
if (stun_handle_bind(se, &lifetime) < 0) { if (stun_handle_bind(se, &lifetime, STUNTAG_SOCKET(s), TAG_NULL()) < 0) {
SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_bind()")); SU_DEBUG_3(("%s: %s failed\n", __func__, "stun_handle_bind()"));
return -1; return -1;
} }
......
...@@ -237,7 +237,7 @@ int torture_test_stun_bind(char *localaddr) ...@@ -237,7 +237,7 @@ int torture_test_stun_bind(char *localaddr)
s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1); s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1);
result = stun_handle_set_bind_socket(se, s); /* result = stun_handle_set_bind_socket(se, s); */
TEST_1(result != -1); TEST_1(result != -1);
/* test message integrity? */ /* test message integrity? */
...@@ -257,7 +257,7 @@ int torture_test_stun_bind(char *localaddr) ...@@ -257,7 +257,7 @@ int torture_test_stun_bind(char *localaddr)
lifetime = 0; lifetime = 0;
result = stun_handle_bind(se, &lifetime); TEST(result, 0); result = stun_handle_bind(se, &lifetime, STUNTAG_SOCKET(s), TAG_NULL()); TEST(result, 0);
END(); END();
} }
...@@ -273,7 +273,6 @@ int torture_test_get_lifetime(char *localaddr) ...@@ -273,7 +273,6 @@ int torture_test_get_lifetime(char *localaddr)
s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1); s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1);
result = stun_handle_set_bind_socket(se, s);
TEST_1(result != -1); TEST_1(result != -1);
/* test message integrity? */ /* test message integrity? */
...@@ -318,7 +317,7 @@ int torture_test_get_nattype(char *localaddr) ...@@ -318,7 +317,7 @@ int torture_test_get_nattype(char *localaddr)
s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1); s = socket(AF_INET, SOCK_DGRAM, 0); TEST_1(s != -1);
result = stun_handle_set_bind_socket(se, s); /* result = stun_handle_set_bind_socket(se, s); */
TEST_1(result != -1); TEST_1(result != -1);
/* test message integrity? */ /* test message integrity? */
...@@ -343,8 +342,10 @@ int torture_test_get_nattype(char *localaddr) ...@@ -343,8 +342,10 @@ int torture_test_get_nattype(char *localaddr)
atonetaddr(my_addr, localaddr); atonetaddr(my_addr, localaddr);
addrlen = sizeof(*my_addr); addrlen = sizeof(*my_addr);
#if 0
result = stun_handle_get_nattype(se, /* &addr.su_sa, */ &addrlen); TEST(result, 0); result = stun_handle_get_nattype(se, /* &addr.su_sa, */ &addrlen); TEST(result, 0);
printf("NAT type is: %s\n", stun_nattype(se)); printf("NAT type is: %s\n", stun_nattype(se));
#endif
su_close(s); su_close(s);
......
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