OSDN Git Service

We have the _r ether_ntoa/ether_aton functions too.
authorElliott Hughes <enh@google.com>
Mon, 16 May 2016 20:24:31 +0000 (13:24 -0700)
committerElliott Hughes <enh@google.com>
Mon, 16 May 2016 20:24:31 +0000 (13:24 -0700)
We've also had them since H, not L.

Change-Id: Iee7633ea97a0ee9a00bf7b62ead315acf02a3c8e

libc/include/netinet/ether.h
tests/Android.mk
tests/netinet_ether_test.cpp [new file with mode: 0644]

index 17b61c1..e69cdaf 100644 (file)
 
 __BEGIN_DECLS
 
-char* ether_ntoa(const struct ether_addr*) __INTRODUCED_IN(21);
-struct ether_addr* ether_aton(const char*) __INTRODUCED_IN(21);
+char* ether_ntoa(const struct ether_addr*) __INTRODUCED_IN(11);
+char* ether_ntoa_r(const struct ether_addr*, char*) __INTRODUCED_IN(11);
+struct ether_addr* ether_aton(const char*) __INTRODUCED_IN(11);
+struct ether_addr* ether_aton_r(const char*, struct ether_addr*) __INTRODUCED_IN(11);
 
 __END_DECLS
 
index 2db1cda..b3ff5eb 100644 (file)
@@ -72,6 +72,7 @@ libBionicStandardTests_src_files := \
     mntent_test.cpp \
     netdb_test.cpp \
     net_if_test.cpp \
+    netinet_ether_test.cpp \
     netinet_in_test.cpp \
     netinet_udp_test.cpp \
     nl_types_test.cpp \
diff --git a/tests/netinet_ether_test.cpp b/tests/netinet_ether_test.cpp
new file mode 100644 (file)
index 0000000..ee921d9
--- /dev/null
@@ -0,0 +1,50 @@
+/*
+ * Copyright (C) 2016 The Android Open Source Project
+ *
+ * Licensed 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.
+ */
+
+#include <gtest/gtest.h>
+
+#include <netinet/ether.h>
+
+TEST(netinet_ether, ether_aton__ether_ntoa) {
+  ether_addr* a = ether_aton("12-34-56-78-9A-BC");
+  ASSERT_EQ(0x12, a->ether_addr_octet[0]);
+  ASSERT_EQ(0x34, a->ether_addr_octet[1]);
+  ASSERT_EQ(0x56, a->ether_addr_octet[2]);
+  ASSERT_EQ(0x78, a->ether_addr_octet[3]);
+  ASSERT_EQ(0x9a, a->ether_addr_octet[4]);
+  ASSERT_EQ(0xbc, a->ether_addr_octet[5]);
+
+  ASSERT_STREQ("12-34-56-78-9A-BC", ether_ntoa(a));
+}
+
+TEST(netinet_ether, ether_aton_r__ether_ntoa_r) {
+  ether_addr addr;
+  memset(&addr, 0, sizeof(addr));
+  ether_addr* a = ether_aton_r("12-34-56-78-9A-BC", &addr);
+  ASSERT_EQ(&addr, a);
+  ASSERT_EQ(0x12, addr.ether_addr_octet[0]);
+  ASSERT_EQ(0x34, addr.ether_addr_octet[1]);
+  ASSERT_EQ(0x56, addr.ether_addr_octet[2]);
+  ASSERT_EQ(0x78, addr.ether_addr_octet[3]);
+  ASSERT_EQ(0x9a, addr.ether_addr_octet[4]);
+  ASSERT_EQ(0xbc, addr.ether_addr_octet[5]);
+
+  char buf[32];
+  memset(buf, 0, sizeof(buf));
+  char* p = ether_ntoa_r(&addr, buf);
+  ASSERT_EQ(buf, p);
+  ASSERT_STREQ("12-34-56-78-9A-BC", buf);
+}