libexplain  1.4.D001
libexplain/buffer/ifreq_settings.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2009, 2011, 2013 Peter Miller
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU Lesser General Public License as
00007  * published by the Free Software Foundation; either version 3 of the
00008  * License, or (at your option) any later version.
00009  *
00010  * This program 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 License
00016  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00017  */
00018 
00019 #include <libexplain/ac/sys/socket.h>
00020 #include <libexplain/ac/linux/if.h>
00021 #ifndef HAVE_LINUX_IF_H
00022 #include <libexplain/ac/net/if.h>
00023 #endif
00024 
00025 #include <libexplain/buffer/ifreq_settings.h>
00026 #include <libexplain/buffer/pointer.h>
00027 #include <libexplain/is_efault.h>
00028 
00029 
00030 #ifdef HAVE_LINUX_IF_H
00031 
00032 static void
00033 explain_buffer_if_settings(explain_string_buffer_t *sb,
00034     const struct if_settings *data)
00035 {
00036     explain_string_buffer_printf
00037     (
00038         sb,
00039         "{ type = %u, size = %u }",
00040         data->type,
00041         data->size
00042     );
00043 }
00044 
00045 #endif
00046 
00047 void
00048 explain_buffer_ifreq_settings(explain_string_buffer_t *sb,
00049     const struct ifreq *data)
00050 {
00051     if (explain_is_efault_pointer(data, sizeof(*data)))
00052         explain_buffer_pointer(sb, data);
00053     else
00054     {
00055         const struct ifreq *ifr;
00056 
00057         /*
00058          * This is actually a huge big sucky union.  This specific case
00059          * is given the interface name and the settings.
00060          */
00061         ifr = data;
00062         explain_string_buffer_puts(sb, "{ ifr_name = ");
00063         explain_string_buffer_puts_quoted_n
00064         (
00065             sb,
00066             ifr->ifr_name,
00067             sizeof(ifr->ifr_name)
00068         );
00069 #ifdef HAVE_LINUX_IF_H
00070         explain_string_buffer_puts(sb, ", ifr_settings = ");
00071 #if 0
00072         explain_buffer_if_settings(sb, &ifr->ifr_settings);
00073 #else
00074         /*
00075          * Mysteriously, not all <net/if.h> files have irf->ifr_settings.
00076          * This is happening on Linux 32-bits vs 64-bits.  FIIK.
00077          */
00078         explain_buffer_if_settings
00079         (
00080             sb,
00081             (const struct if_settings *)&ifr->ifr_ifru
00082         );
00083 #endif
00084 #endif
00085         explain_string_buffer_puts(sb, " }");
00086     }
00087 }
00088 
00089 
00090 /* vim: set ts=8 sw=4 et : */