libexplain  1.4.D001
libexplain/buffer/siocethtool.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 #include <libexplain/ac/linux/ethtool.h>
00021 
00022 #include <libexplain/buffer/pointer.h>
00023 #include <libexplain/buffer/siocethtool.h>
00024 #include <libexplain/parse_bits.h>
00025 #include <libexplain/is_efault.h>
00026 #include <libexplain/sizeof.h>
00027 
00028 
00029 #ifdef HAVE_LINUX_ETHTOOL_H
00030 
00031 void
00032 explain_buffer_siocethtool(explain_string_buffer_t *sb, const struct ifreq *ifr)
00033 {
00034     if (explain_is_efault_pointer(ifr, sizeof(*ifr)))
00035         explain_buffer_pointer(sb, ifr);
00036     else
00037     {
00038         explain_string_buffer_puts(sb, "{ ifr_name = ");
00039         explain_string_buffer_puts_quoted_n
00040         (
00041             sb,
00042             ifr->ifr_name,
00043             sizeof(ifr->ifr_name)
00044         );
00045         explain_string_buffer_puts(sb, ", ifr_data = ");
00046         if
00047         (
00048             explain_is_efault_pointer
00049             (
00050                 ifr->ifr_data,
00051                 sizeof(struct ethtool_cmd)
00052             )
00053         )
00054         {
00055             explain_buffer_pointer(sb, ifr->ifr_data);
00056         }
00057         else
00058         {
00059             static const explain_parse_bits_table_t table[] =
00060             {
00061                 { "ETHTOOL_GDRVINFO", ETHTOOL_GDRVINFO },
00062                 { "ETHTOOL_GMSGLVL", ETHTOOL_GMSGLVL },
00063                 { "ETHTOOL_GCOALESCE", ETHTOOL_GCOALESCE },
00064                 { "ETHTOOL_GRINGPARAM", ETHTOOL_GRINGPARAM },
00065                 { "ETHTOOL_GPAUSEPARAM", ETHTOOL_GPAUSEPARAM },
00066                 { "ETHTOOL_GRXCSUM", ETHTOOL_GRXCSUM },
00067                 { "ETHTOOL_GTXCSUM", ETHTOOL_GTXCSUM },
00068                 { "ETHTOOL_GSG", ETHTOOL_GSG },
00069                 { "ETHTOOL_GSTRINGS", ETHTOOL_GSTRINGS },
00070                 { "ETHTOOL_GTSO", ETHTOOL_GTSO },
00071 #ifdef ETHTOOL_GPERMADDR
00072                 { "ETHTOOL_GPERMADDR", ETHTOOL_GPERMADDR },
00073 #endif
00074 #ifdef ETHTOOL_GUFO
00075                 { "ETHTOOL_GUFO", ETHTOOL_GUFO },
00076 #endif
00077 #ifdef ETHTOOL_GGSO
00078                 { "ETHTOOL_GGSO", ETHTOOL_GGSO },
00079 #endif
00080 #ifdef ETHTOOL_GFLAGS
00081                 { "ETHTOOL_GFLAGS", ETHTOOL_GFLAGS },
00082 #endif
00083 #ifdef ETHTOOL_GPFLAGS
00084                 { "ETHTOOL_GPFLAGS", ETHTOOL_GPFLAGS },
00085 #endif
00086 #ifdef ETHTOOL_GRXFH
00087                 { "ETHTOOL_GRXFH", ETHTOOL_GRXFH },
00088 #endif
00089             };
00090             const struct ethtool_cmd *etp;
00091 
00092             etp = (const struct ethtool_cmd *)ifr->ifr_data;
00093             explain_string_buffer_puts(sb, "{ cmd = ");
00094             explain_parse_bits_print_single
00095             (
00096                 sb,
00097                 etp->cmd,
00098                 table,
00099                 SIZEOF(table)
00100             );
00101             explain_string_buffer_puts(sb, " }");
00102         }
00103         explain_string_buffer_puts(sb, " }");
00104     }
00105 }
00106 
00107 #else
00108 
00109 void
00110 explain_buffer_siocethtool(explain_string_buffer_t *sb, const struct ifreq *ifr)
00111 {
00112     explain_buffer_pointer(sb, ifr);
00113 }
00114 
00115 #endif
00116 
00117 
00118 /* vim: set ts=8 sw=4 et : */