libexplain  1.4.D001
libexplain/buffer/eaddrinuse.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/eaddrinuse.h>
00022 #include <libexplain/buffer/gettext.h>
00023 
00024 
00025 void
00026 explain_buffer_eaddrinuse(explain_string_buffer_t *sb, int fildes)
00027 {
00028     int             reuseaddr;
00029     socklen_t       optlen;
00030 
00031     explain_buffer_gettext
00032     (
00033         sb,
00034         /*
00035          * xgettext: This message is used as an explanation for an
00036          * EADDRINUSE error.  See connect(2) and bind(2) for more
00037          * information.
00038          */
00039         i18n("local address is already in use; or, the address was in "
00040         "use very recently")
00041     );
00042     optlen = sizeof(reuseaddr);
00043     if
00044     (
00045         getsockopt(fildes, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, &optlen) < 0
00046     ||
00047         !reuseaddr
00048     )
00049     {
00050         /*
00051          * Linux will only allow port re-use with the SO_REUSEADDR
00052          * option when this option was set both in the previous program
00053          * that performed a bind(2) to the port and in the program that
00054          * wants to re-use the port.
00055          *
00056          * Other unix dialects only require that the re-user use this
00057          * option.
00058          */
00059         explain_string_buffer_puts(sb, ", ");
00060         explain_buffer_gettext
00061         (
00062             sb,
00063             /*
00064              * xgettext: This message is used when and EADDRINUSE error
00065              * is seen, and the socket does not have the SO_REUSEADDR
00066              * socket option enabled.  See socket(7) for more information.
00067              */
00068             i18n("the SO_REUSEADDR socket option can be used to shorten "
00069             "the wait")
00070         );
00071     }
00072 }
00073 
00074 
00075 /* vim: set ts=8 sw=4 et : */