libexplain
1.4.D001
|
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 it 00006 * under the terms of the GNU Lesser General Public License as published by 00007 * the Free Software Foundation; either version 3 of the License, or (at 00008 * your option) any later version. 00009 * 00010 * This program is distributed in the hope that it will be useful,but 00011 * WITHOUT ANY WARRANTY; without even the implied warranty 00012 * ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNULesser 00013 * 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/errno.h> 00020 00021 #include <libexplain/buffer/accept4_flags.h> 00022 #include <libexplain/buffer/eagain.h> 00023 #include <libexplain/buffer/ebadf.h> 00024 #include <libexplain/buffer/econnaborted.h> 00025 #include <libexplain/buffer/efault.h> 00026 #include <libexplain/buffer/ehostdown.h> 00027 #include <libexplain/buffer/ehostunreach.h> 00028 #include <libexplain/buffer/eintr.h> 00029 #include <libexplain/buffer/einval.h> 00030 #include <libexplain/buffer/emfile.h> 00031 #include <libexplain/buffer/enetdown.h> 00032 #include <libexplain/buffer/enetunreach.h> 00033 #include <libexplain/buffer/enfile.h> 00034 #include <libexplain/buffer/enobufs.h> 00035 #include <libexplain/buffer/enomem.h> 00036 #include <libexplain/buffer/enonet.h> 00037 #include <libexplain/buffer/enoprotoopt.h> 00038 #include <libexplain/buffer/enosr.h> 00039 #include <libexplain/buffer/enosys.h> 00040 #include <libexplain/buffer/enotsock.h> 00041 #include <libexplain/buffer/eperm.h> 00042 #include <libexplain/buffer/eproto.h> 00043 #include <libexplain/buffer/eprotonosupport.h> 00044 #include <libexplain/buffer/erestart.h> 00045 #include <libexplain/buffer/errno/accept4.h> 00046 #include <libexplain/buffer/errno/generic.h> 00047 #include <libexplain/buffer/esocktnosupport.h> 00048 #include <libexplain/buffer/etimedout.h> 00049 #include <libexplain/buffer/fildes.h> 00050 #include <libexplain/buffer/pointer.h> 00051 #include <libexplain/buffer/socklen.h> 00052 #include <libexplain/explanation.h> 00053 #include <libexplain/is_efault.h> 00054 00055 00056 static void 00057 explain_buffer_errno_accept4_system_call(explain_string_buffer_t *sb, int 00058 errnum, int fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size, 00059 int flags) 00060 { 00061 (void)errnum; 00062 explain_string_buffer_puts(sb, "accept4(fildes = "); 00063 explain_buffer_fildes(sb, fildes); 00064 explain_string_buffer_puts(sb, ", sock_addr = "); 00065 explain_buffer_pointer(sb, sock_addr); 00066 explain_string_buffer_puts(sb, ", sock_addr_size = "); 00067 explain_buffer_socklen_star(sb, sock_addr_size); 00068 explain_string_buffer_puts(sb, ", flags = "); 00069 explain_buffer_accept4_flags(sb, flags); 00070 explain_string_buffer_putc(sb, ')'); 00071 } 00072 00073 00074 static void 00075 explain_buffer_errno_accept4_explanation(explain_string_buffer_t *sb, 00076 int errnum, int fildes, struct sockaddr *sock_addr, 00077 socklen_t *sock_addr_size, int flags) 00078 { 00079 /* 00080 * http://www.opengroup.org/onlinepubs/009695399/functions/accept4.html 00081 */ 00082 (void)sock_addr; 00083 (void)flags; 00084 switch (errnum) 00085 { 00086 case EAGAIN: 00087 #if defined(EWOULDBLOCK) && EWOULDBLOCK != EAGAIN 00088 case EWOULDBLOCK: 00089 #endif 00090 explain_buffer_eagain_accept(sb); 00091 break; 00092 00093 case EBADF: 00094 explain_buffer_ebadf(sb, fildes, "fildes"); 00095 break; 00096 00097 case ECONNABORTED: 00098 explain_buffer_econnaborted(sb); 00099 break; 00100 00101 case EFAULT: 00102 if (explain_is_efault_pointer(sock_addr_size, sizeof(*sock_addr_size))) 00103 explain_buffer_efault(sb, "sock_addr_size"); 00104 else 00105 explain_buffer_efault(sb, "sock_addr"); 00106 break; 00107 00108 case EHOSTDOWN: 00109 explain_buffer_ehostdown(sb); 00110 break; 00111 00112 case EHOSTUNREACH: 00113 explain_buffer_ehostunreach(sb); 00114 break; 00115 00116 case EINTR: 00117 explain_buffer_eintr(sb, "accept4"); 00118 break; 00119 00120 case EINVAL: 00121 if 00122 ( 00123 !explain_is_efault_pointer 00124 ( 00125 sock_addr_size, 00126 sizeof(*sock_addr_size) 00127 ) 00128 && 00129 *sock_addr_size <= 0 00130 ) 00131 { 00132 explain_buffer_einval_too_small 00133 ( 00134 sb, 00135 "sock_addr_size", 00136 *sock_addr_size 00137 ); 00138 break; 00139 } 00140 explain_buffer_einval_not_listening(sb); 00141 break; 00142 00143 case EMFILE: 00144 explain_buffer_emfile(sb); 00145 break; 00146 00147 case ENETDOWN: 00148 explain_buffer_enetdown(sb); 00149 break; 00150 00151 case ENETUNREACH: 00152 explain_buffer_enetunreach(sb); 00153 break; 00154 00155 case ENFILE: 00156 explain_buffer_enfile(sb); 00157 break; 00158 00159 case ENOBUFS: 00160 explain_buffer_enobufs(sb); 00161 break; 00162 00163 case ENOMEM: 00164 explain_buffer_enomem_kernel(sb); 00165 break; 00166 00167 #ifdef ENONET 00168 case ENONET: 00169 explain_buffer_enonet(sb); 00170 break; 00171 #endif 00172 00173 case ENOPROTOOPT: 00174 explain_buffer_enoprotoopt(sb, "flags"); 00175 break; 00176 00177 case ENOTSOCK: 00178 explain_buffer_enotsock(sb, fildes, "fildes"); 00179 break; 00180 00181 case ENOSYS: 00182 #if defined(EOPNOTSUPP) && EOPNOTSUPP != ENOSYS 00183 case EOPNOTSUPP: 00184 #endif 00185 explain_buffer_enosys_socket(sb, "accept4", fildes); 00186 break; 00187 00188 #ifdef ENOSR 00189 case ENOSR: 00190 explain_buffer_enosr(sb); 00191 break; 00192 #endif 00193 00194 case EPERM: 00195 explain_buffer_eperm_accept(sb); 00196 break; 00197 00198 #ifdef EPROTO 00199 case EPROTO: 00200 explain_buffer_eproto_accept(sb, fildes); 00201 break; 00202 #endif 00203 00204 case EPROTONOSUPPORT: 00205 explain_buffer_eprotonosupport(sb); 00206 break; 00207 00208 #ifdef ERESTART 00209 case ERESTART: 00210 explain_buffer_erestart(sb, "accept4"); 00211 break; 00212 #endif 00213 00214 case ESOCKTNOSUPPORT: 00215 explain_buffer_esocktnosupport(sb, "accept4", fildes); 00216 break; 00217 00218 case ETIMEDOUT: 00219 explain_buffer_etimedout(sb, "accept4"); 00220 break; 00221 00222 default: 00223 explain_buffer_errno_generic(sb, errnum, "accept4"); 00224 break; 00225 } 00226 } 00227 00228 00229 void 00230 explain_buffer_errno_accept4(explain_string_buffer_t *sb, int errnum, int 00231 fildes, struct sockaddr *sock_addr, socklen_t *sock_addr_size, int flags) 00232 { 00233 explain_explanation_t exp; 00234 00235 explain_explanation_init(&exp, errnum); 00236 explain_buffer_errno_accept4_system_call(&exp.system_call_sb, errnum, 00237 fildes, sock_addr, sock_addr_size, flags); 00238 explain_buffer_errno_accept4_explanation(&exp.explanation_sb, errnum, 00239 fildes, sock_addr, sock_addr_size, flags); 00240 explain_explanation_assemble(&exp, sb); 00241 } 00242 00243 00244 /* vim: set ts=8 sw=4 et : */