prepend su_ to inet_ntop and inet_pton replacement functions to work around problematic msvc 9 headers

git-svn-id: http://svn.freeswitch.org/svn/freeswitch/trunk@6632 d0543943-73ff-0310-b7d9-9358b9ac24b2
This commit is contained in:
Michael Jerris 2007-12-11 10:45:05 +00:00
parent ed82dd79bc
commit 4a059f764a
13 changed files with 48 additions and 42 deletions

View File

@ -849,7 +849,7 @@ static size_t convert_ip_address(char const *s,
len = span_ip6_address(s);
if (len) {
if (s[len] == '\0' && inet_pton(AF_INET6, s, addr) == 1) {
if (s[len] == '\0' && su_inet_pton(AF_INET6, s, addr) == 1) {
if (SU_IN6_IS_ADDR_V4MAPPED(addr) ||
SU_IN6_IS_ADDR_V4COMPAT(addr)) {
memcpy(addr, addr + 12, 4);
@ -868,7 +868,7 @@ static size_t convert_ip_address(char const *s,
s = memcpy(tmp, s, len + 1);
scan_ip4_address(&tmp);
}
if (s[len] == '\0' && inet_pton(AF_INET, s, addr) == 1)
if (s[len] == '\0' && su_inet_pton(AF_INET, s, addr) == 1)
return (void)(*return_addrlen = 4), len;
}

View File

@ -1795,7 +1795,7 @@ int agent_init_via(nta_agent_t *self, tport_t *primaries, int use_maddr)
int port;
if (su) {
inet_ntop(su->su_family, SU_ADDR(su), host, sizeof host);
su_inet_ntop(su->su_family, SU_ADDR(su), host, sizeof host);
maddr = use_maddr && strcasecmp(canon, host) != 0;
port = ntohs(su->su_port);
}
@ -7524,7 +7524,7 @@ outgoing_print_tport_error(nta_outgoing_t *orq, int level, char *todo,
orq->orq_method_name, orq->orq_cseq->cs_seq,
todo, su_strerror(error), error,
tpn->tpn_proto,
inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
su_inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
htons(su->su_port));
}
@ -9582,7 +9582,7 @@ void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q,
aaaa->aaaa_record->r_type != sres_type_aaaa)
continue; /* There was an error */
inet_ntop(AF_INET6, &aaaa->aaaa_addr, addr, sizeof(addr));
su_inet_ntop(AF_INET6, &aaaa->aaaa_addr, addr, sizeof(addr));
if (j == 0)
SU_DEBUG_5(("nta(%p): %s IN AAAA %s\n", (void *)orq,
@ -9665,7 +9665,7 @@ void outgoing_answer_a(sres_context_t *orq, sres_query_t *q,
a->a_record->r_type != sres_type_a)
continue; /* There was an error */
inet_ntop(AF_INET, &a->a_addr, addr, sizeof(addr));
su_inet_ntop(AF_INET, &a->a_addr, addr, sizeof(addr));
if (j == 0)
SU_DEBUG_5(("nta: %s IN A %s\n", a->a_record->r_name, addr));

View File

@ -1075,7 +1075,7 @@ void hc_tport_error(nth_engine_t * he, nth_client_t * hc,
hc->hc_method_name,
errmsg, error,
tpn->tpn_proto,
inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
su_inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
htons(su->su_port));
he->he_stats->st_tp_errors++;

View File

@ -166,10 +166,14 @@ struct sockaddr_storage {
#define SRES_TIME_MAX ((time_t)LONG_MAX)
#if !HAVE_INET_PTON
int inet_pton(int af, char const *src, void *dst);
int su_inet_pton(int af, char const *src, void *dst);
#else
#define su_inet_pton inet_pton
#endif
#if !HAVE_INET_NTOP
const char *inet_ntop(int af, void const *src, char *dst, size_t size);
const char *su_inet_ntop(int af, void const *src, char *dst, size_t size);
#else
#define su_inet_ntop inet_ntop
#endif
#if defined(va_copy)
@ -2374,14 +2378,14 @@ int sres_parse_nameserver(sres_config_t *c, char const *server)
if (strchr(server, ':')) {
struct sockaddr_in6 *sin6 = (struct sockaddr_in6 *)sa;
memset(sa, 0, ns->ns_addrlen = sizeof *sin6);
err = inet_pton(sa->sa_family = AF_INET6, server, &sin6->sin6_addr);
err = su_inet_pton(sa->sa_family = AF_INET6, server, &sin6->sin6_addr);
}
else
#endif
{
struct sockaddr_in *sin = (struct sockaddr_in *)sa;
memset(sa, 0, ns->ns_addrlen = sizeof *sin);
err = inet_pton(sa->sa_family = AF_INET, server, &sin->sin_addr);
err = su_inet_pton(sa->sa_family = AF_INET, server, &sin->sin_addr);
}
if (err <= 0) {
@ -2469,7 +2473,7 @@ sres_server_t **sres_servers_new(sres_resolver_t *res,
dns->dns_socket = INVALID_SOCKET;
ns = c->c_nameservers[i];
memcpy(dns->dns_addr, ns->ns_addr, dns->dns_addrlen = ns->ns_addrlen);
inet_ntop(dns->dns_addr->ss_family, SS_ADDR(dns->dns_addr),
su_inet_ntop(dns->dns_addr->ss_family, SS_ADDR(dns->dns_addr),
dns->dns_name, sizeof dns->dns_name);
dns->dns_edns = c->c_opt.edns;
servers[i] = dns++;
@ -2554,12 +2558,12 @@ sres_socket_t sres_server_socket(sres_resolver_t *res, sres_server_t *dns)
if (family == AF_INET) {
void *addr = &((struct sockaddr_in *)dns->dns_addr)->sin_addr;
inet_ntop(family, addr, ipaddr, sizeof ipaddr);
su_inet_ntop(family, addr, ipaddr, sizeof ipaddr);
}
#if HAVE_SIN6
else if (family == AF_INET6) {
void *addr = &((struct sockaddr_in6 *)dns->dns_addr)->sin6_addr;
inet_ntop(family, addr, ipaddr, sizeof ipaddr);
su_inet_ntop(family, addr, ipaddr, sizeof ipaddr);
lb = "[", rb = "]";
}
#endif
@ -3168,7 +3172,7 @@ int sres_resolver_error(sres_resolver_t *res, int socket)
snprintf(info + strlen(info), sizeof(info) - strlen(info),
" reported by ");
inet_ntop(from->ss_family, SS_ADDR(from),
su_inet_ntop(from->ss_family, SS_ADDR(from),
info + strlen(info), sizeof(info) - strlen(info));
}
@ -3232,13 +3236,13 @@ sres_resolver_report_error(sres_resolver_t *res,
if (remote->ss_family == AF_INET) {
struct sockaddr_in const *sin = (struct sockaddr_in *)remote;
uint8_t const *in_addr = (uint8_t*)&sin->sin_addr;
inet_ntop(AF_INET, in_addr, buf, sizeof(buf));
su_inet_ntop(AF_INET, in_addr, buf, sizeof(buf));
}
#if HAVE_SIN6
else if (remote->ss_family == AF_INET6) {
struct sockaddr_in6 const *sin6 = (struct sockaddr_in6 *)remote;
uint8_t const *in_addr = (uint8_t*)&sin6->sin6_addr;
inet_ntop(AF_INET6, in_addr, buf, sizeof(buf));
su_inet_ntop(AF_INET6, in_addr, buf, sizeof(buf));
}
#endif
}
@ -3365,12 +3369,12 @@ void sres_log_response(sres_resolver_t const *res,
;
else if (from->ss_family == AF_INET) {
struct sockaddr_in const *sin = (void *)from;
inet_ntop(AF_INET, &sin->sin_addr, host, sizeof host);
su_inet_ntop(AF_INET, &sin->sin_addr, host, sizeof host);
}
#if HAVE_SIN6
else if (from->ss_family == AF_INET6) {
struct sockaddr_in6 const *sin6 = (void *)from;
inet_ntop(AF_INET6, &sin6->sin6_addr, host, sizeof host);
su_inet_ntop(AF_INET6, &sin6->sin6_addr, host, sizeof host);
}
#endif

View File

@ -803,7 +803,7 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket)
if ((err = bind(s, &su->su_sa, sulen)) < 0) {
SU_DEBUG_3(("%s: bind(%s:%u): %s\n", __func__,
inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
su_inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
(unsigned) ntohs(su->su_port),
su_strerror(su_errno())));
return -1;
@ -817,7 +817,7 @@ int assign_socket(stun_discovery_t *sd, su_socket_t s, int register_socket)
memcpy(&sd->sd_bind_addr, su, sulen);
SU_DEBUG_3(("%s: local socket is bound to %s:%u\n", __func__,
inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
su_inet_ntop(su->su_family, SU_ADDR(su), addr, sizeof(addr)),
(unsigned) ntohs(su->su_port)));
events = SU_WAIT_IN | SU_WAIT_ERR;
@ -864,7 +864,7 @@ static int get_localinfo(int family, su_sockaddr_t *su, socklen_t *return_len)
memcpy(su, li->li_addr, *return_len = li->li_addrlen);
SU_DEBUG_3(("%s: using local address %s\n", __func__,
inet_ntop(family, SU_ADDR(su), addr, sizeof(addr))));
su_inet_ntop(family, SU_ADDR(su), addr, sizeof(addr))));
break;
}
@ -1693,7 +1693,7 @@ static int stun_bind_callback(stun_magic_t *m, su_wait_t *w, su_wakeup_arg_t *ar
SU_DEBUG_5(("%s: response from server %s:%u\n", __func__,
inet_ntop(recv.su_family, SU_ADDR(&recv), addr, sizeof(addr)),
su_inet_ntop(recv.su_family, SU_ADDR(&recv), addr, sizeof(addr)),
ntohs(recv.su_port)));
debug_print(&binding_response.enc_buf);
@ -2014,7 +2014,7 @@ static int priv_find_matching_localadress(su_sockaddr_t *su)
char addr[SU_ADDRSIZE];
SU_DEBUG_5(("%s: checking if %s is a local address.\n", __func__,
inet_ntop(AF_INET, SU_ADDR(su), addr, sizeof(addr))));
su_inet_ntop(AF_INET, SU_ADDR(su), addr, sizeof(addr))));
hints->li_family = af = su->su_family;
@ -2032,7 +2032,7 @@ static int priv_find_matching_localadress(su_sockaddr_t *su)
}
SU_DEBUG_9(("%s: skipping local address %s.\n", __func__,
inet_ntop(af, SU_ADDR(li->li_addr), addr, sizeof(addr))));
su_inet_ntop(af, SU_ADDR(li->li_addr), addr, sizeof(addr))));
}
su_freelocalinfo(res);
@ -2758,7 +2758,7 @@ int stun_test_lifetime(stun_handle_t *sh,
}
SU_DEBUG_3(("%s: socket y bound to %s:%u\n", __func__,
inet_ntop(y_addr.su_family, SU_ADDR(&y_addr), addr, sizeof(addr)),
su_inet_ntop(y_addr.su_family, SU_ADDR(&y_addr), addr, sizeof(addr)),
(unsigned) ntohs(y_addr.su_port)));
req->sr_from_y = -1;
@ -2946,7 +2946,7 @@ int stun_keepalive(stun_handle_t *sh,
req = stun_request_create(sd);
SU_DEBUG_3(("%s: Starting to send STUN keepalives to %s:%u\n", __func__,
inet_ntop(sa->su_family, SU_ADDR(sa), addr, sizeof(addr)),
su_inet_ntop(sa->su_family, SU_ADDR(sa), addr, sizeof(addr)),
(unsigned) ntohs(sa->su_port)));
if (stun_make_binding_req(sh, req, req->sr_msg, 0, 0) < 0 ||

View File

@ -223,7 +223,7 @@ int stun_parse_attr_address(stun_attr_t *attr,
memcpy(&addr->su_sin.sin_addr.s_addr, p + 4, 4);
SU_DEBUG_5(("%s: address attribute: %s:%d\n", __func__,
inet_ntop(addr->su_family, SU_ADDR(addr), ipaddr, sizeof(ipaddr)),
su_inet_ntop(addr->su_family, SU_ADDR(addr), ipaddr, sizeof(ipaddr)),
(unsigned) ntohs(addr->su_sin.sin_port)));
attr->pattr = addr;
@ -640,7 +640,7 @@ int stun_send_message(su_socket_t s, su_sockaddr_t *to_addr,
}
if (err > 0) {
inet_ntop(to_addr->su_family, SU_ADDR(to_addr), ipaddr, sizeof(ipaddr));
su_inet_ntop(to_addr->su_family, SU_ADDR(to_addr), ipaddr, sizeof(ipaddr));
SU_DEBUG_5(("%s: message sent to %s:%u\n", __func__,
ipaddr, ntohs(to_addr->su_port)));

View File

@ -184,7 +184,7 @@ void stun_mini_request(stun_mini_t *mini,
struct sockaddr_in const *sin = from;
if (sin->sin_family == AF_INET)
inet_ntop(sin->sin_family, &sin->sin_addr, buffer, sizeof buffer);
su_inet_ntop(sin->sin_family, &sin->sin_addr, buffer, sizeof buffer);
else
sprintf(buffer, "<af=%u>", (unsigned)sin->sin_family);

View File

@ -45,7 +45,7 @@ static const char *inet_ntop6(const unsigned char *src, char *dst, size_t size);
* Paul Vixie, 1996.
*/
const char *
inet_ntop(int af, void const *src, char *dst, size_t size)
su_inet_ntop(int af, void const *src, char *dst, size_t size)
{
switch (af) {

View File

@ -45,7 +45,7 @@ static int inet_pton6(const char *src, unsigned char *dst);
* Paul Vixie, 1996.
*/
int
inet_pton(int af, const char * src, void * dst)
su_inet_pton(int af, const char * src, void * dst)
{
switch (af) {
case AF_INET:

View File

@ -321,8 +321,8 @@ SOFIAPUBFUN int su_getlocalip(su_sockaddr_t *sin);
#endif
#if SU_HAVE_WINSOCK
SOFIAPUBFUN int inet_pton(int af, char const *src, void *dst);
SOFIAPUBFUN const char *inet_ntop(int af, void const *src,
SOFIAPUBFUN int su_inet_pton(int af, char const *src, void *dst);
SOFIAPUBFUN const char *su_inet_ntop(int af, void const *src,
char *dst, size_t size);
SOFIAPUBFUN ssize_t
su_send(su_socket_t s, void *buffer, size_t length, int flags),
@ -351,6 +351,8 @@ uint32_t su_ntohl(uint32_t l)
#define htonl su_ntohl
#else
#define su_inet_pton inet_pton
#define su_inet_ntop inet_ntop
#define su_send(s,b,l,f) send((s),(b),(l),(f))
#define su_sendto(s,b,l,f,a,L) sendto((s),(b),(l),(f),(void const*)(a),(L))
#define su_recv(s,b,l,f) recv((s),(b),(l),(f))

View File

@ -1596,7 +1596,7 @@ int li_name(su_localinfo_t const *hints,
if ((flags & LI_NAMEREQD) == LI_NAMEREQD)
return 1;
SU_DEBUG_7(("li_name: getnameinfo() failed\n"));
if (!inet_ntop(su->su_family, SU_ADDR(su), name, sizeof name))
if (!su_inet_ntop(su->su_family, SU_ADDR(su), name, sizeof name))
return ELI_RESOLVER;
}

View File

@ -2954,14 +2954,14 @@ void tport_deliver(tport_t *self,
#if SU_HAVE_IN6
if (su->su_family == AF_INET6) {
ipaddr[0] = '[';
inet_ntop(su->su_family, SU_ADDR(su), ipaddr + 1, sizeof(ipaddr) - 1);
su_inet_ntop(su->su_family, SU_ADDR(su), ipaddr + 1, sizeof(ipaddr) - 1);
strcat(ipaddr, "]");
}
else {
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
su_inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
}
#else
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
su_inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
#endif
d->d_from->tpn_canon = ipaddr;
@ -3949,7 +3949,7 @@ tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn)
#if SU_HAVE_IN6
SU_DEBUG_9(("tport_resolve addrinfo = %s%s%s:%d\n",
su->su_family == AF_INET6 ? "[" : "",
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)),
su_inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)),
su->su_family == AF_INET6 ? "]" : "",
htons(su->su_port)));
#else
@ -4433,7 +4433,7 @@ tport_t *tport_by_name(tport_t const *self, tp_name_t const *tpn)
su->su_port = htons(strtoul(port, NULL, 10));
if (inet_pton(su->su_family, host, SU_ADDR(su)) > 0) {
if (su_inet_pton(su->su_family, host, SU_ADDR(su)) > 0) {
resolved = 1;
next = NULL;
@ -4710,7 +4710,7 @@ char *tport_hostport(char buf[], isize_t bufsize,
}
#endif
if (inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL)
if (su_inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL)
return NULL;
n = strlen(b);
if (bufsize < n + 2)

View File

@ -154,7 +154,7 @@ void tport_stamp(tport_t const *self, msg_t *msg,
if (msg_addrinfo(msg)->ai_flags & TP_AI_COMPRESSED)
comp = ";comp=sigcomp";
inet_ntop(su->su_family, SU_ADDR(su), name, sizeof(name));
su_inet_ntop(su->su_family, SU_ADDR(su), name, sizeof(name));
snprintf(stamp, 128,
"%s "MOD_ZU" bytes %s %s/[%s]:%u%s%s at %02u:%02u:%02u.%06lu:\n",