aspose file tools*
The moose likes Sockets and Internet Protocols and the fly likes Can I get source ip address and destination ip address of udp packet? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Sockets and Internet Protocols
Bookmark "Can I get source ip address and destination ip address of udp packet?" Watch "Can I get source ip address and destination ip address of udp packet?" New topic
Author

Can I get source ip address and destination ip address of udp packet?

vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 80
Can I get source ip address and destination ip address of udp packet?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 10046
    
163

See http://download.oracle.com/javase/6/docs/api/java/net/DatagramPacket.html#getSocketAddress%28%29

[My Blog] [JavaRanch Journal]
vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 80


It will give information of Source address only.

actually I have one udp server in java at localhost and have some virtual interfaces on it.

now I send udp packet on this server at one virtual interface(say eth0:1). I received that packet but when extract information of source address only.

while i see tcpdump it will give information of source and destination.

that's why i am asking here if tcpdump get information of source and destination then java should have some api to get these information.

Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19670
    
  18

If you click on that link you are sure to see a few other methods that return other addresses. Try those first.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
vikas byn
Ranch Hand

Joined: Mar 18, 2011
Posts: 80
Rob Spoor wrote:If you click on that link you are sure to see a few other methods that return other addresses. Try those first.


i tried it there are two methods for getting ip information - public SocketAddress getSocketAddress() and public InetAddress getAddress() - they give same address information.

actually i need three things - payload, source address and destination address (which is virtual interface in my case).

please forgive me for my bad english.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can I get source ip address and destination ip address of udp packet?