libexplain  1.4.D001
libexplain/buffer/ifreq_flags.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/net/if.h>
00020 
00021 #include <libexplain/buffer/ifreq_flags.h>
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/parse_bits.h>
00024 #include <libexplain/is_efault.h>
00025 #include <libexplain/sizeof.h>
00026 
00027 static void
00028 explain_buffer_ifflags(explain_string_buffer_t *sb, int flags)
00029 {
00030     static const explain_parse_bits_table_t table[] =
00031     {
00032         { "IFF_UP", IFF_UP },
00033         { "IFF_BROADCAST", IFF_BROADCAST },
00034         { "IFF_DEBUG", IFF_DEBUG },
00035         { "IFF_LOOPBACK", IFF_LOOPBACK },
00036         { "IFF_POINTOPOINT", IFF_POINTOPOINT },
00037 #ifdef IFF_NOTRAILERS
00038         { "IFF_NOTRAILERS", IFF_NOTRAILERS },
00039 #endif
00040         { "IFF_RUNNING", IFF_RUNNING },
00041         { "IFF_NOARP", IFF_NOARP },
00042         { "IFF_PROMISC", IFF_PROMISC },
00043         { "IFF_ALLMULTI", IFF_ALLMULTI },
00044 #ifdef IFF_MASTER
00045         { "IFF_MASTER", IFF_MASTER },
00046 #endif
00047 #ifdef IFF_SLAVE
00048         { "IFF_SLAVE", IFF_SLAVE },
00049 #endif
00050         { "IFF_MULTICAST", IFF_MULTICAST },
00051 #ifdef IFF_PORTSEL
00052         { "IFF_PORTSEL", IFF_PORTSEL },
00053 #endif
00054 #ifdef IFF_AUTOMEDIA
00055         { "IFF_AUTOMEDIA", IFF_AUTOMEDIA },
00056 #endif
00057 #ifdef IFF_DYNAMIC
00058         { "IFF_DYNAMIC", IFF_DYNAMIC },
00059 #endif
00060     };
00061 
00062     explain_parse_bits_print(sb, flags, table, SIZEOF(table));
00063 }
00064 
00065 
00066 void
00067 explain_buffer_ifreq_flags(explain_string_buffer_t *sb,
00068     const struct ifreq *data)
00069 {
00070     if (explain_is_efault_pointer(data, sizeof(*data)))
00071         explain_buffer_pointer(sb, data);
00072     else
00073     {
00074         const struct ifreq *ifr;
00075 
00076         /*
00077          * This is actually a huge big sucky union.  This specific
00078          * case is given the interface name and the interface flags.
00079          */
00080         ifr = data;
00081         explain_string_buffer_puts(sb, "{ ifr_name = ");
00082         explain_string_buffer_puts_quoted_n
00083         (
00084             sb,
00085             ifr->ifr_name,
00086             sizeof(ifr->ifr_name)
00087         );
00088         explain_string_buffer_puts(sb, ", ifr_flags = ");
00089         explain_buffer_ifflags(sb, ifr->ifr_flags);
00090         explain_string_buffer_puts(sb, " }");
00091     }
00092 }
00093 
00094 
00095 /* vim: set ts=8 sw=4 et : */