2015-07-08 22:33:23 +02:00
|
|
|
/****************************************************************************
|
2018-05-29 21:21:26 +02:00
|
|
|
* libs/libc/netdb/lib_gethostbyaddr.c
|
2015-07-08 22:33:23 +02:00
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Gregory Nutt. All rights reserved.
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
*
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
* distribution.
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
* without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
2015-12-30 00:31:17 +01:00
|
|
|
#include "libc.h"
|
2015-07-10 20:11:40 +02:00
|
|
|
#include "netdb/lib_netdb.h"
|
2015-07-08 22:33:23 +02:00
|
|
|
|
2015-07-10 20:11:40 +02:00
|
|
|
#ifdef CONFIG_NETDB_HOSTFILE
|
2015-07-08 22:33:23 +02:00
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Public Functions
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Name: gethostbyaddr
|
|
|
|
*
|
|
|
|
* Description:
|
|
|
|
* The gethostbyaddr() function returns a structure of type hostent for
|
|
|
|
* the given host address addr of length len and address type type. Valid
|
|
|
|
* address types are AF_INET and AF_INET6. The host address argument is a
|
|
|
|
* pointer to a struct of a type depending on the address type, for example
|
|
|
|
* a struct in_addr * for address type AF_INET.
|
2017-06-28 18:39:54 +02:00
|
|
|
*
|
2015-07-08 22:33:23 +02:00
|
|
|
* Input Parameters:
|
|
|
|
* addr - The address of the host to find.
|
|
|
|
* len - The length of the address
|
|
|
|
* type - The type of the address
|
|
|
|
*
|
|
|
|
* Returned Value:
|
|
|
|
* Upon successful completion, this function will return a pointer to a
|
|
|
|
* hostent structure if the requested entry was found, and a null pointer
|
|
|
|
* if the end of the database was reached or the requested entry was not
|
|
|
|
* found.
|
|
|
|
*
|
|
|
|
* Upon unsuccessful completion, gethostbyaddr() will set h_errno to
|
|
|
|
* indicate the error
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len, int type)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
DEBUGASSERT(addr != NULL);
|
2015-07-09 00:00:50 +02:00
|
|
|
DEBUGASSERT(type == AF_INET || type == AF_INET6);
|
|
|
|
|
2015-07-08 22:33:23 +02:00
|
|
|
ret = gethostbyaddr_r(addr, len, type, &g_hostent, g_hostbuffer,
|
|
|
|
CONFIG_NETDB_BUFSIZE, &h_errno);
|
|
|
|
return ret == 0 ? &g_hostent : NULL;
|
|
|
|
}
|
|
|
|
|
2015-07-10 20:11:40 +02:00
|
|
|
#endif /* CONFIG_NETDB_HOSTFILE */
|