libexplain  1.4.D001
libexplain/iocontrol/pppiocscompress.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  * Written by Peter Miller <pmiller@opensource.org.au>
00005  *
00006  * This program is free software; you can redistribute it and/or modify it
00007  * under the terms of the GNU Lesser General Public License as published by
00008  * the Free Software Foundation; either version 3 of the License, or (at your
00009  * option) any later version.
00010  *
00011  * This program is distributed in the hope that it will be useful, but WITHOUT
00012  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
00014  * License for more details.
00015  *
00016  * You should have received a copy of the GNU Lesser General Public License
00017  * along with this program. If not, see <http://www.gnu.org/licenses/>.
00018  */
00019 
00020 #include <libexplain/ac/errno.h>
00021 #include <libexplain/ac/net/if_ppp.h>
00022 #include <libexplain/ac/net/ppp-comp.h>
00023 #include <libexplain/ac/sys/ioctl.h>
00024 
00025 #include <libexplain/buffer/efault.h>
00026 #include <libexplain/buffer/einval.h>
00027 #include <libexplain/buffer/enobufs.h>
00028 #include <libexplain/buffer/ppp_option_data.h>
00029 #include <libexplain/iocontrol/generic.h>
00030 #include <libexplain/iocontrol/pppiocscompress.h>
00031 #include <libexplain/is_efault.h>
00032 
00033 #ifdef PPPIOCSCOMPRESS
00034 
00035 
00036 static void
00037 print_data(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00038     int errnum, int fildes, int request, const void *data)
00039 {
00040     (void)p;
00041     (void)errnum;
00042     (void)fildes;
00043     (void)request;
00044     explain_buffer_ppp_option_data(sb, data);
00045 }
00046 
00047 
00048 static void
00049 print_explanation(const explain_iocontrol_t *p, explain_string_buffer_t *sb,
00050     int errnum, int fildes, int request, const void *data)
00051 {
00052     const struct ppp_option_data *dp;
00053 
00054     /* Linux: drivers/net/ppp_generic.c */
00055     dp = data;
00056     switch (errnum)
00057     {
00058     case EFAULT:
00059         if (explain_is_efault_pointer(dp, sizeof(*dp)))
00060             explain_buffer_efault(sb, "data");
00061         else
00062             explain_buffer_efault(sb, "data->ptr");
00063         break;
00064 
00065     case EINVAL:
00066         if (dp->length > CCP_MAX_OPTION_LENGTH)
00067         {
00068             explain_buffer_einval_too_large(sb, "data->length");
00069             break;
00070         }
00071         if (dp->ptr[1] < 2)
00072         {
00073             explain_buffer_einval_too_small(sb, "data->ptr[1]", dp->ptr[1]);
00074             break;
00075         }
00076         if (dp->ptr[1] > dp->length)
00077         {
00078             explain_buffer_einval_too_large(sb, "data->ptr[2]");
00079             break;
00080         }
00081         explain_buffer_einval_vague(sb, "data");
00082         break;
00083 
00084     case ENOBUFS:
00085         explain_buffer_enobufs(sb);
00086         break;
00087 
00088     default:
00089         explain_iocontrol_generic_print_explanation
00090         (
00091             p,
00092             sb,
00093             errnum,
00094             fildes,
00095             request,
00096             data
00097         );
00098         break;
00099     }
00100 }
00101 
00102 
00103 const explain_iocontrol_t explain_iocontrol_pppiocscompress =
00104 {
00105     "PPPIOCSCOMPRESS", /* name */
00106     PPPIOCSCOMPRESS, /* value */
00107     0, /* disambiguate */
00108     0, /* print_name */
00109     print_data,
00110     print_explanation,
00111     0, /* print_data_returned */
00112     sizeof(struct ppp_option_data), /* data_size */
00113     "struct ppp_option_data *", /* data_type */
00114     0, /* flags */
00115     __FILE__,
00116     __LINE__,
00117 };
00118 
00119 #else /* ndef PPPIOCSCOMPRESS */
00120 
00121 const explain_iocontrol_t explain_iocontrol_pppiocscompress =
00122 {
00123     0, /* name */
00124     0, /* value */
00125     0, /* disambiguate */
00126     0, /* print_name */
00127     0, /* print_data */
00128     0, /* print_explanation */
00129     0, /* print_data_returned */
00130     0, /* data_size */
00131     0, /* data_type */
00132     0, /* flags */
00133     __FILE__,
00134     __LINE__,
00135 };
00136 
00137 #endif /* PPPIOCSCOMPRESS */
00138 
00139 
00140 /* vim: set ts=8 sw=4 et : */