Commit 4c47c989 authored by Martti Mela's avatar Martti Mela

Compilation support for non-IPv6 environments

darcs-hash:20051201142448-1b897-a46da7cdb4bf9941ef939b3e936ebaa820110227.gz
parent 03cd4e97
...@@ -1573,7 +1573,10 @@ int agent_init_via(nta_agent_t *self, int use_maddr) ...@@ -1573,7 +1573,10 @@ int agent_init_via(nta_agent_t *self, int use_maddr)
#endif #endif
if (tport_has_ip4(tp)) self->sa_tport_ip4 = 1; if (tport_has_ip4(tp)) self->sa_tport_ip4 = 1;
#if SU_HAVE_IN6
if (tport_has_ip6(tp)) self->sa_tport_ip6 = 1; if (tport_has_ip6(tp)) self->sa_tport_ip6 = 1;
#endif
if (strcasecmp(tpn->tpn_proto, "udp") == 0) if (strcasecmp(tpn->tpn_proto, "udp") == 0)
self->sa_tport_udp = 1; self->sa_tport_udp = 1;
...@@ -7788,9 +7791,11 @@ static int outgoing_query_srv(nta_outgoing_t *orq, struct sipdns_query *); ...@@ -7788,9 +7791,11 @@ static int outgoing_query_srv(nta_outgoing_t *orq, struct sipdns_query *);
static void outgoing_answer_srv(sres_context_t *orq, sres_query_t *q, static void outgoing_answer_srv(sres_context_t *orq, sres_query_t *q,
sres_record_t *answers[]); sres_record_t *answers[]);
#if SU_HAVE_IN6
static int outgoing_query_aaaa(nta_outgoing_t *orq, struct sipdns_query *); static int outgoing_query_aaaa(nta_outgoing_t *orq, struct sipdns_query *);
static void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q, static void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q,
sres_record_t *answers[]); sres_record_t *answers[]);
#endif
static int outgoing_query_a(nta_outgoing_t *orq, struct sipdns_query *); static int outgoing_query_a(nta_outgoing_t *orq, struct sipdns_query *);
static void outgoing_answer_a(sres_context_t *orq, sres_query_t *q, static void outgoing_answer_a(sres_context_t *orq, sres_query_t *q,
...@@ -8134,8 +8139,10 @@ void outgoing_query_all(nta_outgoing_t *orq) ...@@ -8134,8 +8139,10 @@ void outgoing_query_all(nta_outgoing_t *orq)
if (sq->sq_type == sres_type_srv) if (sq->sq_type == sres_type_srv)
outgoing_query_srv(orq, sq); outgoing_query_srv(orq, sq);
#if SU_HAVE_IN6
else if (sq->sq_type == sres_type_aaaa) else if (sq->sq_type == sres_type_aaaa)
outgoing_query_aaaa(orq, sq); outgoing_query_aaaa(orq, sq);
#endif
else if (sq->sq_type == sres_type_a) else if (sq->sq_type == sres_type_a)
outgoing_query_a(orq, sq); outgoing_query_a(orq, sq);
else else
...@@ -8424,6 +8431,7 @@ outgoing_answer_srv(sres_context_t *orq, sres_query_t *q, ...@@ -8424,6 +8431,7 @@ outgoing_answer_srv(sres_context_t *orq, sres_query_t *q,
outgoing_resolve_next(orq); outgoing_resolve_next(orq);
} }
#if SU_HAVE_IN6
/* Query AAAA records */ /* Query AAAA records */
static static
int outgoing_query_aaaa(nta_outgoing_t *orq, struct sipdns_query *sq) int outgoing_query_aaaa(nta_outgoing_t *orq, struct sipdns_query *sq)
...@@ -8505,6 +8513,7 @@ void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q, ...@@ -8505,6 +8513,7 @@ void outgoing_answer_aaaa(sres_context_t *orq, sres_query_t *q,
outgoing_query_results(orq, sq, results, found); outgoing_query_results(orq, sq, results, found);
} }
#endif /* SU_HAVE_IN6 */
/* Query A records */ /* Query A records */
static static
......
...@@ -33,7 +33,6 @@ ...@@ -33,7 +33,6 @@
#include "config.h" #include "config.h"
char const name[] = "portbind"; char const name[] = "portbind";
#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
...@@ -45,6 +44,8 @@ char const name[] = "portbind"; ...@@ -45,6 +44,8 @@ char const name[] = "portbind";
#include <netinet/in.h> #include <netinet/in.h>
#include <netdb.h> #include <netdb.h>
#include "su.h"
#if !defined(IPPROTO_SCTP) #if !defined(IPPROTO_SCTP)
#define IPPROTO_SCTP (132) #define IPPROTO_SCTP (132)
#endif #endif
......
...@@ -490,6 +490,7 @@ int test_init(agent_t *ag, char const *resolv_conf) ...@@ -490,6 +490,7 @@ int test_init(agent_t *ag, char const *resolv_conf)
TEST_1(ag->ag_mclass = msg_mclass_clone(sip_default_mclass(), 0, 0)); TEST_1(ag->ag_mclass = msg_mclass_clone(sip_default_mclass(), 0, 0));
#if SU_HAVE_IN6
if (str0cmp(getenv("ipv6"), "true") == 0) { if (str0cmp(getenv("ipv6"), "true") == 0) {
contact = "sip:[::]:*;comp=sigcomp"; contact = "sip:[::]:*;comp=sigcomp";
af = AF_INET6, sulen0 = sizeof (struct sockaddr_in6); af = AF_INET6, sulen0 = sizeof (struct sockaddr_in6);
...@@ -498,6 +499,10 @@ int test_init(agent_t *ag, char const *resolv_conf) ...@@ -498,6 +499,10 @@ int test_init(agent_t *ag, char const *resolv_conf)
af = AF_INET, sulen0 = sizeof (struct sockaddr_in); af = AF_INET, sulen0 = sizeof (struct sockaddr_in);
contact = "sip:0.0.0.0:*;comp=sigcomp"; contact = "sip:0.0.0.0:*;comp=sigcomp";
} }
#else
af = AF_INET, sulen0 = sizeof (struct sockaddr_in);
contact = "sip:0.0.0.0:*;comp=sigcomp";
#endif
if (ag->ag_m) if (ag->ag_m)
contact = ag->ag_m; contact = ag->ag_m;
......
...@@ -23,7 +23,7 @@ noinst_PROGRAMS = torture_sip \ ...@@ -23,7 +23,7 @@ noinst_PROGRAMS = torture_sip \
# Rules for building the targets # Rules for building the targets
GENERATED_H = sip_hclasses.h sip_protos.h sip_tag.h sip_rfc2543.h GENERATED_H = sip_hclasses.h sip_protos.h sip_tag.h sip_rfc2543.h
H_IN = sip_hclasses.h.in sip_protos.h.in sip_tag.h.in H_IN = sip_hclasses.h.in sip_protos.h.in sip_tag.h.in sip_rfc2543.h.in
PUBLIC_H = sip.h sip_extensions.h sip_util.h \ PUBLIC_H = sip.h sip_extensions.h sip_util.h \
sip_header.h sip_parser.h \ sip_header.h sip_parser.h \
...@@ -114,7 +114,7 @@ sip_parser_table.c: sip_bad_mask ...@@ -114,7 +114,7 @@ sip_parser_table.c: sip_bad_mask
sip_%.h: sip_%.h.in $(MSG_PARSER_AWK) sip_%.h: sip_%.h.in $(MSG_PARSER_AWK)
sip_%.c: sip_%.c.in $(MSG_PARSER_AWK) sip_%.c: sip_%.c.in $(MSG_PARSER_AWK)
sip_tag.c sip_hclasses.h sip_protos.h sip_tag.h: sip.h sip_tag.c sip_hclasses.h sip_protos.h sip_tag.h sip_rfc2543.h: sip.h
$(AWK_MSG_AWK) PR=$@ $< $(AWK_MSG_AWK) PR=$@ $<
sip_parser_table.c: sip.h sip_parser_table.c: sip.h
......
...@@ -1734,6 +1734,8 @@ soa_init_sdp_connection(soa_session_t *ss, ...@@ -1734,6 +1734,8 @@ soa_init_sdp_connection(soa_session_t *ss,
case SOA_AF_IP4_ONLY: case SOA_AF_IP4_ONLY:
hints->li_family = AF_INET, ip4 = 1, ip6 = 0; hints->li_family = AF_INET, ip4 = 1, ip6 = 0;
break; break;
#if HAVE_SIN6
case SOA_AF_IP6_ONLY: case SOA_AF_IP6_ONLY:
hints->li_family = AF_INET6, ip6 = 1, ip4 = 0; hints->li_family = AF_INET6, ip6 = 1, ip4 = 0;
break; break;
...@@ -1743,6 +1745,7 @@ soa_init_sdp_connection(soa_session_t *ss, ...@@ -1743,6 +1745,7 @@ soa_init_sdp_connection(soa_session_t *ss,
case SOA_AF_IP6_IP4: case SOA_AF_IP6_IP4:
ip4 = 1, ip6 = 2; ip4 = 1, ip6 = 2;
break; break;
#endif
default: default:
ip4 = ip6 = 1; ip4 = ip6 = 1;
} }
...@@ -1781,12 +1784,14 @@ soa_init_sdp_connection(soa_session_t *ss, ...@@ -1781,12 +1784,14 @@ soa_init_sdp_connection(soa_session_t *ss,
if (!li) if (!li)
break; break;
#if HAVE_SIN6
else if (li->li_family == AF_INET6) { else if (li->li_family == AF_INET6) {
if (ip6 >= ip4) if (ip6 >= ip4)
break; break;
else if (!li6) else if (!li6)
li6 = li; /* Best IP6 address */ li6 = li; /* Best IP6 address */
} }
#endif
else if (li->li_family == AF_INET) { else if (li->li_family == AF_INET) {
if (ip4 > ip6) if (ip4 > ip6)
break; break;
...@@ -1807,8 +1812,10 @@ soa_init_sdp_connection(soa_session_t *ss, ...@@ -1807,8 +1812,10 @@ soa_init_sdp_connection(soa_session_t *ss,
; ;
else if (li->li_family == AF_INET) else if (li->li_family == AF_INET)
c->c_nettype = sdp_net_in, c->c_addrtype = sdp_addr_ip4; c->c_nettype = sdp_net_in, c->c_addrtype = sdp_addr_ip4;
#if HAVE_SIN6
else if (li->li_family == AF_INET6) else if (li->li_family == AF_INET6)
c->c_nettype = sdp_net_in, c->c_addrtype = sdp_addr_ip6; c->c_nettype = sdp_net_in, c->c_addrtype = sdp_addr_ip6;
#endif
if (li) { if (li) {
assert(strlen(li->li_canonname) < 64); assert(strlen(li->li_canonname) < 64);
......
...@@ -364,7 +364,13 @@ int su_cmp_sockaddr(su_sockaddr_t const *a, su_sockaddr_t const *b); ...@@ -364,7 +364,13 @@ int su_cmp_sockaddr(su_sockaddr_t const *a, su_sockaddr_t const *b);
int su_match_sockaddr(su_sockaddr_t const *a, su_sockaddr_t const *b); int su_match_sockaddr(su_sockaddr_t const *a, su_sockaddr_t const *b);
void su_canonize_sockaddr(su_sockaddr_t *su); void su_canonize_sockaddr(su_sockaddr_t *su);
#if SU_HAVE_IN6
#define SU_CANONIZE_SOCKADDR(su) \ #define SU_CANONIZE_SOCKADDR(su) \
((su)->su_family == AF_INET6 ? su_canonize_sockaddr(su) : (void)0) ((su)->su_family == AF_INET6 ? su_canonize_sockaddr(su) : (void)0)
#else
#define SU_CANONIZE_SOCKADDR(su) \
((void)0)
#endif
#endif /* !defined(SU_H) */ #endif /* !defined(SU_H) */
...@@ -927,10 +927,20 @@ static void *su_clone_main(void *varg) ...@@ -927,10 +927,20 @@ static void *su_clone_main(void *varg)
su_root_run(self); /* Do the work */ su_root_run(self); /* Do the work */
printf("Ready to zap root from %p\n", pthread_self());
fflush(stdout);
su_root_destroy(self); /* Cleanup root */ su_root_destroy(self); /* Cleanup root */
printf("Ready to zap port from %p\n", pthread_self());
fflush(stdout);
SU_PORT_ZAPREF(port, su_clone_main); SU_PORT_ZAPREF(port, su_clone_main);
printf("Ready to exit from %p\n", pthread_self());
fflush(stdout);
pthread_exit(NULL);
return NULL; return NULL;
} }
#endif #endif
...@@ -1163,10 +1173,14 @@ void su_clone_wait(su_root_t *root, su_clone_r rclone) ...@@ -1163,10 +1173,14 @@ void su_clone_wait(su_root_t *root, su_clone_r rclone)
su_root_step(root, 0); su_root_step(root, 0);
su_root_step(root, 0); su_root_step(root, 0);
printf("Ready to wait()\n");
while (one) while (one)
su_root_step(root, 10); su_root_step(root, 10);
#if SU_HAVE_PTHREADS #if SU_HAVE_PTHREADS
printf("Ready to join(%p)\n", clone_tid);
if (!pthread_equal(clone_tid, pthread_self())) if (!pthread_equal(clone_tid, pthread_self()))
pthread_join(clone_tid, NULL); pthread_join(clone_tid, NULL);
#endif #endif
......
...@@ -138,8 +138,8 @@ static int name_test(tp_test_t *tt) ...@@ -138,8 +138,8 @@ static int name_test(tp_test_t *tt)
TEST(tport_convert_addr(home, tpn, "tcp", "localhost", su), 0); TEST(tport_convert_addr(home, tpn, "tcp", "localhost", su), 0);
su->su_family = AF_INET6;
#if SU_HAVE_IN6 #if SU_HAVE_IN6
su->su_family = AF_INET6;
TEST(tport_convert_addr(home, tpn, "tcp", "localhost", su), 0); TEST(tport_convert_addr(home, tpn, "tcp", "localhost", su), 0);
#endif #endif
......
...@@ -636,12 +636,15 @@ int tport_has_ip4(tport_t const *self) ...@@ -636,12 +636,15 @@ int tport_has_ip4(tport_t const *self)
/* || self->tp_pri->pri_family2 == AF_INET */); /* || self->tp_pri->pri_family2 == AF_INET */);
} }
#if SU_HAVE_IN6
/** Return true if transport supports IPv6 */ /** Return true if transport supports IPv6 */
int tport_has_ip6(tport_t const *self) int tport_has_ip6(tport_t const *self)
{ {
return self && return self &&
(self->tp_pri->pri_family == 0 || self->tp_pri->pri_family == AF_INET6); (self->tp_pri->pri_family == 0 || self->tp_pri->pri_family == AF_INET6);
} }
#endif
/** Return true if transport supports TLS. */ /** Return true if transport supports TLS. */
int tport_has_tls(tport_t const *self) int tport_has_tls(tport_t const *self)
...@@ -1150,11 +1153,13 @@ tport_primary_t *tport_listen(tport_master_t *mr, su_addrinfo_t const *ai, ...@@ -1150,11 +1153,13 @@ tport_primary_t *tport_listen(tport_master_t *mr, su_addrinfo_t const *ai,
s = su_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); s = su_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
#if SU_HAVE_IN6
if (s == SOCKET_ERROR) { if (s == SOCKET_ERROR) {
if (ai->ai_family == AF_INET6 && su_errno() == EAFNOSUPPORT) if (ai->ai_family == AF_INET6 && su_errno() == EAFNOSUPPORT)
errlevel = 7; errlevel = 7;
return TPORT_LISTEN_ERROR(su_errno(), socket); return TPORT_LISTEN_ERROR(su_errno(), socket);
} }
#endif
/* Passive open, do bind() (and listen() if connection-oriented). */ /* Passive open, do bind() (and listen() if connection-oriented). */
...@@ -1405,11 +1410,13 @@ tport_t *tport_connect(tport_primary_t *pri, ...@@ -1405,11 +1410,13 @@ tport_t *tport_connect(tport_primary_t *pri,
s = su_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); s = su_socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol);
#if SU_HAVE_IN6
if (s == SOCKET_ERROR) { if (s == SOCKET_ERROR) {
if (ai->ai_family == AF_INET6 && su_errno() == EAFNOSUPPORT) if (ai->ai_family == AF_INET6 && su_errno() == EAFNOSUPPORT)
errlevel = 7; errlevel = 7;
TPORT_CONNECT_ERROR(su_errno(), socket); TPORT_CONNECT_ERROR(su_errno(), socket);
} }
#endif
if (pri->pri_primary->tp_socket != SOCKET_ERROR) { if (pri->pri_primary->tp_socket != SOCKET_ERROR) {
su_sockaddr_t susa; su_sockaddr_t susa;
...@@ -1827,7 +1834,7 @@ int tport_bind_server(tport_master_t *mr, ...@@ -1827,7 +1834,7 @@ int tport_bind_server(tport_master_t *mr,
tagi_t *tags) tagi_t *tags)
{ {
char hostname[256]; char hostname[256];
char const *proto, *canon, *host, *port; char const *proto, *canon = NULL, *host, *port;
char port0[16]; char port0[16];
int ephemeral_port; int ephemeral_port;
int i, error = 0, not_supported, family = 0; int i, error = 0, not_supported, family = 0;
...@@ -1898,8 +1905,10 @@ int tport_bind_server(tport_master_t *mr, ...@@ -1898,8 +1905,10 @@ int tport_bind_server(tport_master_t *mr,
if (host && (strcmp(host, "0.0.0.0") == 0 || strcmp(host, "0") == 0)) if (host && (strcmp(host, "0.0.0.0") == 0 || strcmp(host, "0") == 0))
host = NULL, family = AF_INET; host = NULL, family = AF_INET;
#if SU_HAVE_IN6
else if (host && strcmp(host, "::") == 0) else if (host && strcmp(host, "::") == 0)
host = NULL, family = AF_INET6; host = NULL, family = AF_INET6;
#endif
if (tpn->tpn_canon && strcmp(tpn->tpn_canon, tpn_any) && if (tpn->tpn_canon && strcmp(tpn->tpn_canon, tpn_any) &&
(host || tpn->tpn_canon != tpn->tpn_host)) (host || tpn->tpn_canon != tpn->tpn_host))
...@@ -1918,11 +1927,18 @@ int tport_bind_server(tport_master_t *mr, ...@@ -1918,11 +1927,18 @@ int tport_bind_server(tport_master_t *mr,
error = su_getlocalinfo(hints, &li); error = su_getlocalinfo(hints, &li);
if (error) { if (error) {
#if SU_HAVE_IN6
SU_DEBUG_3(("%s(%p): su_getlocalinfo() for %s address: %s\n", SU_DEBUG_3(("%s(%p): su_getlocalinfo() for %s address: %s\n",
__func__, mr, __func__, mr,
family == AF_INET6 ? "ip6" family == AF_INET6 ? "ip6"
: family == AF_INET ? "ip4" : "ip", : family == AF_INET ? "ip4" : "ip",
su_gli_strerror(error))); su_gli_strerror(error)));
#else
SU_DEBUG_3(("%s(%p): su_getlocalinfo() for %s address: %s\n",
__func__, mr,
family == AF_INET ? "ip4" : "ip",
su_gli_strerror(error)));
#endif
su_seterrno(ENOENT); su_seterrno(ENOENT);
return -1; return -1;
} }
...@@ -1979,8 +1995,13 @@ int tport_bind_server(tport_master_t *mr, ...@@ -1979,8 +1995,13 @@ int tport_bind_server(tport_master_t *mr,
for (ai = res; ai; ai = ai->ai_next) { for (ai = res; ai; ai = ai->ai_next) {
/* Skip non-internet (AF_LOCAL) addresses */ /* Skip non-internet (AF_LOCAL) addresses */
#if SU_HAVE_IN6
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
continue; continue;
#else
if (ai->ai_family != AF_INET)
continue;
#endif
SU_DEBUG_9(("%s(%p): calling tport_socket\n", __func__, mr)); SU_DEBUG_9(("%s(%p): calling tport_socket\n", __func__, mr));
...@@ -2449,9 +2470,11 @@ int tport_convert_addr(su_home_t *home, ...@@ -2449,9 +2470,11 @@ int tport_convert_addr(su_home_t *home,
else if (canonlen && su->su_family == AF_INET && else if (canonlen && su->su_family == AF_INET &&
strspn(canon, "0123456789.") == canonlen) strspn(canon, "0123456789.") == canonlen)
host = canon; host = canon;
#if SU_HAVE_IN6
else if (canonlen && su->su_family == AF_INET6 && else if (canonlen && su->su_family == AF_INET6 &&
strspn(canon, "0123456789abcdefABCDEF:.") == canonlen) strspn(canon, "0123456789abcdefABCDEF:.") == canonlen)
host = canon; host = canon;
#endif
else else
host = localipname(su->su_family, buf, sizeof(buf)); host = localipname(su->su_family, buf, sizeof(buf));
...@@ -2545,12 +2568,15 @@ char *localipname(int pf, char *buf, int bufsiz) ...@@ -2545,12 +2568,15 @@ char *localipname(int pf, char *buf, int bufsiz)
hints->li_family = pf; hints->li_family = pf;
#if SU_HAVE_IN6
if (pf == AF_INET6) { if (pf == AF_INET6) {
/* Link-local addresses are not usable on IPv6 */ /* Link-local addresses are not usable on IPv6 */
hints->li_scope = LI_SCOPE_GLOBAL | LI_SCOPE_SITE /* | LI_SCOPE_HOST */; hints->li_scope = LI_SCOPE_GLOBAL | LI_SCOPE_SITE /* | LI_SCOPE_HOST */;
} }
#endif
if ((error = su_getlocalinfo(hints, &li))) { if ((error = su_getlocalinfo(hints, &li))) {
#if SU_HAVE_IN6
if (error == ELI_NOADDRESS && pf == AF_INET6) { if (error == ELI_NOADDRESS && pf == AF_INET6) {
hints->li_family = AF_INET; hints->li_family = AF_INET;
error = su_getlocalinfo(hints, &li); error = su_getlocalinfo(hints, &li);
...@@ -2563,6 +2589,7 @@ char *localipname(int pf, char *buf, int bufsiz) ...@@ -2563,6 +2589,7 @@ char *localipname(int pf, char *buf, int bufsiz)
error = su_getlocalinfo(hints, &li); error = su_getlocalinfo(hints, &li);
} }
} }
#endif
if (error) { if (error) {
SU_DEBUG_1(("tport: su_getlocalinfo: %s\n", su_gli_strerror(error))); SU_DEBUG_1(("tport: su_getlocalinfo: %s\n", su_gli_strerror(error)));
return NULL; return NULL;
...@@ -3063,6 +3090,7 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next, ...@@ -3063,6 +3090,7 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
char ipaddr[SU_ADDRSIZE + 2]; char ipaddr[SU_ADDRSIZE + 2];
su_sockaddr_t *su = msg_addr(msg); su_sockaddr_t *su = msg_addr(msg);
#if SU_HAVE_IN6
if (su->su_family == AF_INET6) { if (su->su_family == AF_INET6) {
ipaddr[0] = '['; ipaddr[0] = '[';
inet_ntop(su->su_family, SU_ADDR(su), ipaddr + 1, sizeof(ipaddr) - 1); inet_ntop(su->su_family, SU_ADDR(su), ipaddr + 1, sizeof(ipaddr) - 1);
...@@ -3071,6 +3099,9 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next, ...@@ -3071,6 +3099,9 @@ void tport_deliver(tport_t *self, msg_t *msg, msg_t *next,
else { else {
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)); inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
} }
#else
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr));
#endif
d->d_from->tpn_canon = ipaddr; d->d_from->tpn_canon = ipaddr;
d->d_from->tpn_host = ipaddr; d->d_from->tpn_host = ipaddr;
...@@ -4369,6 +4400,7 @@ int tport_send_error(tport_t *self, msg_t *msg, ...@@ -4369,6 +4400,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
self, su_strerror(error), self->tp_socket, self, su_strerror(error), self->tp_socket,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp)); tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp));
} }
#if SU_HAVE_IN6
else if (self->tp_pri->pri_family == AF_INET6) { else if (self->tp_pri->pri_family == AF_INET6) {
su_sockaddr_t const *su = msg_addr(msg); su_sockaddr_t const *su = msg_addr(msg);
SU_DEBUG_3(("tport_vsend(%p): %s with " SU_DEBUG_3(("tport_vsend(%p): %s with "
...@@ -4377,6 +4409,7 @@ int tport_send_error(tport_t *self, msg_t *msg, ...@@ -4377,6 +4409,7 @@ int tport_send_error(tport_t *self, msg_t *msg,
tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp, tpn->tpn_proto, tpn->tpn_host, tpn->tpn_port, comp,
su->su_scope_id, *msg_addrlen(msg))); su->su_scope_id, *msg_addrlen(msg)));
} }
#endif
else { else {
su_sockaddr_t const *su = msg_addr(msg); su_sockaddr_t const *su = msg_addr(msg);
SU_DEBUG_3(("\ttport_vsend(%p): %s with " SU_DEBUG_3(("\ttport_vsend(%p): %s with "
...@@ -5036,11 +5069,19 @@ tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn) ...@@ -5036,11 +5069,19 @@ tport_resolve(tport_t *self, msg_t *msg, tp_name_t const *tpn)
su = (su_sockaddr_t *) msg_addrinfo(msg)->ai_addr; su = (su_sockaddr_t *) msg_addrinfo(msg)->ai_addr;
#if SU_HAVE_IN6
SU_DEBUG_9(("tport_resolve addrinfo = %s%s%s:%d\n", SU_DEBUG_9(("tport_resolve addrinfo = %s%s%s:%d\n",
su->su_family == AF_INET6 ? "[" : "", su->su_family == AF_INET6 ? "[" : "",
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)), inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)),
su->su_family == AF_INET6 ? "]" : "", su->su_family == AF_INET6 ? "]" : "",
htons(su->su_port))); htons(su->su_port)));
#else
SU_DEBUG_9(("tport_resolve addrinfo = %s%s%s:%d\n",
"",
inet_ntop(su->su_family, SU_ADDR(su), ipaddr, sizeof(ipaddr)),
"",
htons(su->su_port)));
#endif
su_freeaddrinfo(res); su_freeaddrinfo(res);
...@@ -5055,8 +5096,14 @@ msg_select_addrinfo(msg_t *msg, su_addrinfo_t *res) ...@@ -5055,8 +5096,14 @@ msg_select_addrinfo(msg_t *msg, su_addrinfo_t *res)
socklen_t *sulen = msg_addrlen(msg); socklen_t *sulen = msg_addrlen(msg);
for (ai = res; ai; ai = ai->ai_next) { for (ai = res; ai; ai = ai->ai_next) {
#if SU_HAVE_IN6
if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6)
continue; continue;
#else
if (ai->ai_family != AF_INET)
continue;
#endif
if (ai->ai_addrlen > sizeof(su_sockaddr_t)) if (ai->ai_addrlen > sizeof(su_sockaddr_t))
continue; continue;
mai->ai_family = ai->ai_family; mai->ai_family = ai->ai_family;
...@@ -5672,8 +5719,10 @@ tport_t *tport_primary_by_name(tport_t const *tp, tp_name_t const *tpn) ...@@ -5672,8 +5719,10 @@ tport_t *tport_primary_by_name(tport_t const *tp, tp_name_t const *tpn)
if (tpn->tpn_host == NULL) if (tpn->tpn_host == NULL)
family = 0; family = 0;
#if SU_HAVE_IN6
else if (strchr(tpn->tpn_host, ':')) else if (strchr(tpn->tpn_host, ':'))
family = AF_INET6; family = AF_INET6;
#endif
else if (strcmp(tpn->tpn_host, tpn_any)) else if (strcmp(tpn->tpn_host, tpn_any))
family = AF_INET; family = AF_INET;
...@@ -5694,8 +5743,10 @@ tport_t *tport_primary_by_name(tport_t const *tp, tp_name_t const *tpn) ...@@ -5694,8 +5743,10 @@ tport_t *tport_primary_by_name(tport_t const *tp, tp_name_t const *tpn)
if (family) { if (family) {
if (family == AF_INET && !tport_has_ip4(tp)) if (family == AF_INET && !tport_has_ip4(tp))
continue; continue;
#if SU_HAVE_IN6
if (family == AF_INET6 && !tport_has_ip6(tp)) if (family == AF_INET6 && !tport_has_ip6(tp))
continue; continue;
#endif
} }
if (proto && strcasecmp(proto, tp->tp_protoname)) if (proto && strcasecmp(proto, tp->tp_protoname))
continue; continue;
...@@ -6059,14 +6110,19 @@ char *tport_hostport(char buf[], int bufsize, ...@@ -6059,14 +6110,19 @@ char *tport_hostport(char buf[], int bufsize,
char *b = buf; char *b = buf;
int n; int n;
#if SU_HAVE_IN6
if (with_port_and_brackets > 1 || su->su_family == AF_INET6) { if (with_port_and_brackets > 1 || su->su_family == AF_INET6) {
*b++ = '['; bufsize--; *b++ = '['; bufsize--;
} }
#endif
if (inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL) if (inet_ntop(su->su_family, SU_ADDR(su), b, bufsize) == NULL)
return NULL; return NULL;
n = strlen(b); bufsize -= n; b += n; n = strlen(b); bufsize -= n; b += n;
if (bufsize < 2) if (bufsize < 2)
return NULL; return NULL;
#if SU_HAVE_IN6
if (with_port_and_brackets > 1 || su->su_family == AF_INET6) { if (with_port_and_brackets > 1 || su->su_family == AF_INET6) {
*b++ = ']'; bufsize--; *b++ = ']'; bufsize--;
} }
...@@ -6083,6 +6139,7 @@ char *tport_hostport(char buf[], int bufsize, ...@@ -6083,6 +6139,7 @@ char *tport_hostport(char buf[], int bufsize,
bufsize = 0; bufsize = 0;
} }
} }
#endif
if (bufsize) if (bufsize)
*b++ = 0; *b++ = 0;
......
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