Back to index

glibc  2.9
check_pf.c
Go to the documentation of this file.
00001 /* Determine protocol families for which interfaces exist.  Generic version.
00002    Copyright (C) 2003, 2006 Free Software Foundation, Inc.
00003    This file is part of the GNU C Library.
00004 
00005    The GNU C Library is free software; you can redistribute it and/or
00006    modify it under the terms of the GNU Lesser General Public
00007    License as published by the Free Software Foundation; either
00008    version 2.1 of the License, or (at your option) any later version.
00009 
00010    The GNU C Library is distributed in the hope that it will be useful,
00011    but WITHOUT ANY WARRANTY; without even the implied warranty of
00012    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00013    Lesser General Public License for more details.
00014 
00015    You should have received a copy of the GNU Lesser General Public
00016    License along with the GNU C Library; if not, write to the Free
00017    Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
00018    02111-1307 USA.  */
00019 
00020 #include <ifaddrs.h>
00021 #include <netdb.h>
00022 
00023 
00024 void
00025 attribute_hidden
00026 __check_pf (bool *seen_ipv4, bool *seen_ipv6,
00027            struct in6addrinfo **in6ai, size_t *in6ailen)
00028 {
00029   /* By default we have no way to determine information about
00030      deprecated and temporary addresses.  */
00031   *in6ai = NULL;
00032   *in6ailen = 0;
00033 
00034   /* Get the interface list via getifaddrs.  */
00035   struct ifaddrs *ifa = NULL;
00036   if (getifaddrs (&ifa) != 0)
00037     {
00038       /* We cannot determine what interfaces are available.  Be
00039         pessimistic.  */
00040       *seen_ipv4 = true;
00041       *seen_ipv6 = true;
00042       return;
00043     }
00044 
00045   *seen_ipv4 = false;
00046   *seen_ipv6 = false;
00047 
00048   struct ifaddrs *runp;
00049   for (runp = ifa; runp != NULL; runp = runp->ifa_next)
00050     if (runp->ifa_addr->sa_family == PF_INET)
00051       *seen_ipv4 = true;
00052     else if (runp->ifa_addr->sa_family == PF_INET6)
00053       *seen_ipv6 = true;
00054 
00055   (void) freeifaddrs (ifa);
00056 }