Back to index

glibc  2.9
ifreq.c
Go to the documentation of this file.
00001 /* Fetch the host's network interface list.  Hurd version.
00002    Copyright (C) 2002,2005 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 <ifreq.h>
00021 #include <hurd.h>
00022 #include <hurd/pfinet.h>
00023 #include <sys/mman.h>
00024 
00025 
00026 void
00027 __ifreq (struct ifreq **ifreqs, int *num_ifs, int sockfd)
00028 {
00029   file_t server;
00030 
00031   server = _hurd_socket_server (PF_INET, 0);
00032   if (server == MACH_PORT_NULL)
00033     {
00034     out:
00035       *num_ifs = 0;
00036       *ifreqs = NULL;
00037     }
00038   else
00039     {
00040       char *data = NULL;
00041       size_t len = 0;
00042       error_t err = __pfinet_siocgifconf (server, -1, &data, &len);
00043       if (err == MACH_SEND_INVALID_DEST || err == MIG_SERVER_DIED)
00044        {
00045          /* On the first use of the socket server during the operation,
00046             allow for the old server port dying.  */
00047          server = _hurd_socket_server (PF_INET, 1);
00048          if (server == MACH_PORT_NULL)
00049            goto out;
00050          err = __pfinet_siocgifconf (server, -1, (data_t *) ifreqs, &len);
00051        }
00052       if (err)
00053        goto out;
00054 
00055       if (len % sizeof (struct ifreq) != 0)
00056        {
00057          munmap (data, len);
00058          errno = EGRATUITOUS;
00059          goto out;
00060        }
00061       *num_ifs = len / sizeof (struct ifreq);
00062       *ifreqs = (struct ifreq *) data;
00063     }
00064 
00065 }