LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-03-2004, 01:00 AM   #1
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Rep: Reputation: 15
implementing ping?


Hi all.

I'm trying to implement a ping command in Java.
Yes I know Java is not the best language to do this, but I'm going to do so anyway.

I've got code that uses JNI ( to call C++ code) to do the actual ping.

Problem now is how do I listen for the responses.

I was thinking of creating an object that stores a list of hosts that I have sent pings to and their sequence numbers. Then I put a packet sniffer down and try to match responses with requests. I do this with JPcap, a module that allows you to capture packets on the network in Java.

Am I on the right track. Does any one know of any sample code, documentation or anything else that will help me.

Thanks in advance
 
Old 11-03-2004, 02:29 AM   #2
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
actually i was looking at pinging in java last week. from what i made of my googling, the accepted method isn't to ping at all, but attempt to open a socket connection to the remote site. This is becuase as you know java can't actually ping natively as it's outside of the scope fo java. but a handling a connection attempt would have a similar affect, and remain inside pure java, retaining the portability.
 
Old 11-03-2004, 02:39 AM   #3
pcdude
LQ Newbie
 
Registered: Sep 2004
Location: South Africa
Distribution: Mandrake
Posts: 26

Original Poster
Rep: Reputation: 15
I'm not sure I understand.
If i'm going to open a socket connection. My choices are TCP or UDP.
Which port will I try to open?

Thanks
 
Old 11-03-2004, 03:37 AM   #4
Scorpions4ever
LQ Newbie
 
Registered: Nov 2004
Distribution: RedHat/Fedora/Slackware/Suse
Posts: 15

Rep: Reputation: 0
Ping packets are ICMP packets actually. The ICMP layer is at the networking layer on a network stack (slightly above IP), whereas TCP and UDP are at the transport layer of a network stack. Java has lot of support for protocols at the transport layer, but not much support for protocols at the networking layer. To send an ICMP packet, you need to create a raw socket (SOCK_RAW) and java doesn't allow you to create one AFAIK. This means you can't implement ping with purely java code.
 
Old 11-03-2004, 03:57 AM   #5
acid_kewpie
Moderator
 
Registered: Jun 2001
Location: UK
Distribution: Gentoo, RHEL, Fedora, Centos
Posts: 43,396

Rep: Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963Reputation: 1963
well i have not done this, but any port on any protocol should be viable. tcp 80 would presumably be the best option, but essentially you're looking at the reason the socket connection failed (i assume this is easily catchable in java), not wether it worked or not. you should presumably be able to distinguish between "connection refused" or "host unreachable" or however the different statuses are definde. like i said, i saw this through google, and there were a number of example test classes around.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Strange Ping Issue - Can't ping localhost but can ping others on LAN code_slinger Linux - Networking 13 03-17-2011 02:47 AM
Implementing mmap Kumar Programming 0 09-08-2005 03:12 AM
implementing a firewall nitinatindore Linux - Security 1 01-04-2005 09:21 AM
implementing a graph bprasanth_20 Programming 4 10-24-2003 11:44 PM
Implementing GRsecurity int0x80 Linux - Security 13 09-30-2002 03:31 PM


All times are GMT -5. The time now is 08:38 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration