]> git.sesse.net Git - vlc/blob - src/network/error.c
More cleanup
[vlc] / src / network / error.c
1 /*****************************************************************************
2  * error.c: Network error handling
3  *****************************************************************************
4  * Copyright (C) 2006 Rémi Denis-Courmont
5  * $Id$
6  *
7  * Author : Rémi Denis-Courmont <rem # videolan.org>
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
22  *****************************************************************************/
23
24 /*****************************************************************************
25  * Preamble
26  *****************************************************************************/
27 #include <vlc/vlc.h>
28 #include <errno.h>
29 #include "network.h"
30
31 #if defined (WIN32) || defined (UNDER_CE)
32 typedef struct
33 {
34     int code;
35     const char *msg;
36 } wsaerrmsg_t;
37
38 static const wsaerrmsg_t wsaerrmsg =
39 {
40     { WSAEINTR, "Interrupted by signal" },
41     { WSAEACCES, "Access denied" },
42     { WSAEFAULT, "Invalid memory address" },
43     { WSAEINVAL, "Invalid argument" },
44     { WSAEMFILE, "Too many open sockets" },
45     { WSAEWOULDBLOCK, "Would block" },
46     //{ WSAEALREADY
47     { WSAENOTSOCK, "Non-socket handle specified" },
48     { WSAEDESTADDRREQ, "Missing destination address" },
49     { WSAEMSGSIZE, "Message too big" },
50     //{ WSAEPROTOTYPE
51     { WSAENOPROTOOPT, "Option not supported by protocol" },
52     { WSAEPROTONOSUPPORT, "Protocol not support" },
53     //WSAESOCKTNOSUPPORT
54     { WSAEOPNOTSUPP, "Operation not supported" },
55     { WSAEPFNOSUPPORT, "Protocol family not supported" },
56     { WSAEAFNOSUPPORT, "Address family not supported" },
57     { WSAEADDRINUSE, "Address already in use" },
58     { WSAEADDRNOTAVAIL, "Address not available" },
59     { WSAENETDOWN, "Network down" },
60     { WSAENETUNREACH, "Network unreachable" },
61     //WSAENETRESET
62     { WSAECONNABORTED, "Connection aborted" },
63     { WSAECONNRESET, "Connection reset by peer" },
64     { WSAENOBUFS, "Not enough memory" },
65     { WSAEISCONN, "Socket already connected" },
66     { WSAENOTCONN, "Connection required first" },
67     { WSAESHUTDOWN, "Connection shutdown" },
68     { WSAETOOMANYREFS, "Too many references" },
69     { WSAETIMEDOUT, "Connection timed out" },
70     { WSAECONNREFUSED, "Connection refused by peer" },
71     //WSAELOOP
72     //WSAENAMETOOLONG
73     { WSAEHOSTDOWN, "Remote host down" },
74     { WSAEHOSTUNREACH, "Remote host unreachable" },
75     //WSAENOTEMPTY
76     //WSAEPROCLIM
77     //WSAEUSERS
78     //WSAEDQUOT
79     //WSAESTALE
80     //WSAEREMOTE
81     //WSAEDISCON
82     { WSASYSNOTREADY, "Network stack not ready" },
83     { WSAVERNOTSUPPORTED, "Network stack version not supported" },
84     { WSANOTINITIALISED, "Network not initialized" },
85     { WSAHOST_NOT_FOUND, "Hostname not found" },
86     { WSATRY_AGAIN, "Temporary hostname error" },
87     { WSANO_RECOVERY, "Non-recoverable hostname error" },
88     /* Winsock2 and QoS error are codes missing,
89        I'm too bored, and they "never" occur. */
90     { 0, NULL }
91 };
92
93
94 const char *net_strerror( int value )
95 {
96     /* There doesn't seem to be any portable error message generation for
97      * Winsock errors. Some old versions had s_error, but it appears to be
98      * gone, and is not documented.
99      */
100     for( const wsaerrmsg_t *e = wsaerrmsg; e.msg != NULL; e++ )
101         if( e.code == value )
102             return e.msg;
103
104     return "Unknown network stack error";
105 }
106 #endif