Commit 9fa54e4f authored by Martti Mela's avatar Martti Mela

async stunning contd. Juhui!

darcs-hash:20051209171833-1b897-b8b865a4965669194ad99aa8062ab107014e5d7e.gz
parent 5c534998
......@@ -52,24 +52,12 @@
#include <su.h>
#include <su_localinfo.h>
#ifndef SU_DEBUG
#define SU_DEBUG 3
#endif
#define SU_LOG (stun_log)
#include <su_debug.h>
#include <openssl/opensslv.h>
extern char const STUN_DEBUG[]; /* dummy declaration for Doxygen */
/** STUN log. */
su_log_t stun_log[] = { SU_LOG_INIT("stun", "STUN_DEBUG", SU_DEBUG) };
#define STUN_ERROR(errno, what) \
{ int err = errno; \
SU_DEBUG_5(("%s: %s: %s\n", __func__, #what, su_strerror(err))); \
}
char const stun_nat_unknown[] = "NAT type undetermined",
stun_open_internet[] = "Open Internet",
stun_udp_blocked[] = "UDP traffic is blocked, or Server unreachable",
......@@ -394,7 +382,7 @@ int stun_bind(stun_socket_t *ss,
if (li->li_family == AF_INET) {
char ipaddr[SU_ADDRSIZE + 2];
memcpy(clnt_addr, li, sizeof(clnt_addr));
clnt_addr = li;
inet_ntop(clnt_addr->li_family, SU_ADDR(clnt_addr->li_addr), ipaddr, sizeof(ipaddr));
SU_DEBUG_3(("stun: local address found to be %s:%u\n",
ipaddr,
......@@ -422,16 +410,22 @@ int stun_bind(stun_socket_t *ss,
sockfd = ss->ss_sockfd;
inet_ntop(clnt_addr->li_family, SU_ADDR(clnt_addr->li_addr), ipaddr, sizeof(ipaddr));
if (bind(sockfd, (struct sockaddr *)clnt_addr, my_addr->li_addrlen) < 0) {
if (bind(sockfd, (struct sockaddr *) clnt_addr->li_addr, my_addr->li_addrlen) < 0) {
SU_DEBUG_3(("stun: Error binding to %s:%u\n", ipaddr,
(unsigned) ntohs(clnt_addr->li_addr->su_port)));
return -1;
}
bind_len = sizeof(bind_addr);
getsockname(sockfd, (struct sockaddr *) &bind_addr.li_addr, &bind_len);
bind_len = sizeof(bind_addr.li_addr);
memcpy(&bind_addr, clnt_addr, sizeof(bind_addr));
if (getsockname(sockfd, (struct sockaddr *) &bind_addr.li_addr, &bind_len) != 0) {
STUN_ERROR(errno, getsockname);
return -1;
}
inet_ntop(clnt_addr->li_family, SU_ADDR(bind_addr.li_addr), ipaddr, sizeof(ipaddr));
inet_ntop(clnt_addr->li_family, (struct sockaddr *) &bind_addr.li_addr, ipaddr, sizeof(ipaddr));
#if 0 /* xxx mela */
SU_DEBUG_3(("stun: Local socket bound to: %s:%u\n", ipaddr,
(unsigned) ntohs(bind_addr.li_addr.su_port)));
......@@ -1002,13 +996,13 @@ int stun_bind_test(stun_socket_t *ss,
ss->ss_state = stun_cstate_init;
if (ss == NULL || srvr_addr == NULL || clnt_addr == NULL)
if (ss == NULL || srvr_addr->li_addr == NULL || clnt_addr == NULL)
return errno = EFAULT, retval;
/* run protocol here... */
s = ss->ss_sockfd;
inet_ntop(srvr_addr->li_family, SU_ADDR(srvr_addr->li_addr), ipaddr, sizeof(ipaddr));
inet_ntop(srvr_addr->li_family, srvr_addr->li_addr, ipaddr, sizeof(ipaddr));
#if 0 /* xxx mela */
SU_DEBUG_3(("stun: sending to %s:%u (req-flags: msgint=%d, ch-addr=%d, chh-port=%d)\n",
ipaddr, ntohs(srvr_addr->li_addr.su_port),
......
......@@ -51,8 +51,10 @@
#define SU_LOG (stun_log)
#include <su_debug.h>
#include "stun_internal.h"
#include "stun_common.h"
const char stun_400_Bad_request[] = "Bad Request",
stun_401_Unauthorized[] = "Unauthorized",
stun_420_Unknown_attribute[] = "Unknown Attribute",
......@@ -542,22 +544,25 @@ int stun_free_message(stun_msg_t *msg) {
int stun_send_message(int sockfd, su_localinfo_t *to_addr, stun_msg_t *msg, stun_buffer_t *pwd)
{
int z;
int err = -1;
char ipaddr[SU_ADDRSIZE + 2];
stun_encode_message(msg, pwd);
z = sendto(sockfd, msg->enc_buf.data, msg->enc_buf.size,
err = sendto(sockfd, msg->enc_buf.data, msg->enc_buf.size,
0, (struct sockaddr *) &to_addr->li_addr, sizeof(*to_addr));
if (err != 0)
STUN_ERROR(err, sendto);
inet_ntop(to_addr->li_family, SU_ADDR(to_addr->li_addr), ipaddr, sizeof(ipaddr));
inet_ntop(to_addr->li_family, to_addr->li_addr, ipaddr, sizeof(ipaddr));
#if 0 /* xxx mela */
SU_DEBUG_5(("stun: message sent to %s:%u\n",
ipaddr, ntohs(to_addr->su_port)));
#endif
debug_print(&msg->enc_buf);
return z;
return err;
}
/** send a STUN message.
......
......@@ -34,19 +34,34 @@
#ifndef SU_WAIT_H
#include <su_wait.h>
#endif
#ifndef SU_TAG_H
#include <su_tag.h>
#endif
#include "stun_common.h"
#ifndef STUN_H
#include "stun.h"
#endif
#ifndef SU_DEBUG
#define SU_DEBUG 3
#endif
#define SU_LOG (stun_log)
#include <su_debug.h>
extern char const STUN_DEBUG[]; /* dummy declaration for Doxygen */
#define STUN_LIFETIME_EST 350 /**< 6 min? */
#define STUN_LIFETIME_MAX 1800 /**< 30 min? */
#define STUN_LIFETIME_CI 5 /**< 5 sec confidence interval */
#define STUN_ERROR(errno, what) \
{ int err = errno; \
SU_DEBUG_5(("%s: %s: %s\n", __func__, #what, su_strerror(err))); \
}
int stun_is_requested(tag_type_t tag, tag_value_t value, ...);
int stun_poll(stun_socket_t *ss);
......
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