summaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authorElliott Hughes <enh@google.com>2009-11-19 18:32:43 -0800
committerElliott Hughes <enh@google.com>2009-11-20 15:39:25 -0800
commitb5fc5ecd3fe5315fc2756c0c25adc458cc8c8d91 (patch)
treea43af318dfbdadbcda40c4baccfedbf6ff5351f8 /include
parent612f6f6d8e3de940b76b0c5a1ace39fe5923be09 (diff)
downloadlibcore-b5fc5ecd3fe5315fc2756c0c25adc458cc8c8d91.zip
libcore-b5fc5ecd3fe5315fc2756c0c25adc458cc8c8d91.tar.gz
libcore-b5fc5ecd3fe5315fc2756c0c25adc458cc8c8d91.tar.bz2
Rewrite NetworkInterface's JNI for IPv6.
The old ioctl SIOCGIFCONF implementation of getNetworkInterfaces only returns IPv4 addresses. Now we've switched everything over to IPv6, that's not good enough. This change (a) implements glibc/BSD-like getifaddrs(3)/freeifaddrs(3) for Android, and (b) rewrites our getNetworkInterfaces to use that method. Of particular note is that we now do more of the work in Java. The JNI hands back a Java equivalent of getifaddrs(3)'s linked list of ifaddrs structs. The new package-private java.net.InterfaceAddress class serves as Java's "struct ifaddrs". The old implementation was also broken: SIOCGIFCONF doesn't actually return interface indexes from the kernel as the old code believed, so we were pulling the address family out of the IPv4 address it returned, leading us to assign the index 2 to all network interfaces. This caused all kinds of weird behavior later. I also had to fix GenericIPMreq so that its interface index field is actually set. The native code gets passed one of these objects when setNetworkInterface is called, so it's kind of important that the object identify which interface it's supposed to correspond to. I've also added missing copyright headers. This fixes all of the harmony tests on the simulator and on the device. It fixes several but not all of the jtreg MulticastSocket and IPv6 tests.
Diffstat (limited to 'include')
-rw-r--r--include/LocalArray.h16
-rw-r--r--include/ScopedFd.h42
2 files changed, 58 insertions, 0 deletions
diff --git a/include/LocalArray.h b/include/LocalArray.h
index 85b5a49..74c9085 100644
--- a/include/LocalArray.h
+++ b/include/LocalArray.h
@@ -1,3 +1,19 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
#ifndef LOCAL_ARRAY_H_included
#define LOCAL_ARRAY_H_included
diff --git a/include/ScopedFd.h b/include/ScopedFd.h
new file mode 100644
index 0000000..30feabd
--- /dev/null
+++ b/include/ScopedFd.h
@@ -0,0 +1,42 @@
+/*
+ * Copyright (C) 2009 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.
+ */
+
+#ifndef SCOPED_FD_H_included
+#define SCOPED_FD_H_included
+
+#include <unistd.h>
+
+// A smart pointer that closes the given fd on going out of scope.
+// Use this when the fd is incidental to the purpose of your function,
+// but needs to be cleaned up on exit.
+class ScopedFd {
+public:
+ explicit ScopedFd(int fd) : fd(fd) {
+ }
+
+ ~ScopedFd() {
+ close(fd);
+ }
+
+ int get() const {
+ return fd;
+ }
+
+private:
+ int fd;
+};
+
+#endif // SCOPED_FD_H_included