[1696] in java-interest

home help back first fref pref prev next nref lref last post

Re: Raw Sockets Under Java

daemon@ATHENA.MIT.EDU (winans@aps.anl.gov)
Thu Sep 14 15:29:43 1995

From: winans@aps.anl.gov
To: Aleph One <aleph1@dfw.net>
Cc: java-interest@java.sun.com
In-Reply-To: Your message of "Wed, 13 Sep 95 10:09:11 CDT."
             <Pine.SUN.3.90.950913100732.22668C-100000@dfw.net> 
Date: Thu, 14 Sep 95 10:00:44 -0500


>My last post went unanswered so here we go again.

Perhaps it is a bogus and/or ambiguous question...

>Is there anyway to create a raw socket under Java?

Would not the availability of writing raw packets post a major secutity
risk?

The simple fact that you have to be root (on a real OS) to use
SOCK_RAW, would indicate that this feature should not be present on
something that is supposed to be secure.  Even if it was present, you'd
have to run the interpreter as root for it to work.

I don't know for sure but I sincerely doubt there is raw socket support
in the distributed class 'library.'

If this is not just so many bits, you COULD void your security warranty
and get to a raw socket by writing a native snipit in C and calling it
to do that which Java does not.  But keep in mind that if you choose
this option, you will have to run your interpreter as root in order to
successfully open a SOCK_RAW.

>Is there anyway  to implement your own protocol?

With the above said, I HIGHLY suspect that you are using the term 'raw
socket' to mean a vanilla TCP connection... aka 'SOCK_STREAM' which is
WAY unlike a SOCK_RAW.  If this is the case and the prototocol you ask
to create is one that operates over a stream... munge thru the code in
classsrc/net/nntp.  I learned enough from that stuff to write an applet
that opens a socket and has a dialogue with a custom server that I
also wrote.

I enclose the top simple level on how to open a stream socket and read
data... you should 'Use the source... Luke' to get examples of how to
dialogue something like an nntp, ftp, or html server.  And use that as
an example of how to implement a protocol over a stream.

public void StreamReaderFunction()
{
	boolean		done = false;
	int		length;
	byte		buff[] = new byte[2000];
	NetworkClient	Connection;

	Connection = new NetworkClient();

	/* Open a connection to UNIX box named myhost.mydomain.net */
	/* On port number 53222 */
	Connection.openServer("myhost.mydomain.net", 53222);
	while (!done)
	{
		try
		{
			length = Connection.serverInput.read(buff, 0, buff.length);

			/* Do something interesting with the data here */
		}
		catch(Exception e)
		{
			done = true;
		}	
	}
	Connection.closeServer();
}

--John Winans
-
Note to Sun employees: this is an EXTERNAL mailing list!
Info: send 'help' to java-interest-request@java.sun.com

home help back first fref pref prev next nref lref last post