You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/08/03 05:47:35 UTC

[nuttx] branch master updated: libc/net: compatible with Android for htonq/ntohq

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new da3a75da2c libc/net: compatible with Android for htonq/ntohq
da3a75da2c is described below

commit da3a75da2c7cc47d677515238735946791dc2b75
Author: fangxinyong <fa...@xiaomi.com>
AuthorDate: Thu Apr 6 12:33:12 2023 +0800

    libc/net: compatible with Android for htonq/ntohq
    
    Signed-off-by: fangxinyong <fa...@xiaomi.com>
---
 include/netinet/in.h      |  5 +++++
 libs/libc/libc.csv        |  2 ++
 libs/libc/net/Make.defs   |  2 +-
 libs/libc/net/lib_htonq.c | 42 ++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 50 insertions(+), 1 deletion(-)

diff --git a/include/netinet/in.h b/include/netinet/in.h
index 3affebaa9b..3ab5712330 100644
--- a/include/netinet/in.h
+++ b/include/netinet/in.h
@@ -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)
diff --git a/libs/libc/libc.csv b/libs/libc/libc.csv
index 7b76aa4b3f..89bfa1d81d 100644
--- a/libs/libc/libc.csv
+++ b/libs/libc/libc.csv
@@ -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 *"
diff --git a/libs/libc/net/Make.defs b/libs/libc/net/Make.defs
index 52b0df6128..3cee4348bf 100644
--- a/libs/libc/net/Make.defs
+++ b/libs/libc/net/Make.defs
@@ -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
diff --git a/libs/libc/net/lib_htonq.c b/libs/libc/net/lib_htonq.c
new file mode 100644
index 0000000000..73661408d8
--- /dev/null
+++ b/libs/libc/net/lib_htonq.c
@@ -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);
+}