libc/netdb: Fix nxstyle issue

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
This commit is contained in:
Xiang Xiao
2020-03-30 20:49:28 +08:00
committed by patacongo
parent d8b5362380
commit 15fac7743c
15 changed files with 121 additions and 127 deletions
+9 -6
View File
@@ -4,7 +4,8 @@
* Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved. * Copyright (C) 2015, 2018 Gregory Nutt. All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Reference: http://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html * Reference:
* http://pubs.opengroup.org/onlinepubs/009695399/basedefs/netdb.h.html
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions * modification, are permitted provided that the following conditions
@@ -180,8 +181,9 @@
struct hostent struct hostent
{ {
FAR char *h_name; /* Official name of the host. */ FAR char *h_name; /* Official name of the host. */
FAR char **h_aliases; /* A pointer to an array of pointers to alternative FAR char **h_aliases; /* A pointer to an array of pointers to the
* host names, terminated by a null pointer. */ * alternative host names, terminated by a
* null pointer. */
int h_addrtype; /* Address type. */ int h_addrtype; /* Address type. */
int h_length; /* The length, in bytes, of the address. */ int h_length; /* The length, in bytes, of the address. */
FAR char **h_addr_list; /* A pointer to an array of pointers to network FAR char **h_addr_list; /* A pointer to an array of pointers to network
@@ -193,10 +195,11 @@ struct hostent
struct netent struct netent
{ {
FAR char *n_name; /* Official, fully-qualified (including the domain) FAR char *n_name; /* Official, fully-qualified(including the domain)
* name of the host. */ * name of the host. */
FAR char **n_aliases; /* A pointer to an array of pointers to alternative FAR char **n_aliases; /* A pointer to an array of pointers to the
* network names, terminated by a null pointer. */ * alternative network names, terminated by a
* null pointer. */
int n_addrtype; /* The address type of the network. */ int n_addrtype; /* The address type of the network. */
uint32_t n_net; /* The network number, in host byte order. */ uint32_t n_net; /* The network number, in host byte order. */
}; };
+7 -3
View File
@@ -2,7 +2,8 @@
* libs/libc/netdb/lib_dns.h * libs/libc/netdb/lib_dns.h
* DNS resolver code header file. * DNS resolver code header file.
* *
* Copyright (C) 2007-2009, 2011-2012, 2014 Gregory Nutt. All rights reserved. * Copyright (C) 2007-2009, 2011-2012, 2014 Gregory Nutt.
* All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Inspired by/based on uIP logic by Adam Dunkels: * Inspired by/based on uIP logic by Adam Dunkels:
@@ -56,7 +57,8 @@
/**************************************************************************** /****************************************************************************
* Pre-processor Definitions * Pre-processor Definitions
****************************************************************************/ ****************************************************************************/
/* DNS client configuration **************************************************/
/* DNS client configuration *************************************************/
#ifndef CONFIG_NETDB_DNSCLIENT_ENTRIES #ifndef CONFIG_NETDB_DNSCLIENT_ENTRIES
# define CONFIG_NETDB_DNSCLIENT_ENTRIES 4 # define CONFIG_NETDB_DNSCLIENT_ENTRIES 4
@@ -85,6 +87,7 @@
/**************************************************************************** /****************************************************************************
* Public Types * Public Types
****************************************************************************/ ****************************************************************************/
/* This describes either an IPv4 or IPv6 address. It is essentially a named /* This describes either an IPv4 or IPv6 address. It is essentially a named
* alternative to sockaddr_storage. * alternative to sockaddr_storage.
*/ */
@@ -248,7 +251,8 @@ int dns_find_answer(FAR const char *hostname, FAR union dns_addr_u *addr,
* Name: dns_notify_nameserver * Name: dns_notify_nameserver
****************************************************************************/ ****************************************************************************/
void dns_notify_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen); void dns_notify_nameserver(FAR const struct sockaddr *addr,
socklen_t addrlen);
#undef EXTERN #undef EXTERN
#if defined(__cplusplus) #if defined(__cplusplus)
+2 -1
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* libs/libc/netdb/lib_dnsbind.c * libs/libc/netdb/lib_dnsbind.c
* *
* Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt.
* All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
+7 -5
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* libs/libc/netdb/lib_dnscache.c * libs/libc/netdb/lib_dnscache.c
* *
* Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2012, 2014-2016 Gregory Nutt.
* All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
@@ -79,7 +80,7 @@ struct dns_cache_s
#endif #endif
char name[CONFIG_NETDB_DNSCLIENT_NAMESIZE]; char name[CONFIG_NETDB_DNSCLIENT_NAMESIZE];
uint8_t naddr; /* How many addresses per name */ uint8_t naddr; /* How many addresses per name */
union dns_addr_u addr[CONFIG_NETDB_MAX_IPADDR]; /* Resolved address */ union dns_addr_u addr[CONFIG_NETDB_MAX_IPADDR];
}; };
/**************************************************************************** /****************************************************************************
@@ -255,13 +256,14 @@ int dns_find_answer(FAR const char *hostname, FAR union dns_addr_u *addr,
else else
#endif #endif
{ {
/* The entry has not expired, check for a name match. Notice that /* The entry has not expired, check for a name match. Because
* because the names are truncated to CONFIG_NETDB_DNSCLIENT_NAMESIZE, * the names are truncated to CONFIG_NETDB_DNSCLIENT_NAMESIZE,
* this has the possibility of aliasing two names and returning * this has the possibility of aliasing two names and returning
* the wrong entry from the cache. * the wrong entry from the cache.
*/ */
if (strncmp(hostname, entry->name, CONFIG_NETDB_DNSCLIENT_NAMESIZE) == 0) if (strncmp(hostname, entry->name,
CONFIG_NETDB_DNSCLIENT_NAMESIZE) == 0)
{ {
/* We have a match. Return the resolved host address */ /* We have a match. Return the resolved host address */
+1
View File
@@ -230,6 +230,7 @@ int dns_foreach_nameserver(dns_callback_t callback, FAR void *arg)
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
} }
#endif #endif
if (ret != OK) if (ret != OK)
{ {
fclose(stream); fclose(stream);
+2 -1
View File
@@ -1,7 +1,8 @@
/**************************************************************************** /****************************************************************************
* libs/libc/netdb/lib_dnsinit.c * libs/libc/netdb/lib_dnsinit.c
* *
* Copyright (C) 2007, 2009, 2012, 2014-2017 Gregory Nutt. All rights reserved. * Copyright (C) 2007, 2009, 2012, 2014-2017 Gregory Nutt.
* All rights reserved.
* Author: Gregory Nutt <gnutt@nuttx.org> * Author: Gregory Nutt <gnutt@nuttx.org>
* *
* Redistribution and use in source and binary forms, with or without * Redistribution and use in source and binary forms, with or without
+2 -1
View File
@@ -133,7 +133,8 @@ int dns_unregister_notify(dns_callback_t callback, FAR void *arg)
* Name: dns_notify_nameserver * Name: dns_notify_nameserver
****************************************************************************/ ****************************************************************************/
void dns_notify_nameserver(FAR const struct sockaddr *addr, socklen_t addrlen) void dns_notify_nameserver(FAR const struct sockaddr *addr,
socklen_t addrlen)
{ {
FAR dq_entry_t *entry; FAR dq_entry_t *entry;
+11 -33
View File
@@ -109,8 +109,8 @@ struct dns_query_info_s
uint16_t id; /* Query ID */ uint16_t id; /* Query ID */
uint16_t rectype; /* Queried record type */ uint16_t rectype; /* Queried record type */
uint16_t qnamelen; /* Queried hostname length */ uint16_t qnamelen; /* Queried hostname length */
char qname[CONFIG_NETDB_DNSCLIENT_NAMESIZE+2]; /* Queried hostname in encoded char qname[CONFIG_NETDB_DNSCLIENT_NAMESIZE + 2]; /* Queried hostname in
* format + NUL */ * encoded format + NUL */
}; };
/**************************************************************************** /****************************************************************************
@@ -127,7 +127,7 @@ struct dns_query_info_s
* *
* query - A pointer to the starting byte of the name entry in the DNS * query - A pointer to the starting byte of the name entry in the DNS
* response. * response.
* queryend - A pointer to the byte after the last byte of the DNS response. * queryend - A pointer to the byte after the last byte of the response.
* *
* Returned Value: * Returned Value:
* Pointer to the first byte after the parsed name, or the value of * Pointer to the first byte after the parsed name, or the value of
@@ -143,7 +143,7 @@ static FAR uint8_t *dns_parse_name(FAR uint8_t *query, FAR uint8_t *queryend)
{ {
n = *query++; n = *query++;
/* Check for a leading or trailing pointer.*/ /* Check for a leading or trailing pointer */
if ((n & 0xc0) != 0) if ((n & 0xc0) != 0)
{ {
@@ -394,6 +394,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
} }
} }
#endif #endif
#ifdef CONFIG_NET_IPv6 #ifdef CONFIG_NET_IPv6
/* Check for an IPv6 address */ /* Check for an IPv6 address */
@@ -427,7 +428,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
} }
hdr = (FAR struct dns_header_s *)buffer; hdr = (FAR struct dns_header_s *)buffer;
endofbuffer = (FAR uint8_t*)buffer + ret; endofbuffer = (FAR uint8_t *)buffer + ret;
ninfo("ID %d\n", ntohs(hdr->id)); ninfo("ID %d\n", ntohs(hdr->id));
ninfo("Query %d\n", hdr->flags1 & DNS_FLAG1_RESPONSE); ninfo("Query %d\n", hdr->flags1 & DNS_FLAG1_RESPONSE);
@@ -479,29 +480,6 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
return -EILSEQ; return -EILSEQ;
} }
#if defined(CONFIG_DEBUG_NET) && defined(CONFIG_DEBUG_INFO)
{
int d = 64;
FAR uint8_t *ptr = nameptr + sizeof(struct dns_question_s);
lib_dumpbuffer("namestart: ", namestart, nameptr - namestart);
for (; ; )
{
ninfo("%02X %02X %02X %02X %02X %02X %02X %02X \n",
ptr[0], ptr[1], ptr[2], ptr[3],
ptr[4], ptr[5], ptr[6], ptr[7]);
ptr += 8;
d -= 8;
if (d < 0)
{
break;
}
}
}
#endif
/* Since dns_parse_name() skips any pointer bytes, /* Since dns_parse_name() skips any pointer bytes,
* we cannot compare for equality here. * we cannot compare for equality here.
*/ */
@@ -571,8 +549,8 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
nameptr += 10 + 4; nameptr += 10 + 4;
ninfo("IPv4 address: %d.%d.%d.%d\n", ninfo("IPv4 address: %d.%d.%d.%d\n",
(ans->u.ipv4.s_addr ) & 0xff, (ans->u.ipv4.s_addr) & 0xff,
(ans->u.ipv4.s_addr >> 8 ) & 0xff, (ans->u.ipv4.s_addr >> 8) & 0xff,
(ans->u.ipv4.s_addr >> 16) & 0xff, (ans->u.ipv4.s_addr >> 16) & 0xff,
(ans->u.ipv4.s_addr >> 24) & 0xff); (ans->u.ipv4.s_addr >> 24) & 0xff);
@@ -580,7 +558,7 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
{ {
FAR struct sockaddr_in *inaddr; FAR struct sockaddr_in *inaddr;
inaddr = (FAR struct sockaddr_in *)&addr[naddr_read].addr; inaddr = &addr[naddr_read].ipv4;
inaddr->sin_family = AF_INET; inaddr->sin_family = AF_INET;
inaddr->sin_port = 0; inaddr->sin_port = 0;
inaddr->sin_addr.s_addr = ans->u.ipv4.s_addr; inaddr->sin_addr.s_addr = ans->u.ipv4.s_addr;
@@ -611,13 +589,13 @@ static int dns_recv_response(int sd, FAR union dns_addr_u *addr, int *naddr,
ntohs(ans->u.ipv6.s6_addr[7]), ntohs(ans->u.ipv6.s6_addr[6]), ntohs(ans->u.ipv6.s6_addr[7]), ntohs(ans->u.ipv6.s6_addr[6]),
ntohs(ans->u.ipv6.s6_addr[5]), ntohs(ans->u.ipv6.s6_addr[4]), ntohs(ans->u.ipv6.s6_addr[5]), ntohs(ans->u.ipv6.s6_addr[4]),
ntohs(ans->u.ipv6.s6_addr[3]), ntohs(ans->u.ipv6.s6_addr[2]), ntohs(ans->u.ipv6.s6_addr[3]), ntohs(ans->u.ipv6.s6_addr[2]),
ntohs(ans->u.ipv6.s6_addr[1]), ntohs(ans->u.ipv6.s6_addr[0])); ntohs(ans->u.ipv6.s6_addr[1]), ntohs(*ans->u.ipv6.s6_addr));
if (naddr_read < *naddr) if (naddr_read < *naddr)
{ {
FAR struct sockaddr_in6 *inaddr; FAR struct sockaddr_in6 *inaddr;
inaddr = (FAR struct sockaddr_in6 *)&addr[naddr_read].addr; inaddr = &addr[naddr_read].ipv6;
inaddr->sin6_family = AF_INET6; inaddr->sin6_family = AF_INET6;
inaddr->sin6_port = 0; inaddr->sin6_port = 0;
memcpy(inaddr->sin6_addr.s6_addr, ans->u.ipv6.s6_addr, 16); memcpy(inaddr->sin6_addr.s6_addr, ans->u.ipv6.s6_addr, 16);
+2 -1
View File
@@ -77,7 +77,8 @@
* *
****************************************************************************/ ****************************************************************************/
FAR struct hostent *gethostbyaddr(FAR const void *addr, socklen_t len, int type) FAR struct hostent *gethostbyaddr(FAR const void *addr,
socklen_t len, int type)
{ {
int ret; int ret;
+1 -1
View File
@@ -311,7 +311,7 @@ int lib_hostfile_lookup(FAR const void *addr, socklen_t len, int type,
goto errorout_with_stream; goto errorout_with_stream;
} }
} }
else if (nread > 0 && len == host->h_length && type == host->h_addrtype) else if (len == host->h_length && type == host->h_addrtype)
{ {
/* We successfully read the entry and the type and size of the /* We successfully read the entry and the type and size of the
* address is good. Now compare the addresses: * address is good. Now compare the addresses:
+8 -6
View File
@@ -94,7 +94,8 @@ struct hostent_info_s
* *
****************************************************************************/ ****************************************************************************/
static int lib_numeric_address(FAR const char *name, FAR struct hostent *host, static int lib_numeric_address(FAR const char *name,
FAR struct hostent *host,
FAR char *buf, size_t buflen) FAR char *buf, size_t buflen)
{ {
FAR struct hostent_info_s *info; FAR struct hostent_info_s *info;
@@ -609,8 +610,10 @@ static int lib_dns_lookup(FAR const char *name, FAR struct hostent *host,
****************************************************************************/ ****************************************************************************/
#ifdef CONFIG_NETDB_HOSTFILE #ifdef CONFIG_NETDB_HOSTFILE
static int lib_hostfile_lookup(FAR const char *name, FAR struct hostent *host, static int lib_hostfile_lookup(FAR const char *name,
FAR char *buf, size_t buflen, int *h_errnop) FAR struct hostent *host,
FAR char *buf, size_t buflen,
FAR int *h_errnop)
{ {
FAR FILE *stream; FAR FILE *stream;
int herrnocode; int herrnocode;
@@ -734,8 +737,8 @@ errorout_with_herrnocode:
* and its struct in_addr equivalent into the h_addr_list[0] field of the * and its struct in_addr equivalent into the h_addr_list[0] field of the
* returned hostent structure. * returned hostent structure.
* *
* gethostname_r() is *not* POSIX but is similar to a Glibc extension and is * gethostname_r() is *not* POSIX but is similar to a Glibc extension and
* used internally by NuttX to implement the POSIX gethostname(). * is used internally by NuttX to implement the POSIX gethostname().
* *
* Input Parameters: * Input Parameters:
* name - The name of the host to find. * name - The name of the host to find.
@@ -784,7 +787,6 @@ int gethostbyname_r(FAR const char *name, FAR struct hostent *host,
#endif #endif
/* Try to find the name in the HOSTALIASES environment variable */ /* Try to find the name in the HOSTALIASES environment variable */
/* REVISIT: Not implemented */
#ifdef CONFIG_NETDB_DNSCLIENT #ifdef CONFIG_NETDB_DNSCLIENT
#if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0 #if CONFIG_NETDB_DNSCLIENT_ENTRIES > 0
+2 -2
View File
@@ -100,8 +100,8 @@ int getnameinfo(FAR const struct sockaddr *addr, socklen_t addrlen,
struct hostent hostent; struct hostent hostent;
int h_errno; int h_errno;
ret = gethostbyaddr_r(saddr, saddr_len, addr->sa_family, &hostent, host, ret = gethostbyaddr_r(saddr, saddr_len, addr->sa_family, &hostent,
hostlen, &h_errno); host, hostlen, &h_errno);
if (ret == OK) if (ret == OK)
{ {
+2 -1
View File
@@ -51,7 +51,8 @@
* Name: getservbyname * Name: getservbyname
****************************************************************************/ ****************************************************************************/
FAR struct servent *getservbyname(FAR const char *name, FAR const char *proto) FAR struct servent *getservbyname(FAR const char *name,
FAR const char *proto)
{ {
static struct servent ent; static struct servent ent;
struct servent *res; struct servent *res;
-1
View File
@@ -57,7 +57,6 @@ char g_hostbuffer[CONFIG_NETDB_BUFSIZE];
* macro or an identifier declared with external linkage. * macro or an identifier declared with external linkage.
*/ */
/* REVISIT: This should at least be per-task? */
int h_errno; int h_errno;
/**************************************************************************** /****************************************************************************