2018-06-08 15:07:21 +02:00
|
|
|
/****************************************************************************
|
|
|
|
* libs/libc/netdb/lib_gaistrerror.c
|
|
|
|
*
|
2021-05-26 10:05:59 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2018-06-08 15:07:21 +02:00
|
|
|
*
|
2021-05-26 10:05:59 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2018-06-08 15:07:21 +02:00
|
|
|
*
|
2021-05-26 10:05:59 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2018-06-08 15:07:21 +02:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <stdint.h>
|
|
|
|
#include <netdb.h>
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Types
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
struct errno_strmap_s
|
|
|
|
{
|
2020-03-29 19:22:29 +02:00
|
|
|
uint8_t errnum;
|
|
|
|
FAR const char *str;
|
2018-06-08 15:07:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Private Data
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifdef CONFIG_LIBC_GAISTRERROR
|
|
|
|
|
|
|
|
/* This table maps all error numbers to descriptive strings.
|
|
|
|
* The only assumption that the code makes with regard to this
|
|
|
|
* this table is that it is ordered by error number.
|
|
|
|
*
|
|
|
|
* The size of this table is quite large. Its size can be
|
|
|
|
* reduced by eliminating some of the more obscure error
|
|
|
|
* strings.
|
|
|
|
*
|
|
|
|
* Only short names are currently supported.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static const struct errno_strmap_s g_gaierrnomap[] =
|
|
|
|
{
|
|
|
|
{ EAI_AGAIN, "EAI_AGAIN" },
|
|
|
|
{ EAI_BADFLAGS, "EAI_BADFLAGS" },
|
|
|
|
{ EAI_FAIL, "EAI_FAIL" },
|
|
|
|
{ EAI_FAMILY, "EAI_FAMILY" },
|
|
|
|
{ EAI_MEMORY, "EAI_MEMORY" },
|
|
|
|
{ EAI_NONAME, "EAI_NONAME" },
|
|
|
|
{ EAI_SERVICE, "EAI_SERVICE" },
|
|
|
|
{ EAI_SOCKTYPE, "EAI_SOCKTYPE" },
|
|
|
|
{ EAI_SYSTEM, "EAI_SYSTEM" },
|
|
|
|
{ EAI_OVERFLOW, "EAI_OVERFLOW" },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define NERRNO_STRS (sizeof(g_gaierrnomap) / sizeof(struct errno_strmap_s))
|
|
|
|
|
|
|
|
#endif /* CONFIG_LIBC_GAISTRERROR */
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: gai_strerror
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR const char *gai_strerror(int errnum)
|
|
|
|
{
|
|
|
|
#ifdef CONFIG_LIBC_GAISTRERROR
|
|
|
|
int ndxlow = 0;
|
|
|
|
int ndxhi = NERRNO_STRS - 1;
|
|
|
|
int ndxmid;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
ndxmid = (ndxlow + ndxhi) >> 1;
|
|
|
|
if (errnum > g_gaierrnomap[ndxmid].errnum)
|
|
|
|
{
|
|
|
|
ndxlow = ndxmid + 1;
|
|
|
|
}
|
|
|
|
else if (errnum < g_gaierrnomap[ndxmid].errnum)
|
|
|
|
{
|
|
|
|
ndxhi = ndxmid - 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return g_gaierrnomap[ndxmid].str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
while (ndxlow <= ndxhi);
|
|
|
|
#endif
|
|
|
|
return "Unknown error";
|
|
|
|
}
|