libexplain  1.4.D001
libexplain/buffer/rtentry.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/route.h>
00020 
00021 #include <libexplain/buffer/int.h>
00022 #include <libexplain/buffer/long.h>
00023 #include <libexplain/buffer/pathname.h>
00024 #include <libexplain/buffer/pointer.h>
00025 #include <libexplain/buffer/rtentry.h>
00026 #include <libexplain/buffer/sockaddr.h>
00027 #include <libexplain/parse_bits.h>
00028 #include <libexplain/is_efault.h>
00029 #include <libexplain/sizeof.h>
00030 
00031 #if defined(SIOCADDRT) || defined(SIOCDELRT) || defined(SIOCRTMSG)
00032 
00033 static void
00034 explain_buffer_rtentry_flags(explain_string_buffer_t *sb, int flags)
00035 {
00036     static const explain_parse_bits_table_t table[] =
00037     {
00038 #ifdef RTF_UP
00039         { "RTF_UP", RTF_UP },
00040 #endif
00041 #ifdef RTF_GATEWAY
00042         { "RTF_GATEWAY", RTF_GATEWAY },
00043 #endif
00044 #ifdef RTF_HOST
00045         { "RTF_HOST", RTF_HOST },
00046 #endif
00047 #ifdef RTF_REINSTATE
00048         { "RTF_REINSTATE", RTF_REINSTATE },
00049 #endif
00050 #ifdef RTF_DYNAMIC
00051         { "RTF_DYNAMIC", RTF_DYNAMIC },
00052 #endif
00053 #ifdef RTF_MODIFIED
00054         { "RTF_MODIFIED", RTF_MODIFIED },
00055 #endif
00056 #ifdef RTF_MTU
00057         { "RTF_MTU", RTF_MTU },
00058 #endif
00059 #ifdef RTF_WINDOW
00060         { "RTF_WINDOW", RTF_WINDOW },
00061 #endif
00062 #ifdef RTF_IRTT
00063         { "RTF_IRTT", RTF_IRTT },
00064 #endif
00065 #ifdef RTF_REJECT
00066         { "RTF_REJECT", RTF_REJECT },
00067 #endif
00068     };
00069 
00070     explain_parse_bits_print(sb, flags, table, SIZEOF(table));
00071 }
00072 
00073 
00074 void
00075 explain_buffer_rtentry(explain_string_buffer_t *sb,
00076     const struct rtentry *data)
00077 {
00078     if (explain_is_efault_pointer(data, sizeof(*data)))
00079     {
00080         explain_buffer_pointer(sb, data);
00081         return;
00082     }
00083 
00084     explain_string_buffer_puts(sb, "{ rt_gateway = ");
00085 #ifndef __linux__
00086     explain_buffer_sockaddr(sb, data->rt_gateway, sizeof(*data->rt_gateway));
00087 #else
00088     explain_buffer_sockaddr(sb, &data->rt_gateway, sizeof(data->rt_gateway));
00089     explain_string_buffer_puts(sb, ", rt_dst = ");
00090     explain_buffer_sockaddr(sb, &data->rt_dst, sizeof(data->rt_dst));
00091     explain_string_buffer_puts(sb, ", rt_genmask = ");
00092     explain_buffer_sockaddr(sb, &data->rt_genmask, sizeof(data->rt_genmask));
00093 #endif
00094     explain_string_buffer_puts(sb, ", rt_flags = ");
00095     explain_buffer_rtentry_flags(sb, data->rt_flags);
00096 #ifdef __linux__
00097     explain_string_buffer_puts(sb, ", rt_metric = ");
00098     explain_buffer_int(sb, data->rt_metric);
00099     explain_string_buffer_puts(sb, ", rt_dev = ");
00100     explain_buffer_pathname(sb, data->rt_dev);
00101     explain_string_buffer_puts(sb, ", rt_mtu = ");
00102     explain_buffer_long(sb, data->rt_mtu);
00103     explain_string_buffer_puts(sb, ", rt_window = ");
00104     explain_buffer_long(sb, data->rt_window);
00105     explain_string_buffer_puts(sb, ", rt_irtt = ");
00106     explain_buffer_int(sb, data->rt_irtt);
00107 #endif
00108     explain_string_buffer_puts(sb, " }");
00109 }
00110 
00111 #else
00112 
00113 void
00114 explain_buffer_rtentry(explain_string_buffer_t *sb,
00115     const struct rtentry *data)
00116 {
00117     explain_buffer_pointer(sb, data);
00118 }
00119 
00120 #endif
00121 
00122 
00123 /* vim: set ts=8 sw=4 et : */