libexplain  1.4.D001
libexplain/buffer/npioctl.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2010, 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_ppp.h>
00020 #include <libexplain/ac/net/ppp_defs.h>
00021 
00022 #include <libexplain/buffer/npioctl.h>
00023 #include <libexplain/buffer/pointer.h>
00024 #include <libexplain/parse_bits.h>
00025 #include <libexplain/is_efault.h>
00026 #include <libexplain/sizeof.h>
00027 
00028 
00029 #ifdef HAVE_NET_IF_PPP_H
00030 
00031 
00032 static void
00033 explain_buffer_npioctl_protocol(explain_string_buffer_t *sb, int value)
00034 {
00035     static const explain_parse_bits_table_t table[] =
00036     {
00037         { "PPP_IP", PPP_IP },
00038         { "PPP_AT", PPP_AT },
00039         { "PPP_IPX", PPP_IPX },
00040         { "PPP_VJC_COMP", PPP_VJC_COMP },
00041         { "PPP_VJC_UNCOMP", PPP_VJC_UNCOMP },
00042         { "PPP_MP", PPP_MP },
00043         { "PPP_IPV6", PPP_IPV6 },
00044         { "PPP_COMPFRAG", PPP_COMPFRAG },
00045         { "PPP_COMP", PPP_COMP },
00046         { "PPP_MPLS_UC", PPP_MPLS_UC },
00047         { "PPP_MPLS_MC", PPP_MPLS_MC },
00048         { "PPP_IPCP", PPP_IPCP },
00049         { "PPP_ATCP", PPP_ATCP },
00050         { "PPP_IPXCP", PPP_IPXCP },
00051         { "PPP_IPV6CP", PPP_IPV6CP },
00052         { "PPP_CCPFRAG", PPP_CCPFRAG },
00053         { "PPP_CCP", PPP_CCP },
00054         { "PPP_MPLSCP", PPP_MPLSCP },
00055         { "PPP_LCP", PPP_LCP },
00056         { "PPP_PAP", PPP_PAP },
00057         { "PPP_LQR", PPP_LQR },
00058         { "PPP_CHAP", PPP_CHAP },
00059         { "PPP_CBCP", PPP_CBCP },
00060     };
00061 
00062     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00063 }
00064 
00065 
00066 static void
00067 explain_buffer_npioctl_mode(explain_string_buffer_t *sb, int value)
00068 {
00069     static const explain_parse_bits_table_t table[] =
00070     {
00071         { "NPMODE_PASS", NPMODE_PASS },
00072         { "NPMODE_DROP", NPMODE_DROP },
00073         { "NPMODE_ERROR", NPMODE_ERROR },
00074         { "NPMODE_QUEUE", NPMODE_QUEUE },
00075     };
00076 
00077     explain_parse_bits_print_single(sb, value, table, SIZEOF(table));
00078 }
00079 
00080 
00081 void
00082 explain_buffer_npioctl(explain_string_buffer_t *sb, const struct npioctl *data,
00083     int complete)
00084 {
00085     if (explain_is_efault_pointer(data, sizeof(*data)))
00086     {
00087         explain_buffer_pointer(sb, data);
00088         return;
00089     }
00090 
00091     explain_string_buffer_puts(sb, "{ protocol = ");
00092     explain_buffer_npioctl_protocol(sb, data->protocol);
00093     if (complete)
00094     {
00095         explain_string_buffer_puts(sb, ", mode = ");
00096         explain_buffer_npioctl_mode(sb, data->mode);
00097     }
00098     explain_string_buffer_puts(sb, " }");
00099 }
00100 
00101 
00102 #else
00103 
00104 
00105 void
00106 explain_buffer_npioctl(explain_string_buffer_t *sb, const struct npioctl *data,
00107     int complete)
00108 {
00109     (void)complete;
00110     explain_buffer_pointer(sb, data);
00111 }
00112 
00113 
00114 #endif
00115 
00116 
00117 /* vim: set ts=8 sw=4 et : */