1*97dc5e69SMatthias Ringwald /**
2*97dc5e69SMatthias Ringwald * @file
3*97dc5e69SMatthias Ringwald * Error Management module
4*97dc5e69SMatthias Ringwald *
5*97dc5e69SMatthias Ringwald */
6*97dc5e69SMatthias Ringwald
7*97dc5e69SMatthias Ringwald /*
8*97dc5e69SMatthias Ringwald * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
9*97dc5e69SMatthias Ringwald * All rights reserved.
10*97dc5e69SMatthias Ringwald *
11*97dc5e69SMatthias Ringwald * Redistribution and use in source and binary forms, with or without modification,
12*97dc5e69SMatthias Ringwald * are permitted provided that the following conditions are met:
13*97dc5e69SMatthias Ringwald *
14*97dc5e69SMatthias Ringwald * 1. Redistributions of source code must retain the above copyright notice,
15*97dc5e69SMatthias Ringwald * this list of conditions and the following disclaimer.
16*97dc5e69SMatthias Ringwald * 2. Redistributions in binary form must reproduce the above copyright notice,
17*97dc5e69SMatthias Ringwald * this list of conditions and the following disclaimer in the documentation
18*97dc5e69SMatthias Ringwald * and/or other materials provided with the distribution.
19*97dc5e69SMatthias Ringwald * 3. The name of the author may not be used to endorse or promote products
20*97dc5e69SMatthias Ringwald * derived from this software without specific prior written permission.
21*97dc5e69SMatthias Ringwald *
22*97dc5e69SMatthias Ringwald * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
23*97dc5e69SMatthias Ringwald * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
24*97dc5e69SMatthias Ringwald * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
25*97dc5e69SMatthias Ringwald * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
26*97dc5e69SMatthias Ringwald * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
27*97dc5e69SMatthias Ringwald * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
28*97dc5e69SMatthias Ringwald * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
29*97dc5e69SMatthias Ringwald * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
30*97dc5e69SMatthias Ringwald * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
31*97dc5e69SMatthias Ringwald * OF SUCH DAMAGE.
32*97dc5e69SMatthias Ringwald *
33*97dc5e69SMatthias Ringwald * This file is part of the lwIP TCP/IP stack.
34*97dc5e69SMatthias Ringwald *
35*97dc5e69SMatthias Ringwald * Author: Adam Dunkels <[email protected]>
36*97dc5e69SMatthias Ringwald *
37*97dc5e69SMatthias Ringwald */
38*97dc5e69SMatthias Ringwald
39*97dc5e69SMatthias Ringwald #include "lwip/err.h"
40*97dc5e69SMatthias Ringwald #include "lwip/def.h"
41*97dc5e69SMatthias Ringwald #include "lwip/sys.h"
42*97dc5e69SMatthias Ringwald
43*97dc5e69SMatthias Ringwald #include "lwip/errno.h"
44*97dc5e69SMatthias Ringwald
45*97dc5e69SMatthias Ringwald #if !NO_SYS
46*97dc5e69SMatthias Ringwald /** Table to quickly map an lwIP error (err_t) to a socket error
47*97dc5e69SMatthias Ringwald * by using -err as an index */
48*97dc5e69SMatthias Ringwald static const int err_to_errno_table[] = {
49*97dc5e69SMatthias Ringwald 0, /* ERR_OK 0 No error, everything OK. */
50*97dc5e69SMatthias Ringwald ENOMEM, /* ERR_MEM -1 Out of memory error. */
51*97dc5e69SMatthias Ringwald ENOBUFS, /* ERR_BUF -2 Buffer error. */
52*97dc5e69SMatthias Ringwald EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */
53*97dc5e69SMatthias Ringwald EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */
54*97dc5e69SMatthias Ringwald EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */
55*97dc5e69SMatthias Ringwald EINVAL, /* ERR_VAL -6 Illegal value. */
56*97dc5e69SMatthias Ringwald EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
57*97dc5e69SMatthias Ringwald EADDRINUSE, /* ERR_USE -8 Address in use. */
58*97dc5e69SMatthias Ringwald EALREADY, /* ERR_ALREADY -9 Already connecting. */
59*97dc5e69SMatthias Ringwald EISCONN, /* ERR_ISCONN -10 Conn already established.*/
60*97dc5e69SMatthias Ringwald ENOTCONN, /* ERR_CONN -11 Not connected. */
61*97dc5e69SMatthias Ringwald -1, /* ERR_IF -12 Low-level netif error */
62*97dc5e69SMatthias Ringwald ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */
63*97dc5e69SMatthias Ringwald ECONNRESET, /* ERR_RST -14 Connection reset. */
64*97dc5e69SMatthias Ringwald ENOTCONN, /* ERR_CLSD -15 Connection closed. */
65*97dc5e69SMatthias Ringwald EIO /* ERR_ARG -16 Illegal argument. */
66*97dc5e69SMatthias Ringwald };
67*97dc5e69SMatthias Ringwald
68*97dc5e69SMatthias Ringwald int
err_to_errno(err_t err)69*97dc5e69SMatthias Ringwald err_to_errno(err_t err)
70*97dc5e69SMatthias Ringwald {
71*97dc5e69SMatthias Ringwald if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) {
72*97dc5e69SMatthias Ringwald return EIO;
73*97dc5e69SMatthias Ringwald }
74*97dc5e69SMatthias Ringwald return err_to_errno_table[-err];
75*97dc5e69SMatthias Ringwald }
76*97dc5e69SMatthias Ringwald #endif /* !NO_SYS */
77*97dc5e69SMatthias Ringwald
78*97dc5e69SMatthias Ringwald #ifdef LWIP_DEBUG
79*97dc5e69SMatthias Ringwald
80*97dc5e69SMatthias Ringwald static const char *err_strerr[] = {
81*97dc5e69SMatthias Ringwald "Ok.", /* ERR_OK 0 */
82*97dc5e69SMatthias Ringwald "Out of memory error.", /* ERR_MEM -1 */
83*97dc5e69SMatthias Ringwald "Buffer error.", /* ERR_BUF -2 */
84*97dc5e69SMatthias Ringwald "Timeout.", /* ERR_TIMEOUT -3 */
85*97dc5e69SMatthias Ringwald "Routing problem.", /* ERR_RTE -4 */
86*97dc5e69SMatthias Ringwald "Operation in progress.", /* ERR_INPROGRESS -5 */
87*97dc5e69SMatthias Ringwald "Illegal value.", /* ERR_VAL -6 */
88*97dc5e69SMatthias Ringwald "Operation would block.", /* ERR_WOULDBLOCK -7 */
89*97dc5e69SMatthias Ringwald "Address in use.", /* ERR_USE -8 */
90*97dc5e69SMatthias Ringwald "Already connecting.", /* ERR_ALREADY -9 */
91*97dc5e69SMatthias Ringwald "Already connected.", /* ERR_ISCONN -10 */
92*97dc5e69SMatthias Ringwald "Not connected.", /* ERR_CONN -11 */
93*97dc5e69SMatthias Ringwald "Low-level netif error.", /* ERR_IF -12 */
94*97dc5e69SMatthias Ringwald "Connection aborted.", /* ERR_ABRT -13 */
95*97dc5e69SMatthias Ringwald "Connection reset.", /* ERR_RST -14 */
96*97dc5e69SMatthias Ringwald "Connection closed.", /* ERR_CLSD -15 */
97*97dc5e69SMatthias Ringwald "Illegal argument." /* ERR_ARG -16 */
98*97dc5e69SMatthias Ringwald };
99*97dc5e69SMatthias Ringwald
100*97dc5e69SMatthias Ringwald /**
101*97dc5e69SMatthias Ringwald * Convert an lwip internal error to a string representation.
102*97dc5e69SMatthias Ringwald *
103*97dc5e69SMatthias Ringwald * @param err an lwip internal err_t
104*97dc5e69SMatthias Ringwald * @return a string representation for err
105*97dc5e69SMatthias Ringwald */
106*97dc5e69SMatthias Ringwald const char *
lwip_strerr(err_t err)107*97dc5e69SMatthias Ringwald lwip_strerr(err_t err)
108*97dc5e69SMatthias Ringwald {
109*97dc5e69SMatthias Ringwald if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) {
110*97dc5e69SMatthias Ringwald return "Unknown error.";
111*97dc5e69SMatthias Ringwald }
112*97dc5e69SMatthias Ringwald return err_strerr[-err];
113*97dc5e69SMatthias Ringwald }
114*97dc5e69SMatthias Ringwald
115*97dc5e69SMatthias Ringwald #endif /* LWIP_DEBUG */
116