This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Patch: Re: Datagram Problems


Suman Sai wrote:

> Hello, everyone.
>
> Thanks, Bryce, for responding to my earlier query. Here's a code 
> snippet, the one that doesn't work. I get "Network Unreachable". Could 
> you please tell me why this is happening? 


Thanks for the test case, Suman. This is a bug in libgcj. I'm checking 
in the patch below which fixes it.

regards

Bryce.


2002-02-18  Bryce McKinlay  <bryce@waitaki.otago.ac.nz>

	* java/net/natPlainDatagramSocketImpl.cc (bind): Call setsockopt to
	enable SO_BROADCAST.

Index: natPlainDatagramSocketImpl.cc
===================================================================
RCS file: /cvs/gcc/egcs/libjava/java/net/natPlainDatagramSocketImpl.cc,v
retrieving revision 1.30
diff -u -r1.30 natPlainDatagramSocketImpl.cc
--- natPlainDatagramSocketImpl.cc	2002/02/07 03:24:01	1.30
+++ natPlainDatagramSocketImpl.cc	2002/02/18 07:26:42
@@ -194,7 +194,6 @@
 java::net::PlainDatagramSocketImpl::bind (jint lport,
 					  java::net::InetAddress *host)
 {
-  // FIXME: prob. need to do a setsockopt with SO_BROADCAST to allow multicast.
   union SockAddr u;
   struct sockaddr *ptr = (struct sockaddr *) &u.address;
   // FIXME: Use getaddrinfo() to get actual protocol instead of assuming ipv4.
@@ -232,6 +231,11 @@
       else if (::getsockname (fnum, (sockaddr*) &u, &addrlen) == 0)
         localPort = ntohs (u.address.sin_port);
       else
+        goto error;
+      /* Allow broadcast by default. */
+      int broadcast = 1;
+      if (::setsockopt (fnum, SOL_SOCKET, SO_BROADCAST, (char *) &broadcast, 
+                        sizeof (broadcast)) != 0)
         goto error;
       return;
     }

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]