libc/net: compatible with Android for htonq/ntohq

Signed-off-by: fangxinyong <fangxinyong@xiaomi.com>
This commit is contained in:
fangxinyong 2023-04-06 12:33:12 +08:00 committed by Xiang Xiao
parent 036d7bfe1e
commit da3a75da2c
4 changed files with 50 additions and 1 deletions

View File

@ -233,13 +233,16 @@
#ifdef CONFIG_ENDIAN_BIG
# define HTONS(ns) (ns)
# define HTONL(nl) (nl)
# define HTONQ(nq) (nq)
#else
# define HTONS __swap_uint16
# define HTONL __swap_uint32
# define HTONQ __swap_uint64
#endif
#define NTOHS(hs) HTONS(hs)
#define NTOHL(hl) HTONL(hl)
#define NTOHQ(hq) HTONQ(hq)
/****************************************************************************
* Public Type Definitions
@ -373,8 +376,10 @@ EXTERN const struct in6_addr in6addr_any;
uint32_t ntohl(uint32_t nl);
uint16_t ntohs(uint16_t ns);
uint64_t ntohq(uint64_t nq);
uint32_t htonl(uint32_t hl);
uint16_t htons(uint16_t hs);
uint64_t htonq(uint64_t hq);
#undef EXTERN
#if defined(__cplusplus)

View File

@ -105,6 +105,7 @@
"gmtime","time.h","","FAR struct tm *","FAR const time_t *"
"gmtime_r","time.h","","FAR struct tm *","FAR const time_t *","FAR struct tm *"
"htonl","arpa/inet.h","","uint32_t","uint32_t"
"htonq","arpa/inet.h","","uint64_t","uint64_t"
"htons","arpa/inet.h","","uint16_t","uint16_t"
"iconv","iconv.h","defined(CONFIG_LIBC_LOCALE)","size_t","iconv_t","FAR char **","FAR size_t *","FAR char **","FAR size_t *"
"iconv_close","iconv.h","defined(CONFIG_LIBC_LOCALE)","int","iconv_t"
@ -171,6 +172,7 @@
"mktime","time.h","","time_t","FAR struct tm *"
"nice","unistd.h","","int","int"
"ntohl","arpa/inet.h","","uint32_t","uint32_t"
"ntohq","arpa/inet.h","","uint64_t","uint64_t"
"ntohs","arpa/inet.h","","uint16_t","uint16_t"
"opendir","dirent.h","","FAR DIR *","FAR const char *"
"perror","stdio.h","defined(CONFIG_FILE_STREAM)","void","FAR const char *"

Can't render this file because it has a wrong number of fields in line 3.

View File

@ -20,7 +20,7 @@
# Add the networking C files to the build
CSRCS += lib_addrconfig.c lib_base64.c lib_htons.c lib_htonl.c
CSRCS += lib_addrconfig.c lib_base64.c lib_htons.c lib_htonl.c lib_htonq.c
CSRCS += lib_inetaddr.c lib_inetaton.c lib_inetntoa.c
CSRCS += lib_inetntop.c lib_inetpton.c lib_inetnetwork.c
CSRCS += lib_etherntoa.c lib_etheraton.c

42
libs/libc/net/lib_htonq.c Normal file
View File

@ -0,0 +1,42 @@
/****************************************************************************
* libs/libc/net/lib_htonq.c
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
****************************************************************************/
/****************************************************************************
* Included Files
****************************************************************************/
#include <nuttx/config.h>
#include <stdint.h>
#include <arpa/inet.h>
/****************************************************************************
* Public Functions
****************************************************************************/
uint64_t htonq(uint64_t hq)
{
return HTONQ(hq);
}
uint64_t ntohq(uint64_t nq)
{
return NTOHQ(nq);
}