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