ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
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.
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.
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.
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.