Hi, this looks like it should work both on *BSD and on Linux - explicit salen parameter, based on sa_family, no special macros (since we have the switch/case part anyway).
And the tabs are right \o/ ACK ;-) gert On Mon, Sep 03, 2012 at 09:26:16AM +0200, Arne Schwabe wrote: > --- > src/openvpn/socket.c | 68 > ++++++++++++++++++++++---------------------------- > 1 file changed, 30 insertions(+), 38 deletions(-) > > diff --git a/src/openvpn/socket.c b/src/openvpn/socket.c > index 505cf3b..a9adf3f 100644 > --- a/src/openvpn/socket.c > +++ b/src/openvpn/socket.c > @@ -2164,60 +2164,52 @@ print_sockaddr (const struct openvpn_sockaddr *addr, > struct gc_arena *gc) > > const char * > print_sockaddr_ex (const struct openvpn_sockaddr *addr, > - const char* separator, > - const unsigned int flags, > - struct gc_arena *gc) > + const char* separator, > + const unsigned int flags, > + struct gc_arena *gc) > { > struct buffer out = alloc_buf_gc (128, gc); > bool addr_is_defined; > + char buf[NI_MAXHOST] = ""; > + > addr_is_defined = addr_defined (addr); > if (!addr_is_defined) { > return "[undef]"; > } > + > + int port; > + int salen; > switch(addr->addr.sa.sa_family) > { > case AF_INET: > - { > - const int port= ntohs (addr->addr.in4.sin_port); > - buf_puts (&out, "[AF_INET]"); > - > - if (!(flags & PS_DONT_SHOW_ADDR)) > - buf_printf (&out, "%s", (addr_defined (addr) ? inet_ntoa > (addr->addr.in4.sin_addr) : "[undef]")); > - > - if (((flags & PS_SHOW_PORT) || (addr_defined (addr) && (flags & > PS_SHOW_PORT_IF_DEFINED))) > - && port) > - { > - if (separator) > - buf_printf (&out, "%s", separator); > - > - buf_printf (&out, "%d", port); > - } > - } > + port= ntohs (addr->addr.in4.sin_port); > + buf_puts (&out, "[AF_INET]"); > + salen = sizeof (struct sockaddr_in); > break; > case AF_INET6: > - { > - const int port= ntohs (addr->addr.in6.sin6_port); > - char buf[INET6_ADDRSTRLEN] = ""; > - buf_puts (&out, "[AF_INET6]"); > - if (addr_is_defined) > - { > - getnameinfo(&addr->addr.sa, sizeof (struct sockaddr_in6), > - buf, sizeof (buf), NULL, 0, NI_NUMERICHOST); > - buf_puts (&out, buf); > - } > - if (((flags & PS_SHOW_PORT) || (addr_is_defined && (flags & > PS_SHOW_PORT_IF_DEFINED))) > - && port) > - { > - if (separator) > - buf_puts (&out, separator); > - > - buf_printf (&out, "%d", port); > - } > - } > + port= ntohs (addr->addr.in6.sin6_port); > + buf_puts (&out, "[AF_INET6]"); > + salen = sizeof (struct sockaddr_in6); > break; > default: > ASSERT(0); > } > + > + if (!(flags & PS_DONT_SHOW_ADDR)) > + { > + getnameinfo(&addr->addr.sa, salen, > + buf, sizeof (buf), NULL, 0, NI_NUMERICHOST); > + buf_puts (&out, buf); > + } > + if (((flags & PS_SHOW_PORT) || (addr_is_defined && (flags & > PS_SHOW_PORT_IF_DEFINED))) > + && port) > + { > + if (separator) > + buf_puts (&out, separator); > + > + buf_printf (&out, "%d", port); > + } > + > return BSTR (&out); > } > > -- > 1.7.9.6 (Apple Git-31.1) > > > ------------------------------------------------------------------------------ > Live Security Virtual Conference > Exclusive live event will cover all the ways today's security and > threat landscape has changed and how IT managers can respond. Discussions > will include endpoint security, mobile security and the latest in malware > threats. http://www.accelacomm.com/jaw/sfrnl04242012/114/50122263/ > _______________________________________________ > Openvpn-devel mailing list > Openvpn-devel@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/openvpn-devel > -- USENET is *not* the non-clickable part of WWW! //www.muc.de/~gert/ Gert Doering - Munich, Germany g...@greenie.muc.de fax: +49-89-35655025 g...@net.informatik.tu-muenchen.de
pgplwXfgIXDeK.pgp
Description: PGP signature