Re: faking source address in Java

New Message Reply About this list Date view Thread view Subject view Author view

Hafeez Bana (hafhat@cs.rmit.edu.au)
Fri, 25 Sep 1998 15:35:32 +1000 (EST)


Hello,

The below cannot be done.Java does not allows access to raw sockets.

However you are allowed to implement your socket routines that can
interface with java i.e extend the abstract class SocketImpl and make
native calls to C code.

i.e
class SourceSettableSocket extends SoketImpl
  {

  // implement all the abstract methods like connet,bind etc
  // only in this case have some extra native calls to C/c++ code
  // that actually do the work e.g

  public native void Sock_Connect(){
   // this wouold be called by the method Connect()
  }
  
  // you can include a native method to set the required IP header i.e
  public native void Set_Sock_Header(Name,Value){
  
  }

  }

Now since you have implemented all the neccesary methods Any Application
that uses the "normal" sockets can use your class i.e

   Socket my = new SourceSettableSocket();

and work ok...but in additon when you want to change any headers all you
will have to do is

   SourceSettableSocket my1 = (SourceSettableSocket)my;

and then call

   my1.setHeader("Source","127.0.0.1");

and the again cast it back to a normal soket and you're done!

Yours Sincerely,
Hafeez bana

On Thu, 24 Sep 1998, Lewis McCarthy wrote:

> David Honig writes:
> > I'd like to modify the *source* address of UDP datagrams
> > sent from an application written in Java. Anyone know
> > how to do this? Levels below DatagramPackets seem opaque...
>
> I suspect this can't be done within Java, but would be interested to learn otherwise.
>
> I assume that java.net.DatagramSocket.send() uses a native sockets API to hand off the
> outgoing DatagramPacket payload (and dest IP/port) to the transport layer. Typically
> (AFAIK) sockets APIs don't provide facilities for an application to set the src IP addr.
>
> -Lewis
> "It depends on what the meaning of the word `is` is."
>

--------------------------------------------------------------------------
Homepage: http://yallara.cs.rmit.edu.au/~hafhat

"Normal is not something to aspire to, it is something to get away from"
        -Jodie Foster
"The Measure of a man is not by what he has or has not done for others, but
by what he has done for himself"
        -Ayn Rand


New Message Reply About this list Date view Thread view Subject view Author view

 
All trademarks and copyrights are the property of their respective owners.

Other Directory Sites: SeekWonder | Directory Owners Forum

The following archive was created by hippie-mail 7.98617-22 on Sat Apr 10 1999 - 01:14:01