commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mt...@apache.org
Subject svn commit: r1100530 - in /commons/sandbox/runtime/trunk/src/main: java/org/apache/commons/runtime/net/ native/shared/
Date Sat, 07 May 2011 13:42:14 GMT
Author: mturk
Date: Sat May  7 13:42:14 2011
New Revision: 1100530

URL: http://svn.apache.org/viewvc?rev=1100530&view=rev
Log:
Add IP address classes

Added:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java
  (with props)
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java
  (with props)
Removed:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/AbstractSocketAddress.java
Modified:
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java
    commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
    commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java?rev=1100530&r1=1100529&r2=1100530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/EndpointAddress.java
Sat May  7 13:42:14 2011
@@ -31,24 +31,19 @@ public abstract class EndpointAddress
     protected byte[] sa;
 
     private int    family;
-    private static final  int     sasize;
-    private static native int     init0();
     private static native int     family0(byte[] sa);
     private static native void    free0(byte[] sa);
     private static native boolean equals0(byte[] sa1, byte[] sa2);
     private static native String  name0(byte[] sa);
 
-    static {
-        // Gets the size of internal structure
-        //
-        sasize = init0();
-
-    }
     /**
      * Creates a new EndpointAddress object.
      */
     protected EndpointAddress()
     {
+        // Mark the family as unresolved.
+        // The next getFamily() call will return
+        // the value from the internal buffer.
         this.family = -1;
     }
     
@@ -72,14 +67,6 @@ public abstract class EndpointAddress
     }
 
     /**
-     * Returns {@code true} if the address has more elements.
-     */
-    public final boolean hasNext()
-    {
-        return sa.length > sasize;
-    }
-
-    /**
      * Returns a string representation of this endpoint.
      */
     @Override

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java?rev=1100530&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java
Sat May  7 13:42:14 2011
@@ -0,0 +1,72 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.File;
+import java.net.UnknownHostException;
+import org.apache.commons.runtime.Memory;
+import org.apache.commons.runtime.Status;
+import org.apache.commons.runtime.SystemException;
+
+/**
+ * This class represents a Internet Protocol (IP) socket endpoint
+ * described by a name and port.
+ * <p>
+ * </p>
+ */
+public class IPSocketAddress extends SocketAddress
+{
+
+    private static native int   size0();
+    private static final  int   sasize;
+
+    static {
+        // Gets the size of internal structure
+        //
+        sasize = size0();
+    }
+    
+    protected IPSocketAddress()
+    {
+        // No instance
+    }
+
+    public IPSocketAddress(String hostname, int port)
+        throws OutOfMemoryError, NetworkException
+    {
+        byte[] sa = SocketAddressImpl.getnameinfo(AddressFamily.UNSPEC, hostname, null, port);
+        SocketAddressImpl.sockaddr(this, sa);
+    }
+
+    public static final SocketAddress[] getAll(String hostname, int port)
+        throws OutOfMemoryError, NetworkException
+    {        
+        byte[] sa = SocketAddressImpl.getnameinfo(AddressFamily.UNSPEC, hostname, null, port);
+        int n = sa.length / sasize;
+        SocketAddress[] a = new SocketAddress[n];
+        for (int i = 0; i < n; i++) {
+            byte[] ba = new byte[sasize];
+            System.arraycopy(sa, i * sasize, ba, 0, sasize);
+            // Create a new SocketAddress
+            a[i] = new SocketAddressImpl(ba);
+        }
+        return a;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPSocketAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java?rev=1100530&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java
Sat May  7 13:42:14 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.File;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import org.apache.commons.runtime.Status;
+
+/**
+ * This class represents a Internet Protocol 4 (IPv4) socket endpoint
+ * described by a name and port.
+ * <p>
+ * </p>
+ */
+public final class IPv4SocketAddress extends IPSocketAddress
+{
+
+    private IPv4SocketAddress()
+    {
+        // No instance
+    }
+
+    public IPv4SocketAddress(String hostname, int port)
+        throws OutOfMemoryError, NetworkException
+    {
+        if (hostname == null || hostname.length() == 0)
+            throw new IllegalArgumentException("invalid hostname");
+        byte[] sa = SocketAddressImpl.getnameinfo(AddressFamily.INET, hostname, null, port);
+        SocketAddressImpl.sockaddr(this, sa);        
+    }
+
+    public IPv4SocketAddress(String hostname)
+        throws OutOfMemoryError, NetworkException
+    {
+        this(hostname, 0);
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv4SocketAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java?rev=1100530&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java
Sat May  7 13:42:14 2011
@@ -0,0 +1,55 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import java.io.File;
+import java.net.SocketException;
+import java.net.UnknownHostException;
+import org.apache.commons.runtime.Status;
+
+/**
+ * This class represents a Internet Protocol 6 (IPv6) socket endpoint
+ * described by a name and port.
+ * <p>
+ * </p>
+ */
+public final class IPv6SocketAddress extends IPSocketAddress
+{
+
+    private IPv6SocketAddress()
+    {
+        // No instance
+    }
+
+    public IPv6SocketAddress(String hostname, int port)
+        throws OutOfMemoryError, NetworkException
+    {
+        if (hostname == null || hostname.length() == 0)
+            throw new IllegalArgumentException("invalid hostname");
+        byte[] sa = SocketAddressImpl.getnameinfo(AddressFamily.INET6, hostname, null, port);
+        SocketAddressImpl.sockaddr(this, sa);
+    }
+
+    public IPv6SocketAddress(String hostname)
+        throws OutOfMemoryError, NetworkException
+    {
+        this(hostname, 0);
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/IPv6SocketAddress.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java?rev=1100530&r1=1100529&r2=1100530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
(original)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddress.java
Sat May  7 13:42:14 2011
@@ -33,21 +33,6 @@ public abstract class SocketAddress exte
 {
     // Hide parent field.
     // private byte[] sa;
-    /**
-     * First query for IPv4 addresses; only look
-     * for IPv6 addresses if the first query failed;
-     * only valid if family is UNSPEC and hostname
-     * isn't null; mutually exclusive with IPV6_ADDR_OK
-     */
-    private static final int IPV4_ADDR_OK  = 1;
-    /**
-     * First query for IPv6 addresses; only look
-     * for IPv4 addresses if the first query failed;
-     * only valid if family is UNSPEC and hostname
-     * isn't null; mutually exclusive with IPV4_ADDR_OK
-     */
-    private static final int IPV6_ADDR_OK  = 2;
-
     /* Structure members */
     private static native String  hostname0(byte[] sa);
     private static native String  hostname1(byte[] sa);
@@ -55,11 +40,10 @@ public abstract class SocketAddress exte
     private static native int     port0(byte[] sa);
 
     private static native String  ipaddr0(byte[] sa);
-    private static native byte[]  sockaddr0(String hostname, String servname, int family,
int port, int flags)
-        throws OutOfMemoryError, NetworkException;
     private static native int     next0(byte[] sa);
 
     private String fqdn = null;
+
     /**
      * Creates an new object
      */
@@ -75,6 +59,10 @@ public abstract class SocketAddress exte
         super(family);
     }
 
+    protected SocketAddress(byte[] sockaddr)
+    {
+        super.sa = sockaddr;
+    }
     /**
      * Create a new socket address object.
      *
@@ -82,35 +70,31 @@ public abstract class SocketAddress exte
      * @param servname a service name or a port number represented as string.
      * @param family indicates a protocl family accepted.
      */
-    protected SocketAddress(AddressFamily family, String hostname, String servname, int port,
int flags)
+    protected SocketAddress(AddressFamily family, String hostname, String servname, int port)
         throws InvalidArgumentException,
                NetworkException
     {
         super(family);
         if (family == AddressFamily.LOCAL)
             throw new InvalidArgumentException();
-        if (hostname == null) {
-            int masked = flags & (IPV4_ADDR_OK | IPV6_ADDR_OK);
-            if (family != AddressFamily.UNSPEC || masked == (IPV4_ADDR_OK | IPV6_ADDR_OK))
-                throw new InvalidArgumentException();
-            if (servname == null)
-                servname = Integer.toString(port);
+        if (hostname == null && family != AddressFamily.UNSPEC) {
+            throw new InvalidArgumentException();
         }
-        super.sa = sockaddr0(hostname, servname, family.valueOf(), port, flags);
+        super.sa = SocketAddressImpl.getnameinfo(family, hostname, servname, port);
     }
 
     protected SocketAddress(AddressFamily family, String hostname, String servname)
         throws InvalidArgumentException,
                NetworkException
     {
-        this(family, hostname, servname, 0, 0);
+        this(family, hostname, servname, 0);
     }
 
     protected SocketAddress(AddressFamily family, String hostname)
         throws InvalidArgumentException,
                NetworkException
     {
-        this(family, hostname, null, 0, 0);
+        this(family, hostname, null, 0);
     }
 
     /**
@@ -160,5 +144,4 @@ public abstract class SocketAddress exte
         return port0(super.sa);
     }
 
-
 }

Added: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java?rev=1100530&view=auto
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java
(added)
+++ commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java
Sat May  7 13:42:14 2011
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+
+package org.apache.commons.runtime.net;
+
+import org.apache.commons.runtime.InvalidArgumentException;
+
+/**
+ * This class represents a generic socket endpoint.
+ * It is used by {@link SocketAddress#next()} to create
+ * a next address object form internal sockaddr structure.  
+ */
+final class SocketAddressImpl extends SocketAddress
+{
+
+    private static native byte[]  sockaddr0(String hostname, String servname, int family,
int port, int flags)
+        throws OutOfMemoryError, NetworkException;
+
+    /**
+     * First query for IPv4 addresses; only look
+     * for IPv6 addresses if the first query failed;
+     * only valid if family is UNSPEC and hostname
+     * isn't null; mutually exclusive with IPV6_ADDR_OK
+     */
+    public static final int    IPV4_ADDR_OK  = 1;
+    /**
+     * First query for IPv6 addresses; only look
+     * for IPv4 addresses if the first query failed;
+     * only valid if family is UNSPEC and hostname
+     * isn't null; mutually exclusive with IPV4_ADDR_OK
+     */
+    public static final int    IPV6_ADDR_OK  = 2;
+
+        
+    /**
+     * Default constructor
+     */
+    public SocketAddressImpl(byte[] sockaddr)
+    {
+        super(sockaddr);
+    }
+
+    /**
+     * Create a new socket address with given family.
+     */
+    public SocketAddressImpl(AddressFamily family)
+        throws NetworkException, InvalidArgumentException
+    {
+        super(family);
+    }
+
+    public static byte[] getnameinfo(AddressFamily family, String hostname, String servname,
int port)
+        throws OutOfMemoryError, NetworkException
+    {
+        if (hostname == null && servname == null)
+            servname = Integer.toString(port);        
+        return sockaddr0(hostname, servname, family.valueOf(), port, 0);
+    }
+
+    public static void sockaddr(EndpointAddress e, byte[] ba)
+    {
+        e.sa = ba;
+    }
+
+}

Propchange: commons/sandbox/runtime/trunk/src/main/java/org/apache/commons/runtime/net/SocketAddressImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c
URL: http://svn.apache.org/viewvc/commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c?rev=1100530&r1=1100529&r2=1100530&view=diff
==============================================================================
--- commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c (original)
+++ commons/sandbox/runtime/trunk/src/main/native/shared/netaddr.c Sat May  7 13:42:14 2011
@@ -387,8 +387,8 @@ AcrInetPton(int af, const char *src, voi
     /* NOTREACHED */
 }
 
-int
-AcrGetSockaddrIp(char *buf, int buflen, acr_sockaddr_t *sockaddr)
+static int
+sockaddr_to_ipstr(char *buf, int buflen, acr_sockaddr_t *sockaddr)
 {
     if (AcrInetNtop(sockaddr->family, sockaddr->ipaddr, buf, buflen) == 0)
         return ACR_GET_OS_ERROR();
@@ -472,7 +472,7 @@ sockaddr_vars_set(acr_sockaddr_t *addr, 
 static int
 call_resolver(acr_sockaddr_t **sa, const char *hostname,
               const char *servname,
-              int family, int port, int flags)
+              int family, int port)
 {
     struct addrinfo hints, *ai, *ai_list;
     acr_sockaddr_t *new_sa;
@@ -531,26 +531,24 @@ call_resolver(acr_sockaddr_t **sa, const
 
     ai = ai_list;
     while (ai != 0) {
-        if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) {
-            ai = ai->ai_next;
-            continue;
-        }
-        ai_cnt++;
+        if (ai->ai_family == AF_INET || ai->ai_family == AF_INET6)
+            ai_cnt++;
         ai = ai->ai_next;
     }
     if (ai_cnt == 0) {
-        /* No inet addresses found
+        /* No inet/inet6 addresses found
          */
         return ACR_ENOENT;
     }
     new_sa = calloc(ai_len, ai_cnt);
-    if (sa == 0)
+    if (new_sa == 0)
         return ACR_ENOMEM;
     ai = ai_list;
     while (ai) {
         /* Ignore anything bogus: getaddrinfo in some old versions of
          * glibc will return AF_LOCAL entries for APR_UNSPEC+AI_PASSIVE
-         * lookups. */
+         * lookups.
+         */
         if (ai->ai_family != AF_INET && ai->ai_family != AF_INET6) {
             ai = ai->ai_next;
             continue;
@@ -574,30 +572,30 @@ call_resolver(acr_sockaddr_t **sa, const
     return 0;
 }
 
-int
-AcrFindAddresses(acr_sockaddr_t **sa, const char *hostname,
+static int
+find_addresses(acr_sockaddr_t **sa, const char *hostname,
                  const char *servname, int family, int port, int flags)
 {
     if (flags & ACR_IPV4_ADDR_OK) {
-        int rc = call_resolver(sa, hostname, servname, AF_INET, port, flags);
+        int rc = call_resolver(sa, hostname, servname, AF_INET, port);
         if (rc != 0)
             family = AF_INET6; /* try again */
         else
             return 0;
     }
     else if (flags & ACR_IPV6_ADDR_OK) {
-        int rc = call_resolver(sa, hostname, servname, AF_INET6, port, flags);
+        int rc = call_resolver(sa, hostname, servname, AF_INET6, port);
         if (rc != 0)
             family = AF_INET;  /* try again */
         else
             return 0;
     }
-    return call_resolver(sa, hostname, servname, family, port, flags);
+    return call_resolver(sa, hostname, servname, family, port);
 }
 
 #define GETHOSTBYNAME_BUFLEN 512
-int
-AcrGetNameInfo(const char **hostname, acr_sockaddr_t *sockaddr, int flags)
+static int
+get_hostname(const char **hostname, acr_sockaddr_t *sockaddr, int flags)
 {
     int rc;
     char tmphostname[NI_MAXHOST];
@@ -662,8 +660,8 @@ AcrGetNameInfo(const char **hostname, ac
     return 0;
 }
 
-int
-AcrGetServInfo(const char **servname, acr_sockaddr_t *sockaddr, int flags)
+static int
+get_servname(const char **servname, acr_sockaddr_t *sockaddr, int flags)
 {
     int rc;
     char tmpservname[NI_MAXSERV];
@@ -747,11 +745,6 @@ sockaddr_to_byte_array(JNI_STDENV, acr_s
 #define SOCKADDR_RELEASE(BA, SA) \
     AcrReleaseArrayCritical(env, (BA), (SA))
 
-ACR_NET_EXPORT(jint, EndpointAddress, init0)(JNI_STDARGS)
-{
-    return ISIZEOF(acr_sockaddr_t);
-}
-
 ACR_NET_EXPORT(jint, EndpointAddress, family0)(JNI_STDARGS, jbyteArray a)
 {
     jint rv = -1;
@@ -784,7 +777,7 @@ ACR_NET_EXPORT(jstring, EndpointAddress,
         if (sa->hostname[0] == '\0') {
             /* Return IP address representation
              */
-            if (AcrGetSockaddrIp(buf, 256, sa) == 0)
+            if (sockaddr_to_ipstr(buf, 256, sa) == 0)
                 name = buf;
         }
         else
@@ -874,6 +867,11 @@ ACR_NET_EXPORT(jbyteArray, LocalEndpoint
     return ba;
 }
 
+ACR_NET_EXPORT(jint, IPSocketAddress, size0)(JNI_STDARGS)
+{
+    return ISIZEOF(acr_sockaddr_t);
+}
+
 ACR_NET_EXPORT(jstring, SocketAddress, hostname0)(JNI_STDARGS, jbyteArray a)
 {
     jstring rv = 0;
@@ -884,7 +882,7 @@ ACR_NET_EXPORT(jstring, SocketAddress, h
             rv = AcrNewJavaStringA(env, sa->hostname);
         else {
             char buf[256];
-            if (AcrGetSockaddrIp(buf, 256, sa) == 0)
+            if (sockaddr_to_ipstr(buf, 256, sa) == 0)
                 rv = AcrNewJavaStringA(env, buf);
         }
     }
@@ -900,12 +898,12 @@ ACR_NET_EXPORT(jstring, SocketAddress, h
     acr_sockaddr_t *sa = SOCKADDR_CAST(a);
 
     if (sa != 0) {
-        rc = AcrGetNameInfo(&host, sa, 0);
+        rc = get_hostname(&host, sa, 0);
         if (rc == 0)
             rv = AcrNewJavaStringA(env, host);
         else {
             char buf[256];
-            if (AcrGetSockaddrIp(buf, 256, sa) == 0)
+            if (sockaddr_to_ipstr(buf, 256, sa) == 0)
                 rv = AcrNewJavaStringA(env, buf);
         }
     }
@@ -924,7 +922,7 @@ ACR_NET_EXPORT(jstring, SocketAddress, s
         if (sa->servname != '\0')
             rv = AcrNewJavaStringA(env, sa->servname);
         else {
-            rc = AcrGetServInfo(&serv, sa, 0);
+            rc = get_servname(&serv, sa, 0);
             if (rc == 0)
                 rv = AcrNewJavaStringA(env, serv);
         }
@@ -940,7 +938,7 @@ ACR_NET_EXPORT(jstring, SocketAddress, i
     acr_sockaddr_t *sa = SOCKADDR_CAST(a);
 
     if (sa != 0) {
-        if (AcrGetSockaddrIp(buf, 256, sa) == 0)
+        if (sockaddr_to_ipstr(buf, 256, sa) == 0)
             rv = AcrNewJavaStringA(env, buf);
     }
     SOCKADDR_RELEASE(a, sa);
@@ -958,28 +956,31 @@ ACR_NET_EXPORT(jint, SocketAddress, port
     return rv;
 }
 
-ACR_NET_EXPORT(jbyteArray, SocketAddress, sockaddr0)(JNI_STDARGS, jstring hostname,
-                                                     jstring servname,
-                                                     jint family, jint port, jint flags)
+ACR_NET_EXPORT(jbyteArray, SocketAddressImpl, sockaddr0)(JNI_STDARGS,
+                                                         jstring hostname,
+                                                         jstring servname,
+                                                         jint jfamily,
+                                                         jint port,
+                                                         jint flags)
 {
     acr_sockaddr_t *sa = 0;
-    int ffamily;
+    int family;
     int rc = 0;
 
-    switch (family) {
+    switch (jfamily) {
         case 1:
-            ffamily = AF_INET;
+            family = AF_INET;
         break;
         case 2:
-            ffamily = AF_INET6;
+            family = AF_INET6;
         break;
         default:
-            ffamily = AF_UNSPEC;
+            family = AF_UNSPEC;
         break;
     }
     WITH_CSTR(hostname) {
     WITH_CSTR(servname) {
-        rc = AcrFindAddresses(&sa, J2S(hostname), J2S(servname), ffamily, port, flags);
+        rc = find_addresses(&sa, J2S(hostname), J2S(servname), family, port, flags);
     } DONE_WITH_STR(servname);
     } DONE_WITH_STR(hostname);
 



Mime
View raw message