X-Git-Url: https://git.gag.com/?a=blobdiff_plain;ds=sidebyside;f=common-src%2Fsockaddr-util.c;h=28da531239f1a3807a19ae004c11df5514b1971a;hb=d28952249e392eb31bc8eecc53f6c477f30c617b;hp=ffbc32ecf18fc7b10fc1014b93631baa532f6418;hpb=b116e9366c7b2ea2c2eb53b0a13df4090e176235;p=debian%2Famanda diff --git a/common-src/sockaddr-util.c b/common-src/sockaddr-util.c index ffbc32e..28da531 100644 --- a/common-src/sockaddr-util.c +++ b/common-src/sockaddr-util.c @@ -1,9 +1,10 @@ /* - * Copyright (c) 2007, 2008, 2010 Zmanda, Inc. All Rights Reserved. + * Copyright (c) 2007-2012 Zmanda, Inc. All Rights Reserved. * - * This program is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 as published - * by the Free Software Foundation. + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. * * This program is distributed in the hope that it will be useful, but * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY @@ -85,7 +86,31 @@ str_sockaddr( { inet_ntop(AF_INET, &sa->sin.sin_addr.s_addr, ipstr, sizeof(ipstr)); } - g_snprintf(mystr_sockaddr,sizeof(mystr_sockaddr),"%s.%d", ipstr, port); + g_snprintf(mystr_sockaddr,sizeof(mystr_sockaddr),"%s:%d", ipstr, port); + mystr_sockaddr[sizeof(mystr_sockaddr)-1] = '\0'; + + return mystr_sockaddr; +} + +char * +str_sockaddr_no_port( + sockaddr_union *sa) +{ +#ifdef WORKING_IPV6 + char ipstr[INET6_ADDRSTRLEN]; +#else + char ipstr[INET_ADDRSTRLEN]; +#endif + +#ifdef WORKING_IPV6 + if ( SU_GET_FAMILY(sa) == AF_INET6) { + inet_ntop(AF_INET6, &sa->sin6.sin6_addr, ipstr, sizeof(ipstr)); + } else +#endif + { + inet_ntop(AF_INET, &sa->sin.sin_addr.s_addr, ipstr, sizeof(ipstr)); + } + g_snprintf(mystr_sockaddr,sizeof(mystr_sockaddr),"%s", ipstr); mystr_sockaddr[sizeof(mystr_sockaddr)-1] = '\0'; return mystr_sockaddr;