2015-07-09 04:33:23 +08:00
|
|
|
/****************************************************************************
|
2018-05-30 03:21:26 +08:00
|
|
|
* libs/libc/netdb/lib_gethostbyaddr.c
|
2015-07-09 04:33:23 +08:00
|
|
|
*
|
2021-03-02 22:54:21 +08: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
|
2015-07-09 04:33:23 +08:00
|
|
|
*
|
2021-03-02 22:54:21 +08:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2015-07-09 04:33:23 +08:00
|
|
|
*
|
2021-03-02 22:54:21 +08: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.
|
2015-07-09 04:33:23 +08:00
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
/****************************************************************************
|
|
|
|
* Included Files
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <netdb.h>
|
|
|
|
|
2015-07-11 02:11:40 +08:00
|
|
|
#include "netdb/lib_netdb.h"
|
2015-07-09 04:33:23 +08:00
|
|
|
|
2020-03-29 18:31:45 +08:00
|
|
|
#ifdef CONFIG_LIBC_NETDB
|
2015-07-09 04:33:23 +08: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-29 00:39:54 +08:00
|
|
|
*
|
2015-07-09 04:33:23 +08: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
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2020-03-30 20:49:28 +08:00
|
|
|
FAR struct hostent *gethostbyaddr(FAR const void *addr,
|
|
|
|
socklen_t len, int type)
|
2015-07-09 04:33:23 +08:00
|
|
|
{
|
2020-04-01 02:21:04 +08:00
|
|
|
FAR struct hostent *res;
|
2015-07-09 04:33:23 +08:00
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = gethostbyaddr_r(addr, len, type, &g_hostent, g_hostbuffer,
|
2020-04-01 02:21:04 +08:00
|
|
|
CONFIG_NETDB_BUFSIZE, &res, &h_errno);
|
|
|
|
return ret == 0 ? res : NULL;
|
2015-07-09 04:33:23 +08:00
|
|
|
}
|
|
|
|
|
2020-03-29 18:31:45 +08:00
|
|
|
#endif /* CONFIG_LIBC_NETDB */
|