Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
BC
public
external
sofia-sip
Commits
883ff49c
Commit
883ff49c
authored
Jan 14, 2006
by
Martti Mela
Browse files
tport: new stun almost works
darcs-hash:20060114125835-1b897-e7727b4251c3005dd39e8efe3ae662a535524323.gz
parent
c060ebe8
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
38 additions
and
18 deletions
+38
-18
libsofia-sip-ua/stun/stun.c
libsofia-sip-ua/stun/stun.c
+15
-7
libsofia-sip-ua/tport/tport.c
libsofia-sip-ua/tport/tport.c
+23
-11
No files found.
libsofia-sip-ua/stun/stun.c
View file @
883ff49c
...
...
@@ -27,8 +27,8 @@
*
* See RFC 3489 for further information.
*
* @author Tat Chan <Tat.Chan@nokia.com>
* @author Martti Mela <Martti.Mela@nokia.com>
* @author Tat Chan <Tat.Chan@nokia.com>
* @author Pekka Pessi <Pekka.Pessi@nokia.com>
* @author Kai Vehmanen <Kai.Vehmanen@nokia.com>
*
...
...
@@ -596,11 +596,12 @@ void stun_handle_destroy(stun_handle_t *sh)
for
(
sd
=
sh
->
sh_discoveries
;
sd
;
)
{
kill
=
sd
;
sd
=
sd
->
sd_next
;
/* Index has same value as sockfd, right? */
su_root_deregister
(
sh
->
sh_root
,
sd
->
sd_socket
);
su_root_deregister
(
sh
->
sh_root
,
kill
->
sd_socket
);
if
(
sd
->
sd_action
==
stun_action_tls_query
)
su_close
(
sd
->
sd_socket
);
if
(
kill
->
sd_action
==
stun_action_tls_query
)
su_close
(
kill
->
sd_socket
);
stun_discovery_destroy
(
kill
);
}
...
...
@@ -663,7 +664,6 @@ static int get_localinfo(su_localinfo_t *clientinfo)
continue
;
clientinfo
->
li_family
=
li
->
li_family
;
clientinfo
->
li_addrlen
=
li
->
li_addrlen
;
sa
=
clientinfo
->
li_addr
;
memcpy
(
sa
,
li
->
li_addr
,
sizeof
(
su_addrinfo_t
));
...
...
@@ -771,7 +771,7 @@ int stun_handle_bind(stun_handle_t *sh,
clientinfo
->
li_addr
=
&
bind_addr
;
clientinfo
->
li_addrlen
=
bind_len
;
if
(
!
SU_HAS_INADDR_ANY
(
&
bind_addr
)
)
{
if
(
bind_addr
.
su_port
!=
0
)
{
/* already bound */
clientinfo
->
li_family
=
bind_addr
.
su_family
;
/* clientinfo->li_socktype = su_getsocktype(s); */
...
...
@@ -780,7 +780,15 @@ int stun_handle_bind(stun_handle_t *sh,
/* Not bound - bind it */
get_localinfo
(
clientinfo
);
if
(
bind
(
s
,
(
struct
sockaddr
*
)
&
clientinfo
->
li_addr
,
clientinfo
->
li_addrlen
)
<
0
)
{
if
(
bind_addr
.
su_family
==
AF_INET
)
clientinfo
->
li_addrlen
=
16
;
else
clientinfo
->
li_addrlen
=
32
;
clientinfo
->
li_addrlen
=
bind_len
;
if
(
err
=
bind
(
s
,
(
struct
sockaddr
*
)
&
clientinfo
->
li_addr
,
clientinfo
->
li_addrlen
)
<
0
)
{
STUN_ERROR
(
errno
,
bind
);
SU_DEBUG_3
((
"%s: Error binding to %s:%u
\n
"
,
__func__
,
inet_ntop
(
clientinfo
->
li_family
,
SU_ADDR
(
clientinfo
->
li_addr
),
ipaddr
,
sizeof
(
ipaddr
)),
...
...
libsofia-sip-ua/tport/tport.c
View file @
883ff49c
...
...
@@ -116,6 +116,7 @@ typedef struct _tls_t tls_t; /* dummy */
#if HAVE_SOFIA_STUN
#include "stun.h"
#include "stun_tag.h"
#endif
#if HAVE_UPNP
...
...
@@ -256,6 +257,7 @@ struct tport_s {
#if 0
stun_socket_t *tp_stun_socket;
#endif
su_socket_t
tp_stun_socket
;
#endif
/* ==== Receive queue ================================================== */
...
...
@@ -373,10 +375,12 @@ struct tport_master {
#if HAVE_UPNP
#endif
#if HAVE_SOFIA_STUN
tport_master_t
*
tport
;
char
*
stun_server
;
/* stun_socket_t *stun_socket; */
stun_handle_t
*
stun
;
su_socket_t
stun_socket
;
su_sockaddr_t
sockaddr
;
#endif
}
mr_nat
[
1
];
};
...
...
@@ -6855,22 +6859,27 @@ void tport_stun_cb(tport_master_t *mr, stun_handle_t *sh,
stun_action_t
action
,
stun_state_t
event
)
{
su_sockaddr_t
*
sa
=
NULL
;
char
ipaddr
[
SU_ADDRSIZE
+
2
]
=
{
0
};
SU_DEBUG_3
((
"%s: %s
\n
"
,
__func__
,
stun_str_state
(
event
)));
switch
(
action
)
{
case
stun_action_tls_query
:
mr
->
mr_stun_step_ready
=
0
;
mr
->
mr_stun_step_ready
=
1
;
break
;
case
stun_action_binding_request
:
if
(
event
!=
stun_bind_done
||
event
!=
stun_bind_timeout
)
break
;
sa
=
stun_discovery_get_address
(
sd
);
memcpy
(
&
mr
->
mr_nat
->
sockaddr
,
sa
,
sizeof
(
su_sockaddr_t
));
SU_DEBUG_0
((
"%s: local address NATed as %s:%u
\n
"
,
__func__
,
inet_ntop
(
sa
->
su_family
,
SU_ADDR
(
sa
),
ipaddr
,
sizeof
(
ipaddr
)),
(
unsigned
)
ntohs
(
sa
->
su_port
)));
mr
->
mr_stun_step_ready
=
0
;
mr
->
mr_stun_step_ready
=
1
;
break
;
default:
...
...
@@ -6902,15 +6911,17 @@ tport_nat_initialize_nat_traversal(tport_master_t *mr,
nat
->
external_ip_address
=
NULL
;
/* nat->stun_socket = NULL; */
nat
->
tport
=
mr
;
for
(
i
=
0
;
stun_transports
[
i
];
i
++
)
{
if
((
strcmp
(
tpn
->
tpn_proto
,
"*"
)
==
0
||
strcasecmp
(
tpn
->
tpn_proto
,
stun_transports
[
i
])
==
0
))
{
SU_DEBUG_5
((
"%s(%p) starting STUN engine
\n
"
,
__func__
,
mr
));
nat
->
stun
=
stun_handle_
t
create
(
mr
,
mr
->
mr_root
,
tport_stun_cb
,
TAG_NEXT
(
tags
));
nat
->
stun
=
stun_handle_create
(
mr
,
mr
->
mr_root
,
tport_stun_cb
,
TAG_NEXT
(
tags
));
if
(
!
nat
->
stun
)
return
NULL
;
...
...
@@ -6923,7 +6934,7 @@ tport_nat_initialize_nat_traversal(tport_master_t *mr,
/* Change me in tport_stun_cb() */
mr
->
mr_stun_step_ready
=
0
;
while
(
mr
->
mr_stun_step_ready
!=
1
)
{
su_root_step
(
mr
->
mr_root
);
su_root_step
(
mr
->
mr_root
,
1000
);
}
nat
->
try_stun
=
1
;
...
...
@@ -6979,11 +6990,12 @@ int tport_nat_stun_bind(struct tport_nat_s *nat,
socklen_t
*
sulen
,
su_socket_t
s
)
{
int
nat_bound
=
0
,
lifetime
=
0
,
bind_res
=
0
;
int
nat_bound
=
0
;
/* nat->stun_socket = stun_socket_create(nat->stun, s); */
tport_master_t
*
mr
=
nat
->
tport
;
nat
->
stun_socket
=
s
;
if
(
stun_handle_bind
(
sh
,
STUNTAG_SOCKET
(
s
),
TAG_NULL
())
<
0
)
{
if
(
stun_handle_bind
(
nat
->
stun
,
STUNTAG_SOCKET
(
s
),
TAG_NULL
())
<
0
)
{
SU_DEBUG_9
((
"%s: %s failed.
\n
"
,
__func__
,
"stun_handle_bind()"
));
return
nat_bound
;
}
...
...
@@ -6991,12 +7003,12 @@ int tport_nat_stun_bind(struct tport_nat_s *nat,
/* Change me in tport_stun_cb() */
mr
->
mr_stun_step_ready
=
0
;
while
(
mr
->
mr_stun_step_ready
!=
1
)
{
su_root_step
(
mr
->
mr_root
);
su_root_step
(
mr
->
mr_root
,
1000
);
}
SU_DEBUG_9
((
"%s: stun_bind() ok
\n
"
,
__func__
));
memcpy
(
su
,
stun_discovery_get_address
(
sd
)
,
sizeof
(
su
));
memcpy
(
su
,
&
nat
->
sockaddr
,
sizeof
(
su
));
nat
->
stun_enabled
=
1
;
nat_bound
=
1
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment