This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: Re: Datagram Problems
- From: Bryce McKinlay <bryce at waitaki dot otago dot ac dot nz>
- To: Suman Sai <saisuman at hotmail dot com>
- Cc: java at gcc dot gnu dot org, java-patches at gcc dot gnu dot org
- Date: Mon, 18 Feb 2002 20:31:42 +1300
- Subject: Patch: Re: Datagram Problems
- References: <F68De4wk2UfxhUIBSIe0000938d@hotmail.com>
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;
}