1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
samba-mirror/lib/replace/test/getifaddrs.c
David Disseldorp 8a6743e4ed Bug 8997: change libreplace GPL source to LGPL
libreplace currently includes socket.c and getifaddrs.c both of which
are GPL licensed.
Although not required, talloc and tdb build alongside this source,
leading to some ambiguity regarding their LGPL licences.

The following copyright holders have agreed to the GPL->LGPL change:
lib/replace/getifaddrs.c
   Copyright (C) Andrew Tridgell 1998
   Copyright (C) Jeremy Allison 2007
   Copyright (C) Jelmer Vernooij <jelmer@samba.org> 2007

lib/replace/test/getifaddrs.c
lib/replace/socket.c
 * Copyright (C) Michael Adam <obnox@samba.org> 2008

Signed-off-by: David Disseldorp <ddiss@samba.org>

Reviewed-by: Andrew Bartlett <abartlet@samba.org>

Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Mon Jun  3 18:06:18 CEST 2013 on sn-devel-104
2013-06-03 18:06:18 +02:00

106 lines
2.5 KiB
C

/*
* Unix SMB/CIFS implementation.
*
* libreplace getifaddrs test
*
* Copyright (C) Michael Adam <obnox@samba.org> 2008
*
* ** NOTE! The following LGPL license applies to the replace
* ** library. This does NOT imply that all of Samba is released
* ** under the LGPL
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, see <http://www.gnu.org/licenses/>.
*/
#ifndef AUTOCONF_TEST
#include "replace.h"
#include "system/network.h"
#include "replace-test.h"
#endif
#ifdef HAVE_INET_NTOP
#define rep_inet_ntop inet_ntop
#endif
static const char *format_sockaddr(struct sockaddr *addr,
char *addrstring,
socklen_t addrlen)
{
const char *result = NULL;
if (addr->sa_family == AF_INET) {
result = rep_inet_ntop(AF_INET,
&((struct sockaddr_in *)addr)->sin_addr,
addrstring,
addrlen);
#ifdef HAVE_STRUCT_SOCKADDR_IN6
} else if (addr->sa_family == AF_INET6) {
result = rep_inet_ntop(AF_INET6,
&((struct sockaddr_in6 *)addr)->sin6_addr,
addrstring,
addrlen);
#endif
}
return result;
}
int getifaddrs_test(void)
{
struct ifaddrs *ifs = NULL;
struct ifaddrs *ifs_head = NULL;
int ret;
ret = getifaddrs(&ifs);
ifs_head = ifs;
if (ret != 0) {
fprintf(stderr, "getifaddrs() failed: %s\n", strerror(errno));
return 1;
}
while (ifs) {
printf("%-10s ", ifs->ifa_name);
if (ifs->ifa_addr != NULL) {
char addrstring[INET6_ADDRSTRLEN];
const char *result;
result = format_sockaddr(ifs->ifa_addr,
addrstring,
sizeof(addrstring));
if (result != NULL) {
printf("IP=%s ", addrstring);
}
if (ifs->ifa_netmask != NULL) {
result = format_sockaddr(ifs->ifa_netmask,
addrstring,
sizeof(addrstring));
if (result != NULL) {
printf("NETMASK=%s", addrstring);
}
} else {
printf("AF=%d ", ifs->ifa_addr->sa_family);
}
} else {
printf("<no address>");
}
printf("\n");
ifs = ifs->ifa_next;
}
freeifaddrs(ifs_head);
return 0;
}