1195972f6Sopenharmony_ci/** 2195972f6Sopenharmony_ci * @file 3195972f6Sopenharmony_ci * Error Management module 4195972f6Sopenharmony_ci * 5195972f6Sopenharmony_ci */ 6195972f6Sopenharmony_ci 7195972f6Sopenharmony_ci/* 8195972f6Sopenharmony_ci * Copyright (c) 2001-2004 Swedish Institute of Computer Science. 9195972f6Sopenharmony_ci * All rights reserved. 10195972f6Sopenharmony_ci * 11195972f6Sopenharmony_ci * Redistribution and use in source and binary forms, with or without modification, 12195972f6Sopenharmony_ci * are permitted provided that the following conditions are met: 13195972f6Sopenharmony_ci * 14195972f6Sopenharmony_ci * 1. Redistributions of source code must retain the above copyright notice, 15195972f6Sopenharmony_ci * this list of conditions and the following disclaimer. 16195972f6Sopenharmony_ci * 2. Redistributions in binary form must reproduce the above copyright notice, 17195972f6Sopenharmony_ci * this list of conditions and the following disclaimer in the documentation 18195972f6Sopenharmony_ci * and/or other materials provided with the distribution. 19195972f6Sopenharmony_ci * 3. The name of the author may not be used to endorse or promote products 20195972f6Sopenharmony_ci * derived from this software without specific prior written permission. 21195972f6Sopenharmony_ci * 22195972f6Sopenharmony_ci * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED 23195972f6Sopenharmony_ci * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 24195972f6Sopenharmony_ci * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT 25195972f6Sopenharmony_ci * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 26195972f6Sopenharmony_ci * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 27195972f6Sopenharmony_ci * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 28195972f6Sopenharmony_ci * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 29195972f6Sopenharmony_ci * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 30195972f6Sopenharmony_ci * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY 31195972f6Sopenharmony_ci * OF SUCH DAMAGE. 32195972f6Sopenharmony_ci * 33195972f6Sopenharmony_ci * This file is part of the lwIP TCP/IP stack. 34195972f6Sopenharmony_ci * 35195972f6Sopenharmony_ci * Author: Adam Dunkels <adam@sics.se> 36195972f6Sopenharmony_ci * 37195972f6Sopenharmony_ci */ 38195972f6Sopenharmony_ci 39195972f6Sopenharmony_ci#include "lwip/err.h" 40195972f6Sopenharmony_ci#include "lwip/def.h" 41195972f6Sopenharmony_ci#include "lwip/sys.h" 42195972f6Sopenharmony_ci 43195972f6Sopenharmony_ci#include "lwip/errno.h" 44195972f6Sopenharmony_ci 45195972f6Sopenharmony_ci#if !NO_SYS 46195972f6Sopenharmony_ci/** Table to quickly map an lwIP error (err_t) to a socket error 47195972f6Sopenharmony_ci * by using -err as an index */ 48195972f6Sopenharmony_cistatic const int err_to_errno_table[] = { 49195972f6Sopenharmony_ci 0, /* ERR_OK 0 No error, everything OK. */ 50195972f6Sopenharmony_ci ENOMEM, /* ERR_MEM -1 Out of memory error. */ 51195972f6Sopenharmony_ci ENOBUFS, /* ERR_BUF -2 Buffer error. */ 52195972f6Sopenharmony_ci EWOULDBLOCK, /* ERR_TIMEOUT -3 Timeout */ 53195972f6Sopenharmony_ci EHOSTUNREACH, /* ERR_RTE -4 Routing problem. */ 54195972f6Sopenharmony_ci EINPROGRESS, /* ERR_INPROGRESS -5 Operation in progress */ 55195972f6Sopenharmony_ci EINVAL, /* ERR_VAL -6 Illegal value. */ 56195972f6Sopenharmony_ci EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */ 57195972f6Sopenharmony_ci EADDRINUSE, /* ERR_USE -8 Address in use. */ 58195972f6Sopenharmony_ci EALREADY, /* ERR_ALREADY -9 Already connecting. */ 59195972f6Sopenharmony_ci EISCONN, /* ERR_ISCONN -10 Conn already established.*/ 60195972f6Sopenharmony_ci ENOTCONN, /* ERR_CONN -11 Not connected. */ 61195972f6Sopenharmony_ci -1, /* ERR_IF -12 Low-level netif error */ 62195972f6Sopenharmony_ci ECONNABORTED, /* ERR_ABRT -13 Connection aborted. */ 63195972f6Sopenharmony_ci ECONNRESET, /* ERR_RST -14 Connection reset. */ 64195972f6Sopenharmony_ci ENOTCONN, /* ERR_CLSD -15 Connection closed. */ 65195972f6Sopenharmony_ci EIO /* ERR_ARG -16 Illegal argument. */ 66195972f6Sopenharmony_ci}; 67195972f6Sopenharmony_ci 68195972f6Sopenharmony_ciint 69195972f6Sopenharmony_cierr_to_errno(err_t err) 70195972f6Sopenharmony_ci{ 71195972f6Sopenharmony_ci if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_to_errno_table))) { 72195972f6Sopenharmony_ci return EIO; 73195972f6Sopenharmony_ci } 74195972f6Sopenharmony_ci return err_to_errno_table[-err]; 75195972f6Sopenharmony_ci} 76195972f6Sopenharmony_ci#endif /* !NO_SYS */ 77195972f6Sopenharmony_ci 78195972f6Sopenharmony_ci#ifdef LWIP_DEBUG 79195972f6Sopenharmony_ci 80195972f6Sopenharmony_cistatic const char *err_strerr[] = { 81195972f6Sopenharmony_ci "Ok.", /* ERR_OK 0 */ 82195972f6Sopenharmony_ci "Out of memory error.", /* ERR_MEM -1 */ 83195972f6Sopenharmony_ci "Buffer error.", /* ERR_BUF -2 */ 84195972f6Sopenharmony_ci "Timeout.", /* ERR_TIMEOUT -3 */ 85195972f6Sopenharmony_ci "Routing problem.", /* ERR_RTE -4 */ 86195972f6Sopenharmony_ci "Operation in progress.", /* ERR_INPROGRESS -5 */ 87195972f6Sopenharmony_ci "Illegal value.", /* ERR_VAL -6 */ 88195972f6Sopenharmony_ci "Operation would block.", /* ERR_WOULDBLOCK -7 */ 89195972f6Sopenharmony_ci "Address in use.", /* ERR_USE -8 */ 90195972f6Sopenharmony_ci "Already connecting.", /* ERR_ALREADY -9 */ 91195972f6Sopenharmony_ci "Already connected.", /* ERR_ISCONN -10 */ 92195972f6Sopenharmony_ci "Not connected.", /* ERR_CONN -11 */ 93195972f6Sopenharmony_ci "Low-level netif error.", /* ERR_IF -12 */ 94195972f6Sopenharmony_ci "Connection aborted.", /* ERR_ABRT -13 */ 95195972f6Sopenharmony_ci "Connection reset.", /* ERR_RST -14 */ 96195972f6Sopenharmony_ci "Connection closed.", /* ERR_CLSD -15 */ 97195972f6Sopenharmony_ci "Illegal argument." /* ERR_ARG -16 */ 98195972f6Sopenharmony_ci}; 99195972f6Sopenharmony_ci 100195972f6Sopenharmony_ci/** 101195972f6Sopenharmony_ci * Convert an lwip internal error to a string representation. 102195972f6Sopenharmony_ci * 103195972f6Sopenharmony_ci * @param err an lwip internal err_t 104195972f6Sopenharmony_ci * @return a string representation for err 105195972f6Sopenharmony_ci */ 106195972f6Sopenharmony_ciconst char * 107195972f6Sopenharmony_cilwip_strerr(err_t err) 108195972f6Sopenharmony_ci{ 109195972f6Sopenharmony_ci if ((err > 0) || (-err >= (err_t)LWIP_ARRAYSIZE(err_strerr))) { 110195972f6Sopenharmony_ci return "Unknown error."; 111195972f6Sopenharmony_ci } 112195972f6Sopenharmony_ci return err_strerr[-err]; 113195972f6Sopenharmony_ci} 114195972f6Sopenharmony_ci 115195972f6Sopenharmony_ci#endif /* LWIP_DEBUG */ 116