libexplain  1.4.D001
libexplain/buffer/eafnosupport.c
Go to the documentation of this file.
00001 /*
00002  * libexplain - Explain errno values returned by libc functions
00003  * Copyright (C) 2008, 2009, 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/sys/socket.h>
00020 
00021 #include <libexplain/buffer/address_family.h>
00022 #include <libexplain/buffer/eafnosupport.h>
00023 #include <libexplain/fildes_to_address_family.h>
00024 
00025 
00026 void
00027 explain_buffer_eafnosupport(explain_string_buffer_t *sb, int fildes,
00028     const char *fildes_caption, const struct sockaddr *sock_addr,
00029     const char *sock_addr_caption)
00030 {
00031     int             fildes_af;
00032 
00033     (void)sock_addr;
00034     fildes_af = explain_fildes_to_address_family(fildes);
00035     if (fildes_af >= 0)
00036     {
00037         char            aftxt[30];
00038         explain_string_buffer_t aftxt_sb;
00039 
00040         explain_string_buffer_init(&aftxt_sb, aftxt, sizeof(aftxt));
00041         explain_buffer_address_family(&aftxt_sb, fildes_af);
00042         explain_string_buffer_printf_gettext
00043         (
00044             sb,
00045             /*
00046              * xgettext: This message is used when socket(2) and
00047              * {bind(2) or connect(2)} disagree about the file
00048              * descriptor's address family.
00049              *
00050              * %1$s => The name of the system call argument containing
00051              *         the sockaddr with the erroneous address family.
00052              * %2$s => The name of the system call argument
00053              *         containing the socket file descriptor.
00054              * %3$s => The value of the socket file descriptor's
00055              *         address family, as obtained from the file
00056              *         descriptor itself.
00057              */
00058             i18n("%s does not have the correct address family, "
00059                 "%s address family is %s"),
00060             sock_addr_caption,
00061             fildes_caption,
00062             aftxt
00063         );
00064     }
00065     else
00066     {
00067         explain_string_buffer_printf_gettext
00068         (
00069             sb,
00070             /*
00071              * xgettext: This message is used when socket() and
00072              * connect() disagree about the file descriptor's
00073              * address family.  It is used when the file
00074              * descriptor's actual address family cannot be
00075              * determined.
00076              *
00077              * %1$s => The name of the system call argument containing
00078              *         the sockaddr with the erroneous address family.
00079              * %2$s => The name of the system call argument containing
00080              *         the file descriptor with the other address family.
00081              */
00082             i18n("%s does not have the same address family as %s"),
00083             sock_addr_caption,
00084             fildes_caption
00085         );
00086     }
00087 }
00088 
00089 
00090 /* vim: set ts=8 sw=4 et : */