Commit d31fbd90 authored by Kai Vehmanen's avatar Kai Vehmanen

Fixed STUN bugs when build with VC6/win32.

darcs-hash:20060508101151-77cd4-306485ed7e3ad7da7f9dd8ffa9fee088fcb6304d.gz
parent d24ab6df
......@@ -790,11 +790,9 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int reg_socket)
SU_DEBUG_7(("%s: socket registered.\n", __func__));
bind_len = sizeof bind_addr;
sa = (void *) &bind_addr;
bind_len = sizeof bind_addr;
memset(sa, 0, sizeof(bind_addr));
bind_len = SU_SOCKADDR_SIZE(sa);
memset(sa, 0, bind_len);
/* if bound check the error */
err = getsockname(s, (struct sockaddr *) sa, &bind_len);
if (err < 0 && errno == SOCKET_ERROR) {
......@@ -808,6 +806,8 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int reg_socket)
get_localinfo(clientinfo);
#endif
sa->su_family = AF_INET;
if ((err = bind(s, (struct sockaddr *) sa, bind_len)) < 0) {
STUN_ERROR(errno, bind);
SU_DEBUG_3(("%s: Error binding to %s:%u\n", __func__,
......@@ -2222,15 +2222,22 @@ static int action_determine_nattype(stun_request_t *req, stun_msg_t *binding_res
sd->sd_fourth = 2; /* request, -1, 0, 1 reserved for results */
req->sr_state = stun_req_dispose_me;
req = stun_request_create(sd);
if (stun_make_binding_req(sh, req, req->sr_msg,
STUNTAG_CHANGE_IP(0),
STUNTAG_CHANGE_PORT(0),
TAG_END()) < 0)
return -1;
err = stun_make_binding_req(sh, req, req->sr_msg,
STUNTAG_CHANGE_IP(0),
STUNTAG_CHANGE_PORT(0),
TAG_END());
if (err == 0) {
err = stun_send_binding_request(req, sd->sd_sec_addr);
}
err = stun_send_binding_request(req, sd->sd_sec_addr);
if (err < 0) {
SU_DEBUG_0(("WARNING: Failure in performing STUN Test-IV check. "
"The results related to mapping characteristics may be incorrect."));
stun_free_message(req->sr_msg);
sd->sd_fourth = -1;
/* call function again, sd_fourth stops the recursion */
action_determine_nattype(req, binding_response);
return -1;
}
......
......@@ -278,10 +278,15 @@ int main(int argc, char *argv[])
{
int err = 0, i, sflags = 0;
stunc_t stunc[1];
su_root_t *root = su_root_create(stunc);
su_root_t *root;
stun_handle_t *sh;
su_socket_t s;
if (su_init() != 0)
return -1;
root = su_root_create(stunc);
if (argc < 3)
usage(argv[0]);
......@@ -313,7 +318,7 @@ int main(int argc, char *argv[])
return -1;
}
s = su_socket(AF_INET, SOCK_DGRAM, 0);
s = su_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (s == -1) {
SU_DEBUG_0(("%s: %s failed: %s\n", __func__,
"su_socket()", su_gli_strerror(errno)));
......@@ -328,16 +333,17 @@ int main(int argc, char *argv[])
char ipaddr[SU_ADDRSIZE + 2] = { 0 };
socklen_t socklen = sizeof(sockaddr);
memset(&sockaddr, 0, sizeof(su_sockaddr_t));
srand((unsigned int)time((time_t *)NULL));
memset(&sockaddr, 0, sizeof(su_sockaddr_t));
sockaddr.su_port = htons((rand() % (65536 - 1024)) + 1024);
sockaddr.su_family = AF_INET;
SU_DEBUG_3(("stunc: Binding to local port %u.\n", ntohs(sockaddr.su_port)));
err = bind(s, (struct sockaddr *)&sockaddr, socklen);
if (err) {
SU_DEBUG_1(("%s: Error binding to %s:%u\n", __func__,
if (err < 0) {
SU_DEBUG_1(("%s: Error %d binding to %s:%u\n", __func__, err,
inet_ntop(sockaddr.su_family, SU_ADDR(&sockaddr),
ipaddr, sizeof(ipaddr)),
(unsigned) ntohs(sockaddr.su_port)));
......
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