This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
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


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
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: 78
Can I get source ip address and destination ip address of udp packet?
Jaikiran Pai
Marshal

Joined: Jul 20, 2005
Posts: 9317
    
109

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: 78


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: 19541
    
  16

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: 78
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?
 
Similar Threads
data packet or control packet?
TCP, UDP,IP
response time
server socket and accept call
VPN