[kaffe] CVS kaffe (guilhem): MulticastSocket fixes + DatagramSocket fixes (related to InetAddress)
Kaffe CVS
Kaffe Mailing List <kaffe@kaffe.org>
Thu Oct 30 08:25:26 2003
PatchSet 4140
Date: 2003/10/30 16:22:36
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
MulticastSocket fixes + DatagramSocket fixes (related to InetAddress)
Members:
ChangeLog:1.1732->1.1733
libraries/clib/net/PlainDatagramSocketImpl.c:1.32->1.33
libraries/javalib/java/net/DatagramSocket.java:1.16->1.17
libraries/javalib/java/net/MulticastSocket.java:1.10->1.11
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1732 kaffe/ChangeLog:1.1733
--- kaffe/ChangeLog:1.1732 Thu Oct 30 14:53:56 2003
+++ kaffe/ChangeLog Thu Oct 30 16:22:36 2003
@@ -1,3 +1,17 @@
+2003-10-30 Guilhem Lavaux <guilhem@kaffe.org>
+
+ * libraries/clib/net/PlainDatagramSocketImpl.c:
+ (join, joinGroup, leave, leaveGroup, socketSetOption,
+ socketGetOption) fixed InetAddress access. Added some debug output.
+ (socketGetOption) Use in_addr and not sockaddr_in for IP_MULTICAST_IF.
+
+ * libraries/javalib/java/net/DatagramSocket.java,
+ libraries/javalib/java/net/MulticastSocket.java:
+ (DatagramSocket(SocketAddress)) Fixed behaviour according to Java 1.4
+ API
+ (MulticastSocket) Fixed construction to request previously binded
+ address.
+
2003-10-30 Dalibor Topic <robilad@kaffe.org>
* libraries/clib/io/AudioPlayer.c:
Index: kaffe/libraries/clib/net/PlainDatagramSocketImpl.c
diff -u kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.32 kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.33
--- kaffe/libraries/clib/net/PlainDatagramSocketImpl.c:1.32 Thu Oct 30 08:16:05 2003
+++ kaffe/libraries/clib/net/PlainDatagramSocketImpl.c Thu Oct 30 16:22:37 2003
@@ -452,7 +452,9 @@
{
struct in_addr ia;
- ia.s_addr = htonl(unhand(addrp)->address);
+ memcpy(&ia, unhand_byte_array(unhand(addrp)->addr),
+ sizeof(ia));
+
r = KSETSOCKOPT(unhand(unhand(this)->fd)->nativeFd,
IPPROTO_IP,
IP_MULTICAST_IF,
@@ -487,6 +489,8 @@
int vsize = sizeof(v);
struct sockaddr_in addr;
int alen = sizeof(addr);
+ struct in_addr ia;
+ int ia_len = sizeof(ia);
/* Do easy cases */
for (k = 0; k < sizeof(socketOptions) / sizeof(*socketOptions); k++) {
@@ -514,12 +518,12 @@
#if defined(IP_MULTICAST_IF)
case java_net_SocketOptions_IP_MULTICAST_IF:
r = KGETSOCKOPT(unhand(unhand(this)->fd)->nativeFd,
- IPPROTO_IP, IP_MULTICAST_IF, &addr, &alen);
+ IPPROTO_IP, IP_MULTICAST_IF, &ia, &ia_len);
if (r) {
SignalError("java.net.SocketException", SYS_ERROR(r));
return (0); /* NOT REACHED, avoid warning */
}
- r = ntohl(addr.sin_addr.s_addr);
+ r = ntohl(ia.s_addr);
break;
#endif
case java_net_SocketOptions_SO_TIMEOUT: /* JAVA takes care */
@@ -540,9 +544,15 @@
int r;
struct ip_mreq ipm;
- ipm.imr_multiaddr.s_addr = htonl(unhand(laddr)->address);
+ memcpy(&ipm.imr_multiaddr, unhand_byte_array(unhand(laddr)->addr),
+ sizeof(ipm.imr_multiaddr));
ipm.imr_interface.s_addr = htonl(INADDR_ANY);
+DBG(NATIVENET,
+ dprintf("datagram_join (%p, %p) => %s\n",
+ this, laddr, ip2str(ipm.imr_interface.s_addr));
+ )
+
r = KSETSOCKOPT(unhand(unhand(this)->fd)->nativeFd,
IPPROTO_IP, IP_ADD_MEMBERSHIP, &ipm, sizeof(ipm));
if (r) {
@@ -564,9 +574,15 @@
int r;
struct ip_mreq ipm;
- ipm.imr_multiaddr.s_addr = htonl(unhand(laddr)->address);
+ memcpy(&ipm.imr_multiaddr, unhand_byte_array(unhand(laddr)->addr),
+ sizeof(ipm.imr_multiaddr));
ipm.imr_interface.s_addr = htonl(INADDR_ANY);
+DBG(NATIVENET,
+ dprintf("datagram_leave (%p, %p) => %s\n",
+ this, laddr, ip2str(ipm.imr_interface.s_addr));
+ )
+
r = KSETSOCKOPT(unhand(unhand(this)->fd)->nativeFd,
IPPROTO_IP, IP_DROP_MEMBERSHIP, &ipm, sizeof(ipm));
if (r) {
@@ -591,18 +607,26 @@
jisa = (struct Hjava_net_InetSocketAddress *)jsa;
- ipm.imr_multiaddr.s_addr = htonl(unhand(unhand(jisa)->addr)->address);
+ memcpy(&ipm.imr_multiaddr,
+ unhand_byte_array(unhand(unhand(jisa)->addr)->addr),
+ sizeof(ipm.imr_multiaddr));
+
+DBG(NATIVENET,
+ dprintf(" datagram_joinGroup(%p, %p, %p) -> join %s\n",
+ this, jsa, jni, ip2str(ipm.imr_multiaddr.s_addr));
+ )
+
if( jni && obj_length(unhand(unhand(jni)->inetAddresses)->elementData) != 0)
{
struct Hjava_net_InetAddress* if_addr = (struct Hjava_net_InetAddress *)
unhand_object_array(unhand(unhand(jni)->inetAddresses)->elementData);
- ipm.imr_interface.s_addr =
- htonl(unhand(if_addr)->address);
+ memcpy(&ipm.imr_interface, unhand_byte_array(unhand(if_addr)->addr),
+ sizeof(ipm.imr_interface));;
}
else
{
- ipm.imr_interface.s_addr = htonl(INADDR_ANY);
+ ipm.imr_interface.s_addr = htonl(INADDR_ANY);
}
r = KSETSOCKOPT(unhand(unhand(this)->fd)->nativeFd,
@@ -632,14 +656,17 @@
jisa = (struct Hjava_net_InetSocketAddress *)jsa;
- ipm.imr_multiaddr.s_addr = htonl(unhand(unhand(jisa)->addr)->address);
+ memcpy(&ipm.imr_multiaddr,
+ unhand_byte_array(unhand(unhand(jisa)->addr)->addr),
+ sizeof(ipm.imr_multiaddr));
if( jni && obj_length(unhand(unhand(jni)->inetAddresses)->elementData) != 0)
{
struct Hjava_net_InetAddress* if_addr = (struct Hjava_net_InetAddress *)
unhand_object_array(unhand(unhand(jni)->inetAddresses)->elementData);
- ipm.imr_interface.s_addr =
- htonl(unhand(if_addr)->address);
+ memcpy(&ipm.imr_interface,
+ unhand_byte_array(unhand(if_addr)->addr),
+ sizeof(ipm.imr_interface));;
}
else
{
Index: kaffe/libraries/javalib/java/net/DatagramSocket.java
diff -u kaffe/libraries/javalib/java/net/DatagramSocket.java:1.16 kaffe/libraries/javalib/java/net/DatagramSocket.java:1.17
--- kaffe/libraries/javalib/java/net/DatagramSocket.java:1.16 Sun Sep 28 19:54:10 2003
+++ kaffe/libraries/javalib/java/net/DatagramSocket.java Thu Oct 30 16:22:38 2003
@@ -146,13 +146,24 @@
*/
public DatagramSocket(int port, InetAddress laddr) throws SocketException
{
- if (port < 0 || port > 65535)
- throw new IllegalArgumentException("Invalid port: " + port);
-
- SecurityManager s = System.getSecurityManager();
- if (s != null)
- s.checkListen(port);
+ this(new InetSocketAddress (laddr, port));
+ }
+ /**
+ * Initializes a new instance of <code>DatagramSocket</code> that binds to
+ * the specified local port and address.
+ *
+ * @param address address to bind the socket to. If address is null,
+ * the socket is left unbound.
+ *
+ * @exception SecurityException If a security manager exists and its
+ * <code>checkListen</code> method doesn't allow the operation.
+ * @exception SocketException If an error occurs.
+ *
+ * @since 1.4
+ */
+ public DatagramSocket (SocketAddress address) throws SocketException
+ {
String propVal = System.getProperty("impl.prefix");
if (propVal == null || propVal.equals(""))
impl = new PlainDatagramSocketImpl();
@@ -170,12 +181,26 @@
}
impl.create();
+ // If address is null just return immediately.
+ if (address == null)
+ return;
+
+ InetSocketAddress is_addr = (InetSocketAddress)address;
+ InetAddress laddr;
+
+ laddr = is_addr.getAddress();
if (laddr == null)
laddr = InetAddress.ANY_IF;
-
+ if (is_addr.getPort() < 0 || is_addr.getPort() > 65535)
+ throw new IllegalArgumentException("Invalid port: " + is_addr.getPort());
+
+ SecurityManager s = System.getSecurityManager();
+ if (s != null)
+ s.checkListen (is_addr.getPort());
+
try
{
- impl.bind (port, laddr);
+ impl.bind (is_addr.getPort(), laddr);
}
catch (SocketException exception)
{
@@ -192,25 +217,6 @@
impl.close ();
throw error;
}
- }
-
- /**
- * Initializes a new instance of <code>DatagramSocket</code> that binds to
- * the specified local port and address.
- *
- * @param port The local port number to bind to.
- * @param laddr The local address to bind to.
- *
- * @exception SecurityException If a security manager exists and its
- * <code>checkListen</code> method doesn't allow the operation.
- * @exception SocketException If an error occurs.
- *
- * @since 1.4
- */
- public DatagramSocket (SocketAddress address) throws SocketException
- {
- this (((InetSocketAddress) address).getPort (),
- ((InetSocketAddress) address).getAddress ());
}
/**
Index: kaffe/libraries/javalib/java/net/MulticastSocket.java
diff -u kaffe/libraries/javalib/java/net/MulticastSocket.java:1.10 kaffe/libraries/javalib/java/net/MulticastSocket.java:1.11
--- kaffe/libraries/javalib/java/net/MulticastSocket.java:1.10 Sat Aug 30 14:18:32 2003
+++ kaffe/libraries/javalib/java/net/MulticastSocket.java Thu Oct 30 16:22:38 2003
@@ -80,8 +80,9 @@
*/
public MulticastSocket() throws IOException
{
- super(0, null);
+ super((SocketAddress)null);
setReuseAddress (true);
+ bind (null);
}
/**
@@ -95,8 +96,9 @@
*/
public MulticastSocket(int port) throws IOException
{
- super(port, null);
+ super((SocketAddress)null);
setReuseAddress (true);
+ bind (new InetSocketAddress (port));
}
/**
@@ -112,8 +114,10 @@
*/
public MulticastSocket(SocketAddress address) throws IOException
{
- super(address);
+ super((SocketAddress)null);
setReuseAddress (true);
+ if (address != null)
+ bind (address);
}
/**