You can subscribe to this list here.
| 2006 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(123) |
Dec
(100) |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 2007 |
Jan
(12) |
Feb
(80) |
Mar
(35) |
Apr
|
May
|
Jun
(28) |
Jul
(10) |
Aug
(6) |
Sep
|
Oct
|
Nov
(16) |
Dec
|
| 2008 |
Jan
|
Feb
|
Mar
(8) |
Apr
|
May
|
Jun
|
Jul
|
Aug
(1) |
Sep
|
Oct
|
Nov
(1) |
Dec
(6) |
| 2009 |
Jan
(20) |
Feb
(1) |
Mar
(19) |
Apr
(12) |
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
(3) |
Dec
|
|
From: Peter P. <pr...@us...> - 2006-11-24 13:58:59
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23148/src/edu/harvard/syrah/pyxida Modified Files: Pyxida.java Log Message: Added cmd line switch (-d) to turn on debugging output. Index: Pyxida.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/Pyxida.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Pyxida.java 21 Nov 2006 21:15:00 -0000 1.4 --- Pyxida.java 24 Nov 2006 13:58:57 -0000 1.5 *************** *** 50,55 **** public static void main(String[] args) { log.main("Pyxida Version " + PYXIDA_VERSION + " starting..."); ! ! Log.setPackageRoot(Pyxida.class); // Turn on assertions --- 50,61 ---- public static void main(String[] args) { log.main("Pyxida Version " + PYXIDA_VERSION + " starting..."); ! ! if (args.length > 0 && args[0].equals("-d")) { ! Log.setPackageRoot(Pyxida.class); ! String[] newArgs = new String[args.length - 1]; ! for (int i = 0; i < newArgs.length; i++) ! newArgs[i] = args[i]; ! args = newArgs; ! } // Turn on assertions |
|
From: Peter P. <pr...@us...> - 2006-11-24 13:58:59
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv23148/src/edu/harvard/syrah/pyxida/ping Modified Files: TCPSynPinger.java ICMPPinger.java Log Message: Added cmd line switch (-d) to turn on debugging output. Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** ICMPPinger.java 24 Nov 2006 12:06:22 -0000 1.7 --- ICMPPinger.java 24 Nov 2006 13:58:57 -0000 1.8 *************** *** 7,10 **** --- 7,11 ---- import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.pyxida.Pyxida; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.EventLoop; *************** *** 117,123 **** } ! public static void main(final String[] args) { ANSI.use(true); ! //Log.setPackageRoot(ICMPPinger.class); EventLoop.set(new EventLoop()); --- 118,131 ---- } ! public static void main(String[] args) { ANSI.use(true); ! ! if (args.length > 0 && args[0].equals("-d")) { ! Log.setPackageRoot(Pyxida.class); ! String[] newArgs = new String[args.length - 1]; ! for (int i = 0; i < newArgs.length; i++) ! newArgs[i] = args[i + 1]; ! args = newArgs; ! } EventLoop.set(new EventLoop()); *************** *** 130,133 **** --- 138,143 ---- final PingerIF pinger = new ICMPPinger(); + final String hostname = args[0]; + EventLoop.get().registerTimerCB(new CB0() { protected void cb(CBResult resultOK) { *************** *** 138,142 **** pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { ! AddressFactory.createResolved(args[0], new CB1<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { switch (result.state) { --- 148,152 ---- pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { ! AddressFactory.createResolved(hostname, new CB1<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { switch (result.state) { Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** TCPSynPinger.java 24 Nov 2006 13:48:06 -0000 1.6 --- TCPSynPinger.java 24 Nov 2006 13:58:57 -0000 1.7 *************** *** 8,11 **** --- 8,12 ---- import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.PUtil; + import edu.harvard.syrah.pyxida.Pyxida; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.EventLoop; *************** *** 121,127 **** } ! public static void main(final String[] args) { ANSI.use(true); ! Log.setPackageRoot(TCPSynPinger.class); EventLoop.set(new EventLoop()); --- 122,135 ---- } ! public static void main(String[] args) { ANSI.use(true); ! ! if (args.length > 0 && args[0].equals("-d")) { ! Log.setPackageRoot(Pyxida.class); ! String[] newArgs = new String[args.length - 1]; ! for (int i = 0; i < newArgs.length; i++) ! newArgs[i] = args[i + 1]; ! args = newArgs; ! } EventLoop.set(new EventLoop()); *************** *** 132,135 **** --- 140,145 ---- } + final String hostname = args[0]; + final PingerIF pinger = new TCPSynPinger(); *************** *** 142,146 **** pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { ! AddressFactory.createResolved(args[0], new CB1<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { switch (result.state) { --- 152,156 ---- pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { ! AddressFactory.createResolved(hostname, new CB1<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { switch (result.state) { |
|
From: Peter P. <pr...@us...> - 2006-11-24 13:48:09
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19249/src/edu/harvard/syrah/pyxida/ping Modified Files: TCPSynPinger.java JpcapPinger.java Log Message: * Fixed an issue where TCPSyn would send a packet twice. * Added a random src port allocation, otherwise the kernel is confused Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** TCPSynPinger.java 24 Nov 2006 12:06:22 -0000 1.5 --- TCPSynPinger.java 24 Nov 2006 13:48:06 -0000 1.6 *************** *** 7,10 **** --- 7,11 ---- import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.prp.PUtil; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.EventLoop; *************** *** 33,42 **** case OK : { log.debug("pd.recvPacket=" + pd.recvPacket); ! pd.recvTS = parseTCP(pd.recvPacket, pd.pingAddr); assert pd.sendTS > 0; assert pd.recvTS > pd.sendTS : "send TS (" + pd.sendTS + ") > recv TS (" + pd.recvTS + ")?"; long lat = pd.recvTS - pd.sendTS; log.debug("lat=" + lat + " pd.recvTS=" + pd.recvTS); ! cbPing.call(result, lat / 1000.0); break; --- 34,44 ---- case OK : { log.debug("pd.recvPacket=" + pd.recvPacket); ! processTCP(pd); assert pd.sendTS > 0; assert pd.recvTS > pd.sendTS : "send TS (" + pd.sendTS + ") > recv TS (" + pd.recvTS + ")?"; long lat = pd.recvTS - pd.sendTS; log.debug("lat=" + lat + " pd.recvTS=" + pd.recvTS); ! ! removeRequest(); cbPing.call(result, lat / 1000.0); break; *************** *** 53,74 **** addRequest(pd); ! ! pd.sendPacket = sendTCPSyn(pd.pingAddr); ! try { ! pd.sendTS = System.nanoTime() / 1000; ! log.debug("Sending TCPSyn"); ! sender.sendPacket(pd.sendPacket); ! log.debug("Done"); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! log.debug("sendPacket=" + pd.sendPacket + " sendTS=" + pd.sendTS); ! assert pd.sendTS > 0; } ! private Packet sendTCPSyn(AddressIF pingAddr) { ! TCPPacket tcp = new TCPPacket(PING_SRC_PORT, PING_DST_PORT, 0, 0, false, false, false, false, true, false, true, true, 23360, 0); tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, ! thisIP, pingAddr.getInetAddress()); tcp.data = new byte[0]; --- 55,67 ---- addRequest(pd); ! sendTCPSyn(pd); } ! private void sendTCPSyn(JpcapPingData pd) { ! log.debug("Sending TCP syn"); ! ! TCPPacket tcp = new TCPPacket(PUtil.getRandomInt() % 65535, PING_DST_PORT, 0, 0, false, false, false, false, true, false, false, false, 23360, 0); tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, ! thisIP, pd.pingAddr.getInetAddress()); tcp.data = new byte[0]; *************** *** 78,91 **** ether.dst_mac = gwMAC; tcp.datalink = ether; ! sender.sendPacket(tcp); ! return tcp; } ! private Packet sendTCPRst(AddressIF pingAddr) { ! TCPPacket tcp = new TCPPacket(PING_SRC_PORT, PING_DST_PORT, 0, 0, false, false, false, true, false, false, true, true, 23360, 10); tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, ! thisIP, pingAddr.getInetAddress()); tcp.data = new byte[0]; --- 71,91 ---- ether.dst_mac = gwMAC; tcp.datalink = ether; + + pd.sendTS = System.nanoTime() / 1000; + sender.sendPacket(tcp); ! pd.sendPacket = tcp; ! log.debug("Done: sendPacket=" + pd.sendPacket + " sendTS=" + pd.sendTS); ! assert pd.sendTS > 0; } ! /* ! private void sendTCPRst(JpcapPingData pd) { ! assert false; ! log.debug("Sending TCP rst"); ! TCPPacket tcp = new TCPPacket(0, PING_DST_PORT, 0, 0, false, false, false, true, false, false, true, true, 23360, 10); tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, ! thisIP, pd.pingAddr.getInetAddress()); tcp.data = new byte[0]; *************** *** 96,122 **** tcp.datalink = ether; ! sender.sendPacket(tcp); ! ! return tcp; } ! private long parseTCP(Packet p, AddressIF pingAddr) { log.debug("p=" + p + " p.class=" + (p != null ? p.getClass() : null)); - long recvTS = Long.MIN_VALUE; TCPPacket tcp = (TCPPacket) p; long sec = p.sec; long usec = p.usec; ! recvTS = (sec * 1000 * 1000) + usec; ! log.debug("recvTS=" + recvTS); ! ! // Close the connection properly if we hit an open port ! if (tcp.ack) { ! sendTCPRst(pingAddr); ! removeRequest(); ! } ! ! return recvTS; } --- 96,118 ---- tcp.datalink = ether; ! sender.sendPacket(tcp); ! log.debug("Done."); } + */ ! private void processTCP(JpcapPingData pd) { ! Packet p = pd.recvPacket; log.debug("p=" + p + " p.class=" + (p != null ? p.getClass() : null)); TCPPacket tcp = (TCPPacket) p; long sec = p.sec; long usec = p.usec; ! pd.recvTS = (sec * 1000 * 1000) + usec; ! log.debug("recvTS=" + pd.recvTS); ! ! /* ! * We don't need to send a rst here because the kernel does it for us. ! */ } *************** *** 127,131 **** public static void main(final String[] args) { ANSI.use(true); ! //Log.setPackageRoot(TCPSynPinger.class); EventLoop.set(new EventLoop()); --- 123,127 ---- public static void main(final String[] args) { ANSI.use(true); ! Log.setPackageRoot(TCPSynPinger.class); EventLoop.set(new EventLoop()); Index: JpcapPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/JpcapPinger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** JpcapPinger.java 24 Nov 2006 12:06:22 -0000 1.3 --- JpcapPinger.java 24 Nov 2006 13:48:06 -0000 1.4 *************** *** 34,38 **** protected static final long PING_TIMEOUT = 3000; ! protected static final int PING_SRC_PORT = 55000; private static JpcapCaptor captor; --- 34,38 ---- protected static final long PING_TIMEOUT = 3000; ! //protected static final int PING_SRC_PORT = 55000; private static JpcapCaptor captor; *************** *** 179,183 **** public void run() { ! captor.setFilter("dst host " + thisIP.getHostAddress() + " and dst port " + PING_SRC_PORT + " and (icmp or (tcp and tcp[tcpflags] & (tcp-rst|tcp-ack) != 0))", true); //captor.setFilter("icmp", true); --- 179,183 ---- public void run() { ! captor.setFilter("dst host " + thisIP.getHostAddress() + " and (icmp or (tcp and tcp[tcpflags] & (tcp-syn|tcp-ack) != 0))", true); //captor.setFilter("icmp", true); |
|
From: Peter P. <pr...@us...> - 2006-11-24 13:48:09
|
Update of /cvsroot/pyxida/Pyxida/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19249/lib Modified Files: util-prp.jar Log Message: * Fixed an issue where TCPSyn would send a packet twice. * Added a random src port allocation, otherwise the kernel is confused Index: util-prp.jar =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/util-prp.jar,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 Binary files /tmp/cvsRZ7eYP and /tmp/cvsHcBQx4 differ |
|
From: Peter P. <pr...@us...> - 2006-11-24 12:06:26
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14750/src/edu/harvard/syrah/pyxida/ping Modified Files: TCPSynPinger.java ICMPPinger.java Pinger.java JpcapPinger.java Log Message: Added a TCPSynPinger. It appears to work. You can use it to ping both open and closed ports. Index: Pinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/Pinger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** Pinger.java 24 Nov 2006 10:53:27 -0000 1.3 --- Pinger.java 24 Nov 2006 12:06:22 -0000 1.4 *************** *** 1,8 **** --- 1,16 ---- package edu.harvard.syrah.pyxida.ping; + import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.sbon.async.CBResult; + import edu.harvard.syrah.sbon.async.EventLoop; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; abstract class Pinger implements PingerIF { + private static final Log log = new Log(Pinger.class); + private static final long PING_DELAY = 1000; + protected AddressIF localAddr; protected AddressIF defaultPingAddr; *************** *** 16,19 **** --- 24,41 ---- double lat; } + + public void testPing(final AddressIF remoteNode) { + System.out.print(" Sending ping... "); + ping(remoteNode, new CB1<Double>() { + protected void cb(CBResult result, Double lat) { + System.out.println(lat == 0 ? "Timeout" : "lat=" + (lat > 0 ? lat : "Neg")); + EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { + protected void cb(CBResult result) { + testPing(remoteNode); + } + }); + } + }); + } } Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** TCPSynPinger.java 23 Nov 2006 23:22:48 -0000 1.4 --- TCPSynPinger.java 24 Nov 2006 12:06:22 -0000 1.5 *************** *** 1,56 **** package edu.harvard.syrah.pyxida.ping; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; class TCPSynPinger extends JpcapPinger implements PingerIF { private static final Log log = new Log(TCPSynPinger.class); - - public double ping(AddressIF remoteNode) throws UnsupportedOperationException { - // TODO Auto-generated method stub - return 0; - } ! public double ping(AddressIF nodeA, AddressIF nodeB) throws UnsupportedOperationException { ! // TODO Auto-generated method stub ! return 0; } ! ! public void init(AddressIF defaultPingAddr) { ! // TODO Auto-generated method stub ! } ! public void shutdown() { ! // TODO Auto-generated method stub } ! public void run() { ! // TODO Auto-generated method stub } ! public void init(AddressIF defaultPingAddr, CB0 cbDone) { ! // TODO Auto-generated method stub } ! public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { ! // TODO Auto-generated method stub } public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException { ! // TODO Auto-generated method stub ! } ! ! public void testPing(AddressIF remoteNode) { ! // TODO Auto-generated method stub ! } } --- 1,179 ---- package edu.harvard.syrah.pyxida.ping; + import jpcap.packet.EthernetPacket; + import jpcap.packet.IPPacket; + import jpcap.packet.Packet; + import jpcap.packet.TCPPacket; + import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.sbon.async.CBResult; + import edu.harvard.syrah.sbon.async.EventLoop; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; + import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; class TCPSynPinger extends JpcapPinger implements PingerIF { private static final Log log = new Log(TCPSynPinger.class); ! protected static final int PING_DST_PORT = 80; ! ! public void init(AddressIF defaultPingAddr, final CB0 cbDone) { ! super.init(defaultPingAddr, cbDone); } ! ! public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { ! log.debug("Sending new ping to remoteNode=" + remoteNode + ":" + PING_DST_PORT + " using TCPSyn"); ! final JpcapPingData pd = new JpcapPingData(); ! pd.pingAddr = remoteNode; ! pd.cbDone = new CB0(PING_TIMEOUT) { ! protected void cb(CBResult result) { ! switch (result.state) { ! case OK : { ! log.debug("pd.recvPacket=" + pd.recvPacket); ! pd.recvTS = parseTCP(pd.recvPacket, pd.pingAddr); ! assert pd.sendTS > 0; ! assert pd.recvTS > pd.sendTS : "send TS (" + pd.sendTS + ") > recv TS (" + pd.recvTS + ")?"; ! long lat = pd.recvTS - pd.sendTS; ! log.debug("lat=" + lat + " pd.recvTS=" + pd.recvTS); ! ! cbPing.call(result, lat / 1000.0); ! break; ! } ! case TIMEOUT: ! case ERROR: { ! removeRequest(); ! cbPing.call(result, 0.0); ! break; ! } ! } ! } ! }; ! addRequest(pd); + pd.sendPacket = sendTCPSyn(pd.pingAddr); + try { + pd.sendTS = System.nanoTime() / 1000; + log.debug("Sending TCPSyn"); + sender.sendPacket(pd.sendPacket); + log.debug("Done"); + } catch (Exception e) { + log.warn("Failed sending packet: " + e); + } + log.debug("sendPacket=" + pd.sendPacket + " sendTS=" + pd.sendTS); + assert pd.sendTS > 0; } ! private Packet sendTCPSyn(AddressIF pingAddr) { ! TCPPacket tcp = new TCPPacket(PING_SRC_PORT, PING_DST_PORT, 0, 0, false, false, false, false, true, false, true, true, 23360, 0); ! tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, ! thisIP, pingAddr.getInetAddress()); ! tcp.data = new byte[0]; ! ! EthernetPacket ether = new EthernetPacket(); ! ether.frametype = EthernetPacket.ETHERTYPE_IP; ! ether.src_mac = device.mac_address; ! ether.dst_mac = gwMAC; ! tcp.datalink = ether; ! ! sender.sendPacket(tcp); + return tcp; } + + private Packet sendTCPRst(AddressIF pingAddr) { + TCPPacket tcp = new TCPPacket(PING_SRC_PORT, PING_DST_PORT, 0, 0, false, false, false, true, false, false, true, true, 23360, 10); + tcp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, IPPacket.IPPROTO_TCP, + thisIP, pingAddr.getInetAddress()); + tcp.data = new byte[0]; ! EthernetPacket ether = new EthernetPacket(); ! ether.frametype = EthernetPacket.ETHERTYPE_IP; ! ether.src_mac = device.mac_address; ! ether.dst_mac = gwMAC; ! tcp.datalink = ether; ! ! sender.sendPacket(tcp); + return tcp; } + + private long parseTCP(Packet p, AddressIF pingAddr) { + log.debug("p=" + p + " p.class=" + (p != null ? p.getClass() : null)); ! long recvTS = Long.MIN_VALUE; ! TCPPacket tcp = (TCPPacket) p; ! ! long sec = p.sec; ! long usec = p.usec; ! recvTS = (sec * 1000 * 1000) + usec; ! log.debug("recvTS=" + recvTS); + // Close the connection properly if we hit an open port + if (tcp.ack) { + sendTCPRst(pingAddr); + removeRequest(); + } + + return recvTS; } public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException { ! throw new UnsupportedOperationException(); } ! ! public static void main(final String[] args) { ! ANSI.use(true); ! //Log.setPackageRoot(TCPSynPinger.class); ! EventLoop.set(new EventLoop()); + if (args.length == 0) { + System.out.println("usage: TCPSynPinger <hostname>"); + System.exit(1); + } + + final PingerIF pinger = new TCPSynPinger(); + + EventLoop.get().registerTimerCB(new CB0() { + protected void cb(CBResult resultOK) { + AddressFactory.createResolved("www.google.com", new CB1<AddressIF>() { + protected void cb(CBResult result, AddressIF defaultAddr) { + switch (result.state) { + case OK: { + pinger.init(defaultAddr, new CB0() { + protected void cb(CBResult arg0) { + AddressFactory.createResolved(args[0], new CB1<AddressIF>() { + protected void cb(CBResult result, AddressIF addr) { + switch (result.state) { + case OK: { + System.out.println("Pinging addr=" + addr + ":" + PING_DST_PORT + " using TCPSyn"); + pinger.testPing(addr); + break; + } + case ERROR: + case TIMEOUT: { + log.error(result.what); + } + } + } + }); + } + }); + break; + } + case ERROR: + case TIMEOUT: { + log.error(result.what); + } + } + } + }); + } + }); + EventLoop.get().main(); + } + } Index: JpcapPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/JpcapPinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** JpcapPinger.java 24 Nov 2006 10:53:27 -0000 1.2 --- JpcapPinger.java 24 Nov 2006 12:06:22 -0000 1.3 *************** *** 31,35 **** private static final Log log = new Log(JpcapPinger.class); ! private static final long CAPTION_TIMEOUT = 5000; private static JpcapCaptor captor; --- 31,38 ---- private static final Log log = new Log(JpcapPinger.class); ! private static final long CAPTION_TIMEOUT = -1; ! protected static final long PING_TIMEOUT = 3000; ! ! protected static final int PING_SRC_PORT = 55000; private static JpcapCaptor captor; *************** *** 166,174 **** protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; } public void run() { ! captor.setFilter("icmp and dst host " + thisIP.getHostAddress(), true); //captor.setFilter("icmp", true); --- 169,183 ---- protected void addRequest(JpcapPingData pd) { + // Assume that there's not other ping that is waiting for a response + assert JpcapPinger.currentPing == null; JpcapPinger.currentPing = pd; } + protected void removeRequest() { + JpcapPinger.currentPing = null; + } + public void run() { ! captor.setFilter("dst host " + thisIP.getHostAddress() + " and dst port " + PING_SRC_PORT + " and (icmp or (tcp and tcp[tcpflags] & (tcp-rst|tcp-ack) != 0))", true); //captor.setFilter("icmp", true); Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** ICMPPinger.java 24 Nov 2006 10:53:27 -0000 1.6 --- ICMPPinger.java 24 Nov 2006 12:06:22 -0000 1.7 *************** *** 16,22 **** class ICMPPinger extends JpcapPinger implements PingerIF { private static final Log log = new Log(JpcapPinger.class); - - private static final long PING_DELAY = 1000; - private static final long PING_TIMEOUT = 3000; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { --- 16,19 ---- *************** *** 24,59 **** } - public void testPing(final AddressIF remoteNode) { - System.out.print(" Sending ping... "); - ping(remoteNode, new CB1<Double>() { - protected void cb(CBResult result, Double lat) { - System.out.println(lat == 0 ? "Timeout" : "lat=" + (lat > 0 ? lat : "Neg")); - EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { - protected void cb(CBResult result) { - testPing(remoteNode); - } - }); - } - }); - } - public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { ! log.debug("Sending new ping to remoteNode=" + remoteNode); final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; pd.cbDone = new CB0(PING_TIMEOUT) { ! protected void cb(CBResult resultOK) { ! log.debug("pd.recvPacket=" + pd.recvPacket); ! pd.recvTS = parseICMP(pd.recvPacket); ! log.debug("pd.recvTS=" + pd.recvTS); ! long lat = 0; ! if (pd.recvTS > 0) { ! assert pd.sendTS > 0; ! assert pd.recvTS > pd.sendTS : "send TS > recv TS ?"; ! lat = pd.recvTS - pd.sendTS; } - log.debug("lat=" + lat); - cbPing.call(resultOK, lat / 1000.0); } }; --- 21,49 ---- } public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { ! log.debug("Sending new ping to remoteNode=" + remoteNode + " using ICMP"); final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; pd.cbDone = new CB0(PING_TIMEOUT) { ! protected void cb(CBResult result) { ! switch (result.state) { ! case OK : { ! log.debug("pd.recvPacket=" + pd.recvPacket); ! pd.recvTS = parseICMP(pd.recvPacket); ! assert pd.sendTS > 0; ! assert pd.recvTS > pd.sendTS : "send TS > recv TS ?"; ! long lat = pd.recvTS - pd.sendTS; ! log.debug("lat=" + lat + " pd.recvTS=" + pd.recvTS); ! cbPing.call(result, lat / 1000.0); ! break; ! } ! case TIMEOUT: ! case ERROR: { ! removeRequest(); ! cbPing.call(result, 0.0); ! break; ! } } } }; *************** *** 68,73 **** } pd.sendTS = System.nanoTime() / 1000; ! log.debug("sendPacket=" + pd.sendPacket); ! log.debug("sendTS=" + pd.sendTS); assert pd.sendTS > 0; } --- 58,62 ---- } pd.sendTS = System.nanoTime() / 1000; ! log.debug("sendPacket=" + pd.sendPacket + " sendTS=" + pd.sendTS); assert pd.sendTS > 0; } *************** *** 123,127 **** recvTS = (sec * 1000 * 1000) + usec; log.debug("recvTS=" + recvTS); ! } log.debug("Finished parseICMP"); return recvTS; --- 112,116 ---- recvTS = (sec * 1000 * 1000) + usec; log.debug("recvTS=" + recvTS); ! } log.debug("Finished parseICMP"); return recvTS; |
|
From: Peter P. <pr...@us...> - 2006-11-24 12:06:26
|
Update of /cvsroot/pyxida/Pyxida/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14750/test Added Files: TCPSynPinger Log Message: Added a TCPSynPinger. It appears to work. You can use it to ping both open and closed ports. --- NEW FILE: TCPSynPinger --- #!/bin/bash cd .. export LD_LIBRARY_PATH=`pwd`/lib/jpcap-0.5.1-lib/src/c/ #java -ea -cp classes:../SBON/classes:lib/util-prp.jar:lib/jpcap.jar edu.harvard.syrah.pyxida.ping.ICMPPinger $@ java -ea -cp classes:lib/sbon-async.jar:lib/util-prp.jar:lib/jpcap.jar edu.harvard.syrah.pyxida.ping.TCPSynPinger $@ |
|
From: Peter P. <pr...@us...> - 2006-11-24 10:53:29
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19223/src/edu/harvard/syrah/pyxida/ping Modified Files: ICMPPinger.java Pinger.java JpcapPinger.java Log Message: Found a workaround for the timeout issue. If there's no response to am ICMP echo request, you should receive a timeout message. Index: Pinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/Pinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** Pinger.java 23 Nov 2006 23:22:48 -0000 1.2 --- Pinger.java 24 Nov 2006 10:53:27 -0000 1.3 *************** *** 1,5 **** package edu.harvard.syrah.pyxida.ping; - import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; --- 1,4 ---- *************** *** 16,20 **** AddressIF pingAddr; double lat; - CB1<Double> cbLat; } --- 15,18 ---- Index: JpcapPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/JpcapPinger.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JpcapPinger.java 23 Nov 2006 23:22:48 -0000 1.1 --- JpcapPinger.java 24 Nov 2006 10:53:27 -0000 1.2 *************** *** 13,16 **** --- 13,17 ---- import jpcap.NetworkInterfaceAddress; import jpcap.packet.EthernetPacket; + import jpcap.packet.IPPacket; import jpcap.packet.Packet; import edu.harvard.syrah.prp.Log; *************** *** 33,37 **** private static JpcapCaptor captor; ! private static JpcapSender sender; protected static NetworkInterface device; --- 34,38 ---- private static JpcapCaptor captor; ! protected static JpcapSender sender; protected static NetworkInterface device; *************** *** 51,55 **** } ! protected static JpcapPingData currentPing; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { --- 52,56 ---- } ! private static JpcapPingData currentPing; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { *************** *** 166,205 **** protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; - synchronized(jpcapThread) { - jpcapThread.notify(); - } } public void run() { ! try { while (!jpcapThread.isInterrupted()) { ! if (currentPing == null) { ! synchronized (jpcapThread) { ! jpcapThread.wait(); ! } ! } ! ! if (currentPing != null) { ! AddressIF pingAddr = currentPing.pingAddr; ! Packet packet = currentPing.sendPacket; ! captor.setFilter("icmp and src host " + pingAddr.getHostname(), true); ! currentPing.sendTS = System.nanoTime() / 1000; ! try { ! sender.sendPacket(packet); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! log.debug("sendPacket=" + packet); ! log.debug("sendTS=" + currentPing.sendTS); ! assert currentPing.sendTS > 0; ! currentPing.recvPacket = captor.getPacket(); ! log.debug("Received packet: " + currentPing.recvPacket); EventLoop.get().registerTimerCB(currentPing.cbDone); currentPing = null; } - } - } catch (InterruptedException e) { /* ignore */ } } --- 167,190 ---- protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; } public void run() { ! captor.setFilter("icmp and dst host " + thisIP.getHostAddress(), true); ! //captor.setFilter("icmp", true); ! while (!jpcapThread.isInterrupted()) { ! IPPacket ip = null; ! do { ! log.debug("Waiting for a packet..."); ! ip = (IPPacket) captor.getPacket(); ! log.debug("Captured a packet: ip=" + ip + " src=" + ip.src_ip); ! } while (currentPing == null || !ip.src_ip.equals(currentPing.pingAddr.getInetAddress())); ! currentPing.recvPacket = ip; ! log.debug("Received packet: " + currentPing.recvPacket); EventLoop.get().registerTimerCB(currentPing.cbDone); currentPing = null; } } Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** ICMPPinger.java 23 Nov 2006 23:22:48 -0000 1.5 --- ICMPPinger.java 24 Nov 2006 10:53:27 -0000 1.6 *************** *** 18,21 **** --- 18,22 ---- private static final long PING_DELAY = 1000; + private static final long PING_TIMEOUT = 3000; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { *************** *** 27,31 **** ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println("lat=" + (lat > 0 ? lat : "Timeout")); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { --- 28,32 ---- ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println(lat == 0 ? "Timeout" : "lat=" + (lat > 0 ? lat : "Neg")); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { *************** *** 38,55 **** public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; ! pd.cbLat = cbPing; ! pd.sendPacket = createICMP(remoteNode); ! pd.cbDone = new CB0() { protected void cb(CBResult resultOK) { pd.recvTS = parseICMP(pd.recvPacket); long lat = 0; ! if (pd.recvTS > 0) lat = pd.recvTS - pd.sendTS; cbPing.call(resultOK, lat / 1000.0); } }; ! addRequest(pd); } --- 39,74 ---- public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { + log.debug("Sending new ping to remoteNode=" + remoteNode); final JpcapPingData pd = new JpcapPingData(); pd.pingAddr = remoteNode; ! ! pd.cbDone = new CB0(PING_TIMEOUT) { protected void cb(CBResult resultOK) { + log.debug("pd.recvPacket=" + pd.recvPacket); pd.recvTS = parseICMP(pd.recvPacket); + log.debug("pd.recvTS=" + pd.recvTS); long lat = 0; ! if (pd.recvTS > 0) { ! assert pd.sendTS > 0; ! assert pd.recvTS > pd.sendTS : "send TS > recv TS ?"; lat = pd.recvTS - pd.sendTS; + } + log.debug("lat=" + lat); cbPing.call(resultOK, lat / 1000.0); } }; ! ! addRequest(pd); ! ! pd.sendPacket = createICMP(pd.pingAddr); ! try { ! sender.sendPacket(pd.sendPacket); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! pd.sendTS = System.nanoTime() / 1000; ! log.debug("sendPacket=" + pd.sendPacket); ! log.debug("sendTS=" + pd.sendTS); ! assert pd.sendTS > 0; } *************** *** 82,85 **** --- 101,106 ---- private long parseICMP(Packet p) { + log.debug("p=" + p + " p.class=" + (p != null ? p.getClass() : null)); + long recvTS = Long.MIN_VALUE; ICMPPacket icmp = (ICMPPacket) p; *************** *** 97,101 **** } else if (icmp.type == ICMPPacket.ICMP_ECHOREPLY) { - icmp.src_ip.getHostName(); long sec = p.sec; long usec = p.usec; --- 118,121 ---- *************** *** 157,164 **** } }); - EventLoop.get().main(); - } - } --- 177,181 ---- |
|
From: Peter P. <pr...@us...> - 2006-11-23 23:22:51
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27812/src/edu/harvard/syrah/pyxida/ping Modified Files: TCPSynPinger.java ICMPPinger.java Pinger.java Added Files: JpcapPinger.java Removed Files: JPCapPinger.java Log Message: More work on Pingers. I ran into an issue where I can't convince libpcap to return from packet capture after a given timeout. This appears to be a known issues under Linux. Unfortunately, this means that I'll have to change the overall structure of JpcapPinger. --- JPCapPinger.java DELETED --- Index: Pinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/Pinger.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Pinger.java 22 Nov 2006 18:46:44 -0000 1.1 --- Pinger.java 23 Nov 2006 23:22:48 -0000 1.2 *************** *** 1,4 **** --- 1,5 ---- package edu.harvard.syrah.pyxida.ping; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 7,15 **** protected AddressIF localAddr; protected AddressIF defaultPingAddr; ! ! protected Thread thread; protected boolean shutdown = false; - } --- 8,21 ---- protected AddressIF localAddr; protected AddressIF defaultPingAddr; ! ! //protected Thread thread; protected boolean shutdown = false; + class PingData { + AddressIF pingAddr; + double lat; + CB1<Double> cbLat; + } + } Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** TCPSynPinger.java 23 Nov 2006 16:46:10 -0000 1.3 --- TCPSynPinger.java 23 Nov 2006 23:22:48 -0000 1.4 *************** *** 6,10 **** import edu.harvard.syrah.sbon.comm.AddressIF; ! class TCPSynPinger extends JPCapPinger implements PingerIF { private static final Log log = new Log(TCPSynPinger.class); --- 6,10 ---- import edu.harvard.syrah.sbon.comm.AddressIF; ! class TCPSynPinger extends JpcapPinger implements PingerIF { private static final Log log = new Log(TCPSynPinger.class); --- NEW FILE: JpcapPinger.java --- package edu.harvard.syrah.pyxida.ping; import java.io.IOException; import java.io.InputStream; import java.net.Inet4Address; import java.net.InetAddress; import java.net.MalformedURLException; import java.util.Arrays; import jpcap.JpcapCaptor; import jpcap.JpcapSender; import jpcap.NetworkInterface; import jpcap.NetworkInterfaceAddress; import jpcap.packet.EthernetPacket; import jpcap.packet.Packet; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.POut; import edu.harvard.syrah.sbon.async.EventLoop; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; /** * This is the parent class of the Pingers that use the JPCap library * @author peter * */ abstract class JpcapPinger extends Pinger implements PingerIF { private static final Log log = new Log(JpcapPinger.class); private static final long CAPTION_TIMEOUT = 5000; private static JpcapCaptor captor; private static JpcapSender sender; protected static NetworkInterface device; protected static InetAddress thisIP; protected static byte[] gwMAC; protected static Thread jpcapThread; protected CB0 cbTimeout; class JpcapPingData extends PingData { long sendTS; long recvTS; Packet sendPacket; Packet recvPacket; CB0 cbDone; } protected static JpcapPingData currentPing; public void init(AddressIF defaultPingAddr, final CB0 cbDone) { this.localAddr = AddressFactory.createLocalAddress(); this.defaultPingAddr = defaultPingAddr; // Are we already initialised? if (jpcapThread != null) cbDone.callOK(); jpcapThread = new Thread() { public void run() { NetworkInterface[] devices = JpcapCaptor.getDeviceList(); //log.debug("devices=" + POut.toString(devices)); if (devices.length == 0) log.error("This must be run as root."); nextDevice: for (int i = 0; i <= devices.length; i++) { log.debug("Opening new device " + devices[i].name); try { // TODO The caption timeout is being ignored here, we need a different solution captor = JpcapCaptor.openDevice(devices[i], 2000, false, 5000); } catch (IOException e) { log.debug("Could not open interface no " + i + ". Trying next one"); continue; } device = devices[i]; log.debug("Device " + i + " opened successfully."); if (device.loopback) { log.debug("Ignoring loopback device."); //captor.close(); continue; } for (NetworkInterfaceAddress addr : device.addresses) if (addr.address instanceof Inet4Address) { thisIP = addr.address; log.debug("thisIP=" + thisIP); break; } if (thisIP == null) { log.debug("Local addr not found"); //captor.close(); continue; } // Obtain MAC address of the default gateway InetAddress pingAddr = JpcapPinger.this.defaultPingAddr.getInetAddress(); log.debug("defaultPingAddr=" + pingAddr); captor.setFilter("icmp and dst host " + pingAddr.getHostAddress(), false); InputStream is = null; Packet ping = null; while (true) { // TODO this is ugly -- is there a better way to obtain the MAC address? try { log.debug("Trying to open web connection"); pingAddr.isReachable(1); log.debug("Waiting for packet..."); ping = captor.getPacket(); } catch (MalformedURLException e) { log.error(e.toString()); } catch (IOException e) { log.error(e.toString()); } log.debug("Got one: " + ping); if (ping == null) { log.warn("Cannot obtain MAC address of default gateway."); //captor.close(); continue nextDevice; } else if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, device.mac_address)) { log.debug("doing it again"); continue; } gwMAC = ((EthernetPacket) ping.datalink).dst_mac; log.debug("gwMAC=" + POut.toString(gwMAC)); break; } break; } sender = captor.getJpcapSenderInstance(); /* captor.setFilter("icmp and dst host " + thisIP.getHostAddress(), true); sendICMP(ICMPPinger.this.defaultPingAddr); receiveICMP(); */ log.debug("JpcapPinger initalised."); EventLoop.get().registerTimerCB(cbDone); JpcapPinger.this.run(); } }; jpcapThread.start(); } public void shutdown() { shutdown = true; jpcapThread.interrupt(); } protected void addRequest(JpcapPingData pd) { JpcapPinger.currentPing = pd; synchronized(jpcapThread) { jpcapThread.notify(); } } public void run() { try { while (!jpcapThread.isInterrupted()) { if (currentPing == null) { synchronized (jpcapThread) { jpcapThread.wait(); } } if (currentPing != null) { AddressIF pingAddr = currentPing.pingAddr; Packet packet = currentPing.sendPacket; captor.setFilter("icmp and src host " + pingAddr.getHostname(), true); currentPing.sendTS = System.nanoTime() / 1000; try { sender.sendPacket(packet); } catch (Exception e) { log.warn("Failed sending packet: " + e); } log.debug("sendPacket=" + packet); log.debug("sendTS=" + currentPing.sendTS); assert currentPing.sendTS > 0; currentPing.recvPacket = captor.getPacket(); log.debug("Received packet: " + currentPing.recvPacket); EventLoop.get().registerTimerCB(currentPing.cbDone); currentPing = null; } } } catch (InterruptedException e) { /* ignore */ } } } Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** ICMPPinger.java 23 Nov 2006 16:46:10 -0000 1.4 --- ICMPPinger.java 23 Nov 2006 23:22:48 -0000 1.5 *************** *** 1,14 **** package edu.harvard.syrah.pyxida.ping; - import java.io.IOException; - import java.io.InputStream; - import java.net.Inet4Address; - import java.net.InetAddress; - import java.net.MalformedURLException; - import java.util.Arrays; - - import jpcap.JpcapCaptor; - import jpcap.NetworkInterface; - import jpcap.NetworkInterfaceAddress; import jpcap.packet.EthernetPacket; import jpcap.packet.ICMPPacket; --- 1,4 ---- *************** *** 17,21 **** import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; - import edu.harvard.syrah.prp.POut; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.EventLoop; --- 7,10 ---- *************** *** 25,134 **** import edu.harvard.syrah.sbon.comm.AddressIF; ! class ICMPPinger extends JPCapPinger implements PingerIF { ! private static final Log log = new Log(ICMPPinger.class); private static final long PING_DELAY = 1000; ! ! private AddressIF pingAddr; ! private CB1<Double> cbPing; ! public void init(AddressIF defaultPingAddr, final CB0 cbDone) { ! this.localAddr = AddressFactory.createLocalAddress(); ! this.defaultPingAddr = defaultPingAddr; ! thread = new Thread() { ! public void run() { ! ! NetworkInterface[] devices = JpcapCaptor.getDeviceList(); ! log.debug("devices=" + POut.toString(devices)); ! ! if (devices.length == 0) ! log.error("This must be run as root."); ! ! nextDevice: ! for (int i = 0; i < devices.length; i++) { ! ! log.debug("Opening new device " + devices[i]); ! try { ! captor = JpcapCaptor.openDevice(devices[i], 2000, false, 5000); ! } catch (IOException e) { ! log.debug("Could not open interface no " + i + ". Trying next one"); ! continue; ! } ! ! device = devices[i]; ! log.debug("Device opened successfully."); ! ! if (device.loopback) { ! log.debug("Ignoring loopback device."); ! captor.close(); ! continue; ! } ! ! for (NetworkInterfaceAddress addr : device.addresses) ! if (addr.address instanceof Inet4Address) { ! thisIP = addr.address; ! log.debug("thisIP=" + thisIP); ! break; ! } ! ! if (thisIP == null) { ! log.debug("Local addr not found"); ! captor.close(); ! continue; ! } ! ! // Obtain MAC address of the default gateway ! InetAddress pingAddr = ICMPPinger.this.defaultPingAddr ! .getInetAddress(); ! log.debug("defaultPingAddr=" + pingAddr); ! captor.setFilter("icmp and dst host " + pingAddr.getHostAddress(), ! false); ! InputStream is = null; ! Packet ping = null; ! while (true) { ! // TODO this is ugly -- is there a better way to obtain the MAC address? ! try { ! log.debug("Trying to open web connection"); ! pingAddr.isReachable(1); ! log.debug("Waiting for packet..."); ! ping = captor.getPacket(); ! //captor.setFilter("not", true); ! } catch (MalformedURLException e) { ! log.error(e.toString()); ! } catch (IOException e) { ! log.error(e.toString()); ! } ! log.debug("Got one: " + ping); ! if (ping == null) { ! log.warn("Cannot obtain MAC address of default gateway."); ! captor.close(); ! continue nextDevice; ! } else ! if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, ! device.mac_address)) { ! log.debug("doing it again"); ! continue; ! } ! gwMAC = ((EthernetPacket) ping.datalink).dst_mac; ! log.debug("gwMAC=" + POut.toString(gwMAC)); ! break; ! } ! break; ! } ! ! captor.setFilter("icmp and dst host " + thisIP.getHostAddress(), true); ! sender = captor.getJpcapSenderInstance(); ! sendICMP(ICMPPinger.this.defaultPingAddr); ! receiveICMP(); ! ! log.debug("ICMPPinger initalised."); ! ! EventLoop.get().registerTimerCB(cbDone); ! ! ICMPPinger.this.run(); ! } ! }; ! ! thread.start(); } --- 14,24 ---- import edu.harvard.syrah.sbon.comm.AddressIF; ! class ICMPPinger extends JpcapPinger implements PingerIF { ! private static final Log log = new Log(JpcapPinger.class); private static final long PING_DELAY = 1000; ! public void init(AddressIF defaultPingAddr, final CB0 cbDone) { ! super.init(defaultPingAddr, cbDone); } *************** *** 137,141 **** ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println("lat=" + lat); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { --- 27,31 ---- ping(remoteNode, new CB1<Double>() { protected void cb(CBResult result, Double lat) { ! System.out.println("lat=" + (lat > 0 ? lat : "Timeout")); EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { protected void cb(CBResult result) { *************** *** 147,156 **** } ! public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { ! this.pingAddr = remoteNode; ! this.cbPing = cbPing; ! synchronized(thread) { ! thread.notify(); ! } } --- 37,55 ---- } ! public void ping(AddressIF remoteNode, final CB1<Double> cbPing) throws UnsupportedOperationException { ! final JpcapPingData pd = new JpcapPingData(); ! pd.pingAddr = remoteNode; ! pd.cbLat = cbPing; ! pd.sendPacket = createICMP(remoteNode); ! pd.cbDone = new CB0() { ! protected void cb(CBResult resultOK) { ! pd.recvTS = parseICMP(pd.recvPacket); ! long lat = 0; ! if (pd.recvTS > 0) ! lat = pd.recvTS - pd.sendTS; ! cbPing.call(resultOK, lat / 1000.0); ! } ! }; ! addRequest(pd); } *************** *** 159,167 **** throw new UnsupportedOperationException(); } ! ! private long sendICMP(AddressIF addr) { assert device != null; ! log.debug("Sending ICMP ping to " + addr); ICMPPacket icmp = new ICMPPacket(); --- 58,66 ---- throw new UnsupportedOperationException(); } ! ! private ICMPPacket createICMP(AddressIF addr) { assert device != null; ! log.debug("Creating ICMP ping to " + addr); ICMPPacket icmp = new ICMPPacket(); *************** *** 179,249 **** icmp.datalink = ether; ! long sendTS = System.nanoTime() / 1000; ! try { ! sender.sendPacket(icmp); ! } catch (Exception e) { ! log.warn("Failed sending packet: " + e); ! } ! log.debug("sendPacket=" + icmp); ! return sendTS; } ! ! private long receiveICMP() { ! long recvTS = -1; ! ICMPPacket p = (ICMPPacket) captor.getPacket(); ! log.debug("Received ICMP packet: " + p); ! if (p == null) { log.debug("Timeout"); ! } else if (p.type == ICMPPacket.ICMP_TIMXCEED) { ! p.src_ip.getHostName(); ! log.debug("ICMP_TIMXCEED: " + p.src_ip.toString()); ! } else if (p.type == ICMPPacket.ICMP_UNREACH) { ! p.src_ip.getHostName(); ! log.debug("ICMP_UNREACH: " + p.src_ip.toString()); ! } else if (p.type == ICMPPacket.ICMP_ECHOREPLY) { ! p.src_ip.getHostName(); ! long sec = p.sec; ! long usec = p.usec; ! log.debug("ICMP_ECHOREPLY: " + p.src_ip + " sec=" + sec + " usec=" + usec); ! recvTS = (sec * 1000 * 1000) + usec; ! log.debug("recvTS=" + recvTS); } ! log.debug("Finished receiveICMP"); return recvTS; } - public void run() { - try { - while (!thread.isInterrupted()) { - - synchronized (thread) { - thread.wait(); - } - - if (pingAddr != null) { - captor.setFilter("icmp and src host " + pingAddr.getHostname(), true); - long sendTS = sendICMP(pingAddr); - log.debug("sendTS=" + sendTS); - assert sendTS > 0; - long recvTS = receiveICMP(); - assert recvTS > 0; - final long lat = recvTS - sendTS; - pingAddr = null; - EventLoop.get().registerTimerCB(new CB0() { - protected void cb(CBResult resultOK) { - cbPing.call(resultOK, (double) lat / 1000.0); - } - }); - } - } - } catch (InterruptedException e) { /* ignore */ } - } - - public void shutdown() { - shutdown = true; - thread.interrupt(); - } - public static void main(final String[] args) { ANSI.use(true); --- 78,111 ---- icmp.datalink = ether; ! return icmp; } ! ! private long parseICMP(Packet p) { ! long recvTS = Long.MIN_VALUE; ! ICMPPacket icmp = (ICMPPacket) p; ! if (icmp == null) { log.debug("Timeout"); ! } else ! if (icmp.type == ICMPPacket.ICMP_TIMXCEED) { ! icmp.src_ip.getHostName(); ! log.debug("ICMP_TIMXCEED: " + icmp.src_ip.toString()); ! } else ! if (icmp.type == ICMPPacket.ICMP_UNREACH) { ! icmp.src_ip.getHostName(); ! log.debug("ICMP_UNREACH: " + icmp.src_ip.toString()); ! } else ! if (icmp.type == ICMPPacket.ICMP_ECHOREPLY) { ! icmp.src_ip.getHostName(); ! long sec = p.sec; ! long usec = p.usec; ! log.debug("ICMP_ECHOREPLY: " + icmp.src_ip + " sec=" + sec + " usec=" + usec); ! recvTS = (sec * 1000 * 1000) + usec; ! log.debug("recvTS=" + recvTS); } ! log.debug("Finished parseICMP"); return recvTS; } public static void main(final String[] args) { ANSI.use(true); *************** *** 258,262 **** final PingerIF pinger = new ICMPPinger(); ! EventLoop.get().registerTimerCB(new CB0() { protected void cb(CBResult resultOK) { --- 120,124 ---- final PingerIF pinger = new ICMPPinger(); ! EventLoop.get().registerTimerCB(new CB0() { protected void cb(CBResult resultOK) { *************** *** 264,268 **** protected void cb(CBResult result, AddressIF defaultAddr) { switch (result.state) { ! case OK: { pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { --- 126,130 ---- protected void cb(CBResult result, AddressIF defaultAddr) { switch (result.state) { ! case OK: { pinger.init(defaultAddr, new CB0() { protected void cb(CBResult arg0) { *************** *** 271,275 **** switch (result.state) { case OK: { ! System.out.println("Pinging addr=" + addr + " "); pinger.testPing(addr); break; --- 133,137 ---- switch (result.state) { case OK: { ! System.out.println("Pinging addr=" + addr + " using ICMP"); pinger.testPing(addr); break; |
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27812/lib/jpcap-0.5.1-lib/src/java/jpcap Removed Files: JpcapInstance.class NetworkInterfaceAddress.class NetworkInterface.class JpcapCaptor.class JpcapSender.class Log Message: More work on Pingers. I ran into an issue where I can't convince libpcap to return from packet capture after a given timeout. This appears to be a known issues under Linux. Unfortunately, this means that I'll have to change the overall structure of JpcapPinger. --- JpcapInstance.class DELETED --- --- JpcapCaptor.class DELETED --- --- JpcapSender.class DELETED --- --- NetworkInterfaceAddress.class DELETED --- --- NetworkInterface.class DELETED --- |
|
From: Peter P. <pr...@us...> - 2006-11-23 23:22:50
|
Update of /cvsroot/pyxida/Pyxida/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27812/lib Modified Files: libjpcap.so Log Message: More work on Pingers. I ran into an issue where I can't convince libpcap to return from packet capture after a given timeout. This appears to be a known issues under Linux. Unfortunately, this means that I'll have to change the overall structure of JpcapPinger. Index: libjpcap.so =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/libjpcap.so,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvstKFKfN and /tmp/cvsIMGVoL differ |
|
From: Peter P. <pr...@us...> - 2006-11-23 23:22:50
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/c In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv27812/lib/jpcap-0.5.1-lib/src/c Modified Files: libjpcap.so Log Message: More work on Pingers. I ran into an issue where I can't convince libpcap to return from packet capture after a given timeout. This appears to be a known issues under Linux. Unfortunately, this means that I'll have to change the overall structure of JpcapPinger. Index: libjpcap.so =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/c/libjpcap.so,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsuPgyRU and /tmp/cvs7GJk9S differ |
|
From: Peter P. <pr...@us...> - 2006-11-23 16:46:15
|
Update of /cvsroot/pyxida/Pyxida/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12456/lib Modified Files: sbon-async.jar jpcap.jar Log Message: Made ICMPPinger work. Test it as follows: cd test sudo ./ICMPPinger www.yahoo.com Index: jpcap.jar =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/jpcap.jar,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 Binary files /tmp/cvsqXtDIx and /tmp/cvsY4bRSy differ Index: sbon-async.jar =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/sbon-async.jar,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 Binary files /tmp/cvsimGDix and /tmp/cvssAFUxy differ |
|
From: Peter P. <pr...@us...> - 2006-11-23 16:46:12
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap/packet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12456/lib/jpcap-0.5.1-lib/src/java/jpcap/packet Added Files: DatalinkPacket.class Packet.class Log Message: Made ICMPPinger work. Test it as follows: cd test sudo ./ICMPPinger www.yahoo.com --- NEW FILE: Packet.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: DatalinkPacket.class --- (This appears to be a binary file; contents omitted.) |
|
From: Peter P. <pr...@us...> - 2006-11-23 16:46:12
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12456/src/edu/harvard/syrah/pyxida/ping Modified Files: ICMPPinger.java TCPSynPinger.java PingerIF.java UDPAppPinger.java Log Message: Made ICMPPinger work. Test it as follows: cd test sudo ./ICMPPinger www.yahoo.com Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** ICMPPinger.java 23 Nov 2006 15:51:55 -0000 1.3 --- ICMPPinger.java 23 Nov 2006 16:46:10 -0000 1.4 *************** *** 9,13 **** import jpcap.JpcapCaptor; - import jpcap.JpcapSender; import jpcap.NetworkInterface; import jpcap.NetworkInterfaceAddress; --- 9,12 ---- *************** *** 29,32 **** --- 28,33 ---- private static final Log log = new Log(ICMPPinger.class); + private static final long PING_DELAY = 1000; + private AddressIF pingAddr; private CB1<Double> cbPing; *************** *** 103,107 **** captor.close(); continue nextDevice; ! } else if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, device.mac_address)) { log.debug("doing it again"); --- 104,109 ---- captor.close(); continue nextDevice; ! } else ! if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, device.mac_address)) { log.debug("doing it again"); *************** *** 121,127 **** log.debug("ICMPPinger initalised."); ! ! // TODO we need to wake up the selector here because it's sleeping in another thread. ! EventLoop.get().registerTimerCB(cbDone); --- 123,127 ---- log.debug("ICMPPinger initalised."); ! EventLoop.get().registerTimerCB(cbDone); *************** *** 132,135 **** --- 132,149 ---- thread.start(); } + + public void testPing(final AddressIF remoteNode) { + System.out.print(" Sending ping... "); + ping(remoteNode, new CB1<Double>() { + protected void cb(CBResult result, Double lat) { + System.out.println("lat=" + lat); + EventLoop.get().registerTimerCB(PING_DELAY, new CB0() { + protected void cb(CBResult result) { + testPing(remoteNode); + } + }); + } + }); + } public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { *************** *** 153,157 **** ICMPPacket icmp = new ICMPPacket(); icmp.type = ICMPPacket.ICMP_ECHO; ! icmp.seq = 100; icmp.id = 0; icmp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, --- 167,171 ---- ICMPPacket icmp = new ICMPPacket(); icmp.type = ICMPPacket.ICMP_ECHO; ! icmp.seq = 0; icmp.id = 0; icmp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, *************** *** 164,168 **** ether.dst_mac = gwMAC; icmp.datalink = ether; ! try { sender.sendPacket(icmp); --- 178,183 ---- ether.dst_mac = gwMAC; icmp.datalink = ether; ! ! long sendTS = System.nanoTime() / 1000; try { sender.sendPacket(icmp); *************** *** 171,175 **** } log.debug("sendPacket=" + icmp); ! return System.currentTimeMillis(); } --- 186,190 ---- } log.debug("sendPacket=" + icmp); ! return sendTS; } *************** *** 192,198 **** long usec = p.usec; log.debug("ICMP_ECHOREPLY: " + p.src_ip + " sec=" + sec + " usec=" + usec); ! recvTS = (sec * 1000) + (long) (usec / 1000.0); log.debug("recvTS=" + recvTS); - log.debug("recvSY=" + System.currentTimeMillis()); } log.debug("Finished receiveICMP"); --- 207,212 ---- long usec = p.usec; log.debug("ICMP_ECHOREPLY: " + p.src_ip + " sec=" + sec + " usec=" + usec); ! recvTS = (sec * 1000 * 1000) + usec; log.debug("recvTS=" + recvTS); } log.debug("Finished receiveICMP"); *************** *** 209,213 **** if (pingAddr != null) { ! captor.setFilter("icmp and dst host" + pingAddr.getHostname(), true); long sendTS = sendICMP(pingAddr); log.debug("sendTS=" + sendTS); --- 223,227 ---- if (pingAddr != null) { ! captor.setFilter("icmp and src host " + pingAddr.getHostname(), true); long sendTS = sendICMP(pingAddr); log.debug("sendTS=" + sendTS); *************** *** 219,223 **** EventLoop.get().registerTimerCB(new CB0() { protected void cb(CBResult resultOK) { ! cbPing.call(resultOK, (double) lat); } }); --- 233,237 ---- EventLoop.get().registerTimerCB(new CB0() { protected void cb(CBResult resultOK) { ! cbPing.call(resultOK, (double) lat / 1000.0); } }); *************** *** 234,238 **** public static void main(final String[] args) { ANSI.use(true); ! Log.setPackageRoot(ICMPPinger.class); EventLoop.set(new EventLoop()); --- 248,252 ---- public static void main(final String[] args) { ANSI.use(true); ! //Log.setPackageRoot(ICMPPinger.class); EventLoop.set(new EventLoop()); *************** *** 258,266 **** case OK: { System.out.println("Pinging addr=" + addr + " "); ! pinger.ping(addr, new CB1<Double>() { ! protected void cb(CBResult arg0, Double lat) { ! System.out.println("lat=" + lat); ! } ! }); break; } --- 272,276 ---- case OK: { System.out.println("Pinging addr=" + addr + " "); ! pinger.testPing(addr); break; } Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** TCPSynPinger.java 23 Nov 2006 15:51:55 -0000 1.2 --- TCPSynPinger.java 23 Nov 2006 16:46:10 -0000 1.3 *************** *** 49,51 **** --- 49,56 ---- } + public void testPing(AddressIF remoteNode) { + // TODO Auto-generated method stub + + } + } Index: UDPAppPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/UDPAppPinger.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** UDPAppPinger.java 23 Nov 2006 15:51:55 -0000 1.3 --- UDPAppPinger.java 23 Nov 2006 16:46:10 -0000 1.4 *************** *** 49,51 **** --- 49,56 ---- } + public void testPing(AddressIF remoteNode) { + // TODO Auto-generated method stub + + } + } Index: PingerIF.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/PingerIF.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** PingerIF.java 23 Nov 2006 15:51:55 -0000 1.2 --- PingerIF.java 23 Nov 2006 16:46:10 -0000 1.3 *************** *** 17,20 **** --- 17,22 ---- public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException; + public void testPing(AddressIF remoteNode); + public void shutdown(); |
|
From: Peter P. <pr...@us...> - 2006-11-23 16:46:12
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv12456/lib/jpcap-0.5.1-lib/src/java/jpcap Modified Files: JpcapCaptor.java Added Files: JpcapInstance.class JpcapCaptor.class JpcapSender.class NetworkInterfaceAddress.class NetworkInterface.class PacketReceiver.class Log Message: Made ICMPPinger work. Test it as follows: cd test sudo ./ICMPPinger www.yahoo.com --- NEW FILE: JpcapSender.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: PacketReceiver.class --- (This appears to be a binary file; contents omitted.) Index: JpcapCaptor.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap/JpcapCaptor.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** JpcapCaptor.java 22 Nov 2006 18:51:02 -0000 1.1 --- JpcapCaptor.java 23 Nov 2006 16:46:10 -0000 1.2 *************** *** 92,96 **** /** Closes the opened interface of dump file. */ public void close() { ! System.out.println("close:"+ID); nativeClose(); unreserveID(); --- 92,96 ---- /** Closes the opened interface of dump file. */ public void close() { ! //System.out.println("close:"+ID); nativeClose(); unreserveID(); --- NEW FILE: NetworkInterfaceAddress.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: NetworkInterface.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: JpcapInstance.class --- (This appears to be a binary file; contents omitted.) --- NEW FILE: JpcapCaptor.class --- (This appears to be a binary file; contents omitted.) |
|
From: Peter P. <pr...@us...> - 2006-11-23 15:52:06
|
Update of /cvsroot/pyxida/Pyxida/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24820/test Added Files: ICMPPinger Log Message: Tried to get ICMPPinger to work. It's almost there. It now pings reliably but I couldn't figure out how to extract the timestamps from the packets. Just using System.currentTimeMillis() doesn't work because the packet might have been captured a while ago before Jpcap passes it to Java. I sent an email to the Jpcap author, perhaps he can help. --- NEW FILE: ICMPPinger --- #!/bin/bash cd .. export LD_LIBRARY_PATH=`pwd`/lib/jpcap-0.5.1-lib/src/c/ #java -ea -cp classes:../SBON/classes:lib/util-prp.jar:lib/jpcap.jar edu.harvard.syrah.pyxida.ping.ICMPPinger $@ java -ea -cp classes:lib/sbon-async.jar:lib/util-prp.jar:lib/jpcap.jar edu.harvard.syrah.pyxida.ping.ICMPPinger $@ |
|
From: Peter P. <pr...@us...> - 2006-11-23 15:51:58
|
Update of /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24820/src/edu/harvard/syrah/pyxida/ping Modified Files: TCPSynPinger.java ICMPPinger.java PingerIF.java PingManager.java UDPAppPinger.java Log Message: Tried to get ICMPPinger to work. It's almost there. It now pings reliably but I couldn't figure out how to extract the timestamps from the packets. Just using System.currentTimeMillis() doesn't work because the packet might have been captured a while ago before Jpcap passes it to Java. I sent an email to the Jpcap author, perhaps he can help. Index: PingManager.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/PingManager.java,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** PingManager.java 22 Nov 2006 18:46:44 -0000 1.3 --- PingManager.java 23 Nov 2006 15:51:55 -0000 1.4 *************** *** 6,11 **** import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.sbon.async.CBResult; - import edu.harvard.syrah.sbon.async.CallbacksIF.CB; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; --- 6,11 ---- import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.sbon.async.CBResult; import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 20,25 **** private Set<PingerIF> pingerSet = new HashSet<PingerIF>(); ! public void init(CB0 cbDone) { ! AddressFactory.createResolved(DEFAULT_PING_HOSTNAME, new CB<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { PingManager.this.defaultPingAddr = addr; --- 20,25 ---- private Set<PingerIF> pingerSet = new HashSet<PingerIF>(); ! public void init(final CB0 cbDone) { ! AddressFactory.createResolved(DEFAULT_PING_HOSTNAME, new CB1<AddressIF>() { protected void cb(CBResult result, AddressIF addr) { PingManager.this.defaultPingAddr = addr; *************** *** 29,33 **** PingerIF pinger = new ICMPPinger(); pingerSet.add(pinger); ! pinger.init(defaultPingAddr); } --- 29,33 ---- PingerIF pinger = new ICMPPinger(); pingerSet.add(pinger); ! pinger.init(defaultPingAddr, cbDone); } *************** *** 37,41 **** } ! public void addPingReq(AddressIF nodeA, AddressIF nodeB, CB<Double> cbMeasurement) { // TODO implement me } --- 37,41 ---- } ! public void addPingReq(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbMeasurement) { // TODO implement me } Index: ICMPPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/ICMPPinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** ICMPPinger.java 22 Nov 2006 18:46:44 -0000 1.2 --- ICMPPinger.java 23 Nov 2006 15:51:55 -0000 1.3 *************** *** 6,13 **** import java.net.InetAddress; import java.net.MalformedURLException; - import java.net.URL; import java.util.Arrays; import jpcap.JpcapCaptor; import jpcap.NetworkInterface; import jpcap.NetworkInterfaceAddress; --- 6,13 ---- import java.net.InetAddress; import java.net.MalformedURLException; import java.util.Arrays; import jpcap.JpcapCaptor; + import jpcap.JpcapSender; import jpcap.NetworkInterface; import jpcap.NetworkInterfaceAddress; *************** *** 16,21 **** --- 16,26 ---- import jpcap.packet.IPPacket; import jpcap.packet.Packet; + import edu.harvard.syrah.prp.ANSI; import edu.harvard.syrah.prp.Log; import edu.harvard.syrah.prp.POut; + import edu.harvard.syrah.sbon.async.CBResult; + import edu.harvard.syrah.sbon.async.EventLoop; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressFactory; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 24,28 **** private static final Log log = new Log(ICMPPinger.class); ! public void init(AddressIF defaultPingAddr) { this.localAddr = AddressFactory.createLocalAddress(); this.defaultPingAddr = defaultPingAddr; --- 29,36 ---- private static final Log log = new Log(ICMPPinger.class); ! private AddressIF pingAddr; ! private CB1<Double> cbPing; ! ! public void init(AddressIF defaultPingAddr, final CB0 cbDone) { this.localAddr = AddressFactory.createLocalAddress(); this.defaultPingAddr = defaultPingAddr; *************** *** 33,41 **** log.debug("devices=" + POut.toString(devices)); ! assert devices.length > 0; ! ! nextDevice: for (int i = 0; i < devices.length; i++) { ! log.debug("Opening new device " + devices[i]); try { --- 41,50 ---- log.debug("devices=" + POut.toString(devices)); ! if (devices.length == 0) ! log.error("This must be run as root."); ! ! nextDevice: for (int i = 0; i < devices.length; i++) { ! log.debug("Opening new device " + devices[i]); try { *************** *** 46,57 **** } - log.debug("Device opened successfully."); device = devices[i]; ! if (device.loopback) { log.debug("Ignoring loopback device."); captor.close(); continue; ! } for (NetworkInterfaceAddress addr : device.addresses) --- 55,66 ---- } device = devices[i]; ! log.debug("Device opened successfully."); ! if (device.loopback) { log.debug("Ignoring loopback device."); captor.close(); continue; ! } for (NetworkInterfaceAddress addr : device.addresses) *************** *** 61,68 **** break; } ! //obtain MAC address of the default gateway ! InetAddress pingAddr = ICMPPinger.this.defaultPingAddr.getInetAddress(); ! captor.setFilter("tcp and dst host " + pingAddr.getHostAddress(), true); InputStream is = null; Packet ping = null; --- 70,86 ---- break; } + + if (thisIP == null) { + log.debug("Local addr not found"); + captor.close(); + continue; + } ! // Obtain MAC address of the default gateway ! InetAddress pingAddr = ICMPPinger.this.defaultPingAddr ! .getInetAddress(); ! log.debug("defaultPingAddr=" + pingAddr); ! captor.setFilter("icmp and dst host " + pingAddr.getHostAddress(), ! false); InputStream is = null; Packet ping = null; *************** *** 71,78 **** try { log.debug("Trying to open web connection"); ! is = new URL("http://www.google.com").openStream(); log.debug("Waiting for packet..."); ping = captor.getPacket(); ! is.close(); } catch (MalformedURLException e) { log.error(e.toString()); --- 89,96 ---- try { log.debug("Trying to open web connection"); ! pingAddr.isReachable(1); log.debug("Waiting for packet..."); ping = captor.getPacket(); ! //captor.setFilter("not", true); } catch (MalformedURLException e) { log.error(e.toString()); *************** *** 83,90 **** if (ping == null) { log.warn("Cannot obtain MAC address of default gateway."); ! captor.close(); continue nextDevice; ! } else if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, device.mac_address)) continue; gwMAC = ((EthernetPacket) ping.datalink).dst_mac; log.debug("gwMAC=" + POut.toString(gwMAC)); --- 101,111 ---- if (ping == null) { log.warn("Cannot obtain MAC address of default gateway."); ! captor.close(); continue nextDevice; ! } else if (Arrays.equals(((EthernetPacket) ping.datalink).dst_mac, ! device.mac_address)) { ! log.debug("doing it again"); continue; + } gwMAC = ((EthernetPacket) ping.datalink).dst_mac; log.debug("gwMAC=" + POut.toString(gwMAC)); *************** *** 97,118 **** sender = captor.getJpcapSenderInstance(); sendICMP(ICMPPinger.this.defaultPingAddr); ICMPPinger.this.run(); } }; ! thread.start(); } ! public double ping(AddressIF remoteNode) throws UnsupportedOperationException { ! sendICMP(remoteNode); ! return 0.0; } ! public double ping(AddressIF nodeA, AddressIF nodeB) throws UnsupportedOperationException { throw new UnsupportedOperationException(); } ! private void sendICMP(AddressIF addr) { log.debug("Sending ICMP ping to " + addr); --- 118,152 ---- sender = captor.getJpcapSenderInstance(); sendICMP(ICMPPinger.this.defaultPingAddr); + receiveICMP(); + + log.debug("ICMPPinger initalised."); + // TODO we need to wake up the selector here because it's sleeping in another thread. + + EventLoop.get().registerTimerCB(cbDone); + ICMPPinger.this.run(); } }; ! thread.start(); } ! public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { ! this.pingAddr = remoteNode; ! this.cbPing = cbPing; ! synchronized(thread) { ! thread.notify(); ! } } ! public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) ! throws UnsupportedOperationException { throw new UnsupportedOperationException(); } ! private long sendICMP(AddressIF addr) { ! assert device != null; ! log.debug("Sending ICMP ping to " + addr); *************** *** 121,126 **** icmp.seq = 100; icmp.id = 0; ! icmp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, 100, ! IPPacket.IPPROTO_ICMP, thisIP, addr.getInetAddress()); icmp.data = "data".getBytes(); --- 155,160 ---- icmp.seq = 100; icmp.id = 0; ! icmp.setIPv4Parameter(0, false, false, false, 0, false, false, false, 0, 0, ! 100, IPPacket.IPPROTO_ICMP, thisIP, addr.getInetAddress()); icmp.data = "data".getBytes(); *************** *** 130,134 **** ether.dst_mac = gwMAC; icmp.datalink = ether; ! try { sender.sendPacket(icmp); --- 164,168 ---- ether.dst_mac = gwMAC; icmp.datalink = ether; ! try { sender.sendPacket(icmp); *************** *** 136,142 **** log.warn("Failed sending packet: " + e); } } ! ! private void receiveICMP() { ICMPPacket p = (ICMPPacket) captor.getPacket(); log.debug("Received ICMP packet: " + p); --- 170,180 ---- log.warn("Failed sending packet: " + e); } + log.debug("sendPacket=" + icmp); + return System.currentTimeMillis(); } ! ! private long receiveICMP() { ! long recvTS = -1; ! ICMPPacket p = (ICMPPacket) captor.getPacket(); log.debug("Received ICMP packet: " + p); *************** *** 148,157 **** } else if (p.type == ICMPPacket.ICMP_UNREACH) { p.src_ip.getHostName(); ! log.debug("ICMP_UNREACH: " + p.src_ip); } else if (p.type == ICMPPacket.ICMP_ECHOREPLY) { p.src_ip.getHostName(); ! log.debug("ICMP_ECHOREPLY: " + p.src_ip); } log.debug("Finished receiveICMP"); } --- 186,201 ---- } else if (p.type == ICMPPacket.ICMP_UNREACH) { p.src_ip.getHostName(); ! log.debug("ICMP_UNREACH: " + p.src_ip.toString()); } else if (p.type == ICMPPacket.ICMP_ECHOREPLY) { p.src_ip.getHostName(); ! long sec = p.sec; ! long usec = p.usec; ! log.debug("ICMP_ECHOREPLY: " + p.src_ip + " sec=" + sec + " usec=" + usec); ! recvTS = (sec * 1000) + (long) (usec / 1000.0); ! log.debug("recvTS=" + recvTS); ! log.debug("recvSY=" + System.currentTimeMillis()); } log.debug("Finished receiveICMP"); + return recvTS; } *************** *** 159,174 **** try { while (!thread.isInterrupted()) { ! ! receiveICMP(); ! synchronized (thread) { thread.wait(); } ! ! // TODO do useful stuff here, i.e. wait for incoming ping and match it to the request ping ! } ! } catch (InterruptedException e) { /* ignore */ ! } } --- 203,228 ---- try { while (!thread.isInterrupted()) { ! synchronized (thread) { thread.wait(); } ! ! if (pingAddr != null) { ! captor.setFilter("icmp and dst host" + pingAddr.getHostname(), true); ! long sendTS = sendICMP(pingAddr); ! log.debug("sendTS=" + sendTS); ! assert sendTS > 0; ! long recvTS = receiveICMP(); ! assert recvTS > 0; ! final long lat = recvTS - sendTS; ! pingAddr = null; ! EventLoop.get().registerTimerCB(new CB0() { ! protected void cb(CBResult resultOK) { ! cbPing.call(resultOK, (double) lat); ! } ! }); ! } } ! } catch (InterruptedException e) { /* ignore */ } } *************** *** 178,180 **** --- 232,292 ---- } + public static void main(final String[] args) { + ANSI.use(true); + Log.setPackageRoot(ICMPPinger.class); + + EventLoop.set(new EventLoop()); + + if (args.length == 0) { + System.out.println("usage: ICMPPinger <hostname>"); + System.exit(1); + } + + final PingerIF pinger = new ICMPPinger(); + + EventLoop.get().registerTimerCB(new CB0() { + protected void cb(CBResult resultOK) { + AddressFactory.createResolved("www.google.com", new CB1<AddressIF>() { + protected void cb(CBResult result, AddressIF defaultAddr) { + switch (result.state) { + case OK: { + pinger.init(defaultAddr, new CB0() { + protected void cb(CBResult arg0) { + AddressFactory.createResolved(args[0], new CB1<AddressIF>() { + protected void cb(CBResult result, AddressIF addr) { + switch (result.state) { + case OK: { + System.out.println("Pinging addr=" + addr + " "); + pinger.ping(addr, new CB1<Double>() { + protected void cb(CBResult arg0, Double lat) { + System.out.println("lat=" + lat); + } + }); + break; + } + case ERROR: + case TIMEOUT: { + log.error(result.what); + } + } + } + }); + } + }); + break; + } + case ERROR: + case TIMEOUT: { + log.error(result.what); + } + } + } + }); + } + }); + + EventLoop.get().main(); + + } + } Index: TCPSynPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/TCPSynPinger.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** TCPSynPinger.java 21 Nov 2006 21:14:59 -0000 1.1 --- TCPSynPinger.java 23 Nov 2006 15:51:55 -0000 1.2 *************** *** 2,5 **** --- 2,7 ---- import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 32,34 **** --- 34,51 ---- } + public void init(AddressIF defaultPingAddr, CB0 cbDone) { + // TODO Auto-generated method stub + + } + + public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { + // TODO Auto-generated method stub + + } + + public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException { + // TODO Auto-generated method stub + + } + } Index: UDPAppPinger.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/UDPAppPinger.java,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** UDPAppPinger.java 22 Nov 2006 18:46:44 -0000 1.2 --- UDPAppPinger.java 23 Nov 2006 15:51:55 -0000 1.3 *************** *** 2,5 **** --- 2,7 ---- import edu.harvard.syrah.prp.Log; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 32,34 **** --- 34,51 ---- } + public void init(AddressIF defaultPingAddr, CB0 cbDone) { + // TODO Auto-generated method stub + + } + + public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException { + // TODO Auto-generated method stub + + } + + public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException { + // TODO Auto-generated method stub + + } + } Index: PingerIF.java =================================================================== RCS file: /cvsroot/pyxida/Pyxida/src/edu/harvard/syrah/pyxida/ping/PingerIF.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** PingerIF.java 21 Nov 2006 21:14:59 -0000 1.1 --- PingerIF.java 23 Nov 2006 15:51:55 -0000 1.2 *************** *** 1,4 **** --- 1,6 ---- package edu.harvard.syrah.pyxida.ping; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB0; + import edu.harvard.syrah.sbon.async.CallbacksIF.CB1; import edu.harvard.syrah.sbon.comm.AddressIF; *************** *** 9,17 **** * */ ! public void init(AddressIF defaultPingAddr); ! public double ping(AddressIF remoteNode) throws UnsupportedOperationException; ! public double ping(AddressIF nodeA, AddressIF nodeB) throws UnsupportedOperationException; public void shutdown(); --- 11,19 ---- * */ ! public void init(AddressIF defaultPingAddr, CB0 cbDone); ! public void ping(AddressIF remoteNode, CB1<Double> cbPing) throws UnsupportedOperationException; ! public void ping(AddressIF nodeA, AddressIF nodeB, CB1<Double> cbPing) throws UnsupportedOperationException; public void shutdown(); |
|
From: Peter P. <pr...@us...> - 2006-11-23 15:51:58
|
Update of /cvsroot/pyxida/Pyxida/lib In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24820/lib Modified Files: sbon-async.jar Log Message: Tried to get ICMPPinger to work. It's almost there. It now pings reliably but I couldn't figure out how to extract the timestamps from the packets. Just using System.currentTimeMillis() doesn't work because the packet might have been captured a while ago before Jpcap passes it to Java. I sent an email to the Jpcap author, perhaps he can help. Index: sbon-async.jar =================================================================== RCS file: /cvsroot/pyxida/Pyxida/lib/sbon-async.jar,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 Binary files /tmp/cvs8vsv2C and /tmp/cvsHtUXoe differ |
|
From: Peter P. <pr...@us...> - 2006-11-23 15:51:36
|
Update of /cvsroot/pyxida/Pyxida/test In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24794/test Log Message: Directory /cvsroot/pyxida/Pyxida/test added to the repository |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:51:09
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13312/lib/jpcap-0.5.1-lib/src/java/jpcap Added Files: JpcapCaptor.java NetworkInterface.java PacketReceiver.java JpcapInstance.java package.html JpcapSender.java NetworkInterfaceAddress.java JpcapWriter.java Log Message: Added remaining Jpcap files (java sources + docs) --- NEW FILE: JpcapInstance.java --- package jpcap; abstract class JpcapInstance { protected static final int MAX_NUMBER_OF_INSTANCE = 255; protected static boolean[] instanciatedFlag = new boolean[MAX_NUMBER_OF_INSTANCE]; protected int ID; protected int reserveID(){ ID = -1; for (int i = 0; i < MAX_NUMBER_OF_INSTANCE; i++) if (!instanciatedFlag[i]) { ID = i; instanciatedFlag[i] = true; break; } return ID; } protected void unreserveID(){ instanciatedFlag[ID]=false; } } --- NEW FILE: JpcapWriter.java --- package jpcap; import jpcap.packet.Packet; /** This class is used to save the captured packets into a file. */ public class JpcapWriter { private native String nativeOpenDumpFile(String filename,int ID); private JpcapWriter(JpcapCaptor jpcap,String filename) throws java.io.IOException{ String ret=nativeOpenDumpFile(filename,jpcap.ID); if(ret!=null){ //error throw new java.io.IOException(ret); } } /** Opens a file to save the captured packets. * @param jpcap instance of Jpcap that was used to capture (load) packets * @param filename filename * @throws IOException If the file cannot be opened */ public static JpcapWriter openDumpFile(JpcapCaptor jpcap,String filename) throws java.io.IOException{ return new JpcapWriter(jpcap,filename); } /** Closes the opened file. */ public native void close(); /** Saves a packet into the file. * @param packet Packet to be saved */ public native void writePacket(Packet packet); static{ System.loadLibrary("jpcap"); } } --- NEW FILE: JpcapCaptor.java --- package jpcap; import jpcap.packet.Packet; /** * This class is used to capture packets or read packets from a captured file. */ public class JpcapCaptor extends JpcapInstance{ /** * Number of received packets * * @see #updateStat() */ public int received_packets; /** * Number of dropped packets * * @see #updateStat() */ public int dropped_packets; private native String nativeOpenLive(String device, int snaplen, int promisc, int to_ms); private native String nativeOpenOffline(String filename); private native void nativeClose(); private JpcapCaptor() throws java.io.IOException { if (reserveID()<0) throw new java.io.IOException("Unable to open a device: " + MAX_NUMBER_OF_INSTANCE + " devices are already opened."); } /** * Returns the interfaces that can be used for capturing. * * @return List of Interface objects */ public static native NetworkInterface[] getDeviceList(); /** * Initializes the network interface, and returns an instance of this class. * * @return an instance of this class Jpcap. * @param intrface * The network interface to capture packets * @param snaplen * Max number of bytes captured at once * @param promisc * If true, the inferface becomes promiscuous mode * @param to_ms * Timeout of * {@link #processPacket(int,PacketReceiver) processPacket()} * @exception java.io.IOException * Raised when the specified interface cannot be opened */ public static JpcapCaptor openDevice(NetworkInterface intrface, int snaplen, boolean promisc, int to_ms) throws java.io.IOException { JpcapCaptor jpcap = new JpcapCaptor(); String ret = jpcap.nativeOpenLive(intrface.name, snaplen, (promisc ? 1 : 0), to_ms); if (ret != null) // error throw new java.io.IOException(ret); return jpcap; } /** * Opens a dump file created by tcpdump or Ethereal, and returns an instance * of this class. * * @param filename * File name of the dump file * @exception java.io.IOException * If the file cannot be opened * @return an instance of this class Jpcap */ public static JpcapCaptor openFile(String filename) throws java.io.IOException { JpcapCaptor jpcap = new JpcapCaptor(); String ret = jpcap.nativeOpenOffline(filename); if (ret != null) // error throw new java.io.IOException(ret); return jpcap; } /** Closes the opened interface of dump file. */ public void close() { System.out.println("close:"+ID); nativeClose(); unreserveID(); } /** * Returns a captured packet. * * @return a captured packet */ public native Packet getPacket(); /** * Captures the specified number of packets consecutively. * * @param count * Number of packets to be captured<BR> * You can specify -1 to capture packets parmanently until * timeour, EOF or an error occurs. * @param handler * an instnace of JpcapHandler that analyzes the captured packets * @return Number of captured packets */ public native int processPacket(int count, PacketReceiver handler); /** * Captures the specified number of packets consecutively. * <P> * * Unlike processPacket(), this method ignores the timeout. * * @param count * Number of packets to be captured<BR> * You can specify -1 to capture packets parmanently until EOF or * an error occurs. * @param handler * an instnace of JpcapHandler that analyzes the captured packets * @return Number of captured packets */ public native int loopPacket(int count, PacketReceiver handler); /** * Captures a group of packets. * <P> * * Unlike processPacket(), this method may return before collecting the * number of packets specified by count. Also, in "non-blocking" mode, this * method returns immediately even if it didn't capture any packet. * loopPacket() and processPacket() do not support "non-blocking" mode. * * @param count * Number of packets to be captured<BR> * You can specify -1 to capture packets parmanently until EOF or * an error occurs. * @param handler * an instnace of JpcapHandler that analyzes the captured packets * @return Number of captured packets */ public native int dispatchPacket(int count, PacketReceiver handler); /** * Sets/unsets "non-blocking" mode * @param nonblocking TRUE to set "non-blocking" mode. FALSE to set "blocking" mode */ public native void setNonBlockingMode(boolean nonblocking); /** * Checks if the current setting is in "non-blocking" mode or not. * @return TRUE if it is in "non-blocking" mode. FALSE otherwise. */ public native boolean isNonBlockinMode(); /** * Set a flag that will force processPacket() and loopPacket() to return * rather than looping. * */ public native void breakLoop(); /** * Sets a filter. This filter is same as tcpdump. * * @param condition * a string representation of the filter * @param optimize * If true, the filter is optimized */ public native void setFilter(String condition, boolean optimize); /** * Updates {@link #received_packets received_packets} and * {@link #dropped_packets dropped_packets}. */ public native void updateStat(); /** * Returns an error message * * @return error message */ public native String getErrorMessage(); /** * Obtains an instance of JpcapSender that uses the same interface to send packets. * You can use this method only if you opened an interface with openDevice() method. * @return returns an instance of JpcapSender */ public JpcapSender getJpcapSenderInstance(){ return new JpcapSender(ID); } static { System.loadLibrary("jpcap"); } } --- NEW FILE: JpcapSender.java --- package jpcap; import jpcap.packet.Packet; /** This class is used to send a packet. */ public class JpcapSender extends JpcapInstance { private native String nativeOpenDevice(String device); private native void nativeSendPacket(Packet packet); private native void nativeCloseDevice(); private native void nativeOpenRawSocket(); private native void nativeSendPacketViaRawSocket(Packet packet); private native void nativeCloseRawSocket(); private static final int RAW_SOCKET_ID=99999; private JpcapSender() throws java.io.IOException { if (reserveID() < 0) throw new java.io.IOException("Unable to open a device: " + MAX_NUMBER_OF_INSTANCE + " devices are already opened."); } JpcapSender(int ID){ this.ID=ID; } /** * Initializes a network interface for sending a packet, and returns an * instance of this class. * * @param device * Interface for sending a packet * @throws IOException * Raised when initialization of the interface failed * @return intstance of this class (JpcapSender) */ public static JpcapSender openDevice(NetworkInterface device) throws java.io.IOException { JpcapSender sender = new JpcapSender(); String ret=sender.nativeOpenDevice(device.name); if(ret==null) return sender; else throw new java.io.IOException(ret); } /** * Open a raw IP socket to send a packet.<BR> * When sending a packet via a raw socket, the datalink header of the packet is ignored * (= automatically generated by OS).<P> * Note: the implementation and behavior of a raw socket may vary in different OS. * Also, you can only open one raw socket at a time. * * @throws IOException * Raised when initialization of the interface failed * @return intstance of this class (JpcapSender) */ public static JpcapSender openRawSocket() throws java.io.IOException { JpcapSender sender = new JpcapSender(); sender.nativeOpenRawSocket(); sender.ID=RAW_SOCKET_ID; return sender; } /** Closes the interface. */ public void close() { if(ID==RAW_SOCKET_ID) nativeCloseRawSocket(); else nativeCloseDevice(); unreserveID(); } /** * Sends a packet. * <P> * If this JpcapSender instance was created by openDevice(), you need to set * the Datalink layer's header (e.g., Ethernet header) of the packet. <P> * * If this JpcapSender instance was created by openRawSocket(), you can only * send IP packets, but you may not need to set the Datalink layer's header * of the IP packets you want to send.<BR> * Note: the implementation and behavior of a raw socket may vary in different OS. * For example, in Windows 2000/XP, you need to manually set the datalink/IP headers * of a packet. * @param packet Packet to be sent */ public void sendPacket(Packet packet){ if(ID==RAW_SOCKET_ID) nativeSendPacketViaRawSocket(packet); else nativeSendPacket(packet); } } --- NEW FILE: NetworkInterface.java --- package jpcap; /** * This class represents a network interface. * @author kfujii */ public class NetworkInterface { /** Name of the network interface */ public String name; /** Description about the network interface (e.g., "3Com ..."). May be null.*/ public String description; /** TRUE if this is a loopback interface */ public boolean loopback; /** Name of the datalink of the network interface*/ public String datalink_name; /** Description about the datalink of the network interface. May be null. */ public String datalink_description; /** Ethernet MAC address of the network interface */ public byte[] mac_address; /** Network addresses assigned the network interface. May be null if it is a non-IP (e.g. NetBios) address. */ public NetworkInterfaceAddress[] addresses; public NetworkInterface(String name,String description,boolean loopback, String datalink_name,String datalink_description,byte[] mac,NetworkInterfaceAddress[] addresses){ this.name=name; this.description=description; this.loopback=loopback; this.datalink_name=datalink_name; this.datalink_description=datalink_description; this.mac_address=mac; this.addresses=addresses; } } --- NEW FILE: PacketReceiver.java --- package jpcap; import jpcap.packet.Packet; /** This interface is used to define a method to analyze the captured packets, * which is used in JpcapCaptor.handlePacket() or JpcapCaptor.processPacket() * @see JpcapCaptor#processPacket(int,PacketReceiver) * @see JpcapCaptor#loopPacket(int,PacketReceiver) */ public interface PacketReceiver { /** Analyzes a packet.<BR> * <BR> * This method is called everytime a packet is captured. * @param p A packet to be analyzed */ public void receivePacket(Packet p); } --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>jpcap package</title> </head> <body bgcolor="white"> Provides classes and interfaces for capturing packets from a network interface, sending packets to a network interface, reading packets from a file, and writing packets to a local file. </body> </html> --- NEW FILE: NetworkInterfaceAddress.java --- package jpcap; import java.net.InetAddress; import java.net.UnknownHostException; /** * This class represents a network address assigned to a network interface. * @author kfujii */ public class NetworkInterfaceAddress{ /** Address of the network interface */ public InetAddress address; /** Subnet mask of the network interface */ public InetAddress subnet; /** Broadcast address of the network interface. May be null. */ public InetAddress broadcast; /** Destination address of the network interface (for P2P connection). May be null. */ public InetAddress destination; public NetworkInterfaceAddress(byte[] address,byte[] subnet,byte[] broadcast,byte[] destination){ try{ if(address!=null) this.address=InetAddress.getByAddress(address); if(subnet!=null) this.subnet=InetAddress.getByAddress(subnet); if(broadcast!=null) this.broadcast=InetAddress.getByAddress(broadcast); if(destination!=null) this.destination=InetAddress.getByAddress(destination); }catch(UnknownHostException e){ } } } |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:51:08
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/doc/javadoc/resources In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13312/lib/jpcap-0.5.1-lib/doc/javadoc/resources Added Files: inherit.gif Log Message: Added remaining Jpcap files (java sources + docs) --- NEW FILE: inherit.gif --- (This appears to be a binary file; contents omitted.) |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:51:04
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap/packet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13312/lib/jpcap-0.5.1-lib/src/java/jpcap/packet Added Files: Packet.java EthernetPacket.java ARPPacket.java IPv6Option.java ICMPPacket.java TCPPacket.java IPPacket.java UDPPacket.java DatalinkPacket.java package.html Log Message: Added remaining Jpcap files (java sources + docs) --- NEW FILE: UDPPacket.java --- package jpcap.packet; /** This class represents UDP packet. */ public class UDPPacket extends IPPacket { /** Source port number */ public int src_port; /** Destination port number */ public int dst_port; /** packet length */ public int length; /** Creates a UDP packet. * @param src_port source port number * @param dst_port destination port number */ public UDPPacket(int src_port,int dst_port){ this.src_port=src_port; this.dst_port=dst_port; } void setValue(int src,int dst,int len){ src_port=src;dst_port=dst; length=len; } /** Returns a string representation of this packet.<BR> * * <BR> * Format: src_port > dst_port * @return a string representation of this packet */ public String toString(){ return super.toString()+" UDP "+src_port+" > "+dst_port; } } --- NEW FILE: EthernetPacket.java --- package jpcap.packet; /** This class represents Ethernet packet. */ public class EthernetPacket extends DatalinkPacket { /** Destination MAC address (6byte) */ public byte[] dst_mac; /** Source MAC address (6byte) */ public byte[] src_mac; /** Frame type */ public short frametype; /** PUP protocol */ public static final short ETHERTYPE_PUP = 0x0200; /** IP protocol */ public static final short ETHERTYPE_IP = 0x0800; /** Addr. resolution protocol */ public static final short ETHERTYPE_ARP = 0x0806; /** reverse Addr. resolution protocol */ public static final short ETHERTYPE_REVARP = (short)0x8035; /** IEEE 802.1Q VLAN tagging */ public static final short ETHERTYPE_VLAN = (short)0x8100; /** IPv6 */ public static final short ETHERTYPE_IPV6 = (short)0x86dd; /** used to test interfaces */ public static final short ETHERTYPE_LOOPBACK = (short)0x9000; void setValue(byte[] dst,byte[] src,short frame){ this.dst_mac=dst; this.src_mac=src; this.frametype=frame; } /** Returns the MAC address of the source. * @return MAC address of the source */ public String getSourceAddress(){ char[] src=new char[17]; for(int i=0;i<5;i++){ src[i*3]=hexUpperChar(src_mac[i]); src[i*3+1]=hexLowerChar(src_mac[i]); src[i*3+2]=':'; } src[15]=hexUpperChar(src_mac[5]); src[16]=hexLowerChar(src_mac[5]); return new String(src); } /** Returns the MAC address of the destination. * @return MAC address of the destination */ public String getDestinationAddress(){ char[] dst=new char[17]; for(int i=0;i<5;i++){ dst[i*3]=hexUpperChar(dst_mac[i]); dst[i*3+1]=hexLowerChar(dst_mac[i]); dst[i*3+2]=':'; } dst[15]=hexUpperChar(dst_mac[5]); dst[16]=hexLowerChar(dst_mac[5]); return new String(dst); } /** Returns a string representation of this Ethernet packet.<BR> * <BR> * FormatFsrc_mac -> dst_mac (frametype) * @return a string representation of this Ethernet packet */ public String toString(){ return super.toString()+" "+getSourceAddress()+"->"+ getDestinationAddress()+" ("+frametype+")"; } private char hexUpperChar(byte b){ b=(byte)((b>>4)&0xf); if(b==0) return '0'; else if(b<10) return (char)('0'+b); else return (char)('a'+b-10); } private char hexLowerChar(byte b){ b=(byte)(b&0xf); if(b==0) return '0'; else if(b<10) return (char)('0'+b); else return (char)('a'+b-10); } } --- NEW FILE: DatalinkPacket.java --- package jpcap.packet; /** This class represents datalink layer packet. */ public abstract class DatalinkPacket { } --- NEW FILE: ARPPacket.java --- package jpcap.packet; import java.net.InetAddress; import java.net.UnknownHostException; /** This class represents ARP/RARP packet. */ public class ARPPacket extends Packet { /** Hardware type */ public short hardtype; /** Hardware type: Ethernet */ public static final short HARDTYPE_ETHER=1; /** Hardware type: Token ring */ public static final short HARDTYPE_IEEE802=6; /** Hardware type: Frame relay */ public static final short HARDTYPE_FRAMERELAY=15; /** Protocol type */ public short prototype; /** Protocol type: IP */ public static final short PROTOTYPE_IP=2048; /** Hardware address length */ public short hlen; /** Protocol address length */ public short plen; /** Operation */ public short operation; /** ARP request */ public static final short ARP_REQUEST=1; /** ARP reply */ public static final short ARP_REPLY=2; /** Reverse ARP request */ public static final short RARP_REQUEST=3; /** Reverse ARP reply */ public static final short RARP_REPLY=4; /** Identify peer request */ public static final short INV_REQUEST=8; /** Identify peer response */ public static final short INV_REPLY=9; /** Sender hardware address */ public byte[] sender_hardaddr; /** Sender protocol address */ public byte[] sender_protoaddr; /** Target hardware address */ public byte[] target_hardaddr; /** Target protocol address */ public byte[] target_protoaddr; void setValue(short hardtype,short prototype,short hlen,short plen, short operation,byte[] sha,byte[] spa,byte[] tha,byte[] tpa){ this.hardtype=hardtype; this.prototype=prototype; this.hlen=hlen;this.plen=plen; this.operation=operation; sender_hardaddr=sha; sender_protoaddr=spa; target_hardaddr=tha; target_protoaddr=tpa; } /** Returns the hardware address (MAC address) of the sender. * @return Hardware address of the sender */ public Object getSenderHardwareAddress(){ switch(hardtype){ case HARDTYPE_ETHER: char[] adr=new char[17]; for(int i=0;i<5;i++){ adr[i*3]=hexUpperChar(sender_hardaddr[i]); adr[i*3+1]=hexLowerChar(sender_hardaddr[i]); adr[i*3+2]=':'; } adr[15]=hexUpperChar(sender_hardaddr[5]); adr[16]=hexLowerChar(sender_hardaddr[5]); return new String(adr); default: return "Unknown Protocol"; } } /** Returns the hardware address (MAC address) of the target. * @return Hardware address of the target */ public Object getTargetHardwareAddress(){ switch(hardtype){ case HARDTYPE_ETHER: char[] adr=new char[17]; for(int i=0;i<5;i++){ adr[i*3]=hexUpperChar(target_hardaddr[i]); adr[i*3+1]=hexLowerChar(target_hardaddr[i]); adr[i*3+2]=':'; } adr[15]=hexUpperChar(target_hardaddr[5]); adr[16]=hexLowerChar(target_hardaddr[5]); return new String(adr); default: return "Unknown Protocol"; } } /** Returns the protocol address of the sender. * @return Protocol address of the sender */ public Object getSenderProtocolAddress(){ switch(prototype){ case PROTOTYPE_IP: try { return InetAddress.getByAddress(sender_protoaddr); } catch (UnknownHostException e) { return "Unknown Address"; } default: return "Unknown Protocol"; } } /** Returns the protocol address of the target. * @return Protocol address of the target */ public Object getTargetProtocolAddress(){ switch(prototype){ case PROTOTYPE_IP: try { return InetAddress.getByAddress(target_protoaddr); } catch (UnknownHostException e) { return "Unknown Address"; } default: return "Unknown Protocol"; } } /** Returns a string representation of this ARP/RARP packet.<BR> * * <BR> * Format: ARP(hardtype:prototype) * @return a string representation of this ARP/RARP packet */ public String toString(){ StringBuffer buf=new StringBuffer(); switch(operation){ case ARP_REQUEST: buf.append("ARP REQUEST ");break; case ARP_REPLY: buf.append("ARP REPLY ");break; case RARP_REQUEST: buf.append("RARP REQUEST ");break; case RARP_REPLY: buf.append("RARP REPLY ");break; case INV_REQUEST: buf.append("IDENTIFY REQUEST ");break; case INV_REPLY: buf.append("IDENTIFY REPLY ");break; default: buf.append("UNKNOWN ");break; } return buf.toString()+getSenderHardwareAddress()+"("+getSenderProtocolAddress()+") -> "+ getTargetHardwareAddress()+"("+getTargetProtocolAddress()+")"; } private char hexUpperChar(byte b){ b=(byte)((b>>4)&0xf); if(b==0) return '0'; else if(b<10) return (char)('0'+b); else return (char)('a'+b-10); } private char hexLowerChar(byte b){ b=(byte)(b&0xf); if(b==0) return '0'; else if(b<10) return (char)('0'+b); else return (char)('a'+b-10); } } --- NEW FILE: package.html --- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"> <html> <head> <title>jpcap package</title> </head> <body bgcolor="white"> Provides classes to represent various packets. </body> </html> --- NEW FILE: TCPPacket.java --- package jpcap.packet; /** This class represents TCP packet. */ public class TCPPacket extends IPPacket { /** Source port number */ public int src_port; /** Destination port number */ public int dst_port; /** Sequence number */ public long sequence; /** ACK number */ public long ack_num; /** URG flag */ public boolean urg; /** ACK flag */ public boolean ack; /** PSH flag */ public boolean psh; /** RST flag */ public boolean rst; /** SYN flag */ public boolean syn; /** FIN flag */ public boolean fin; // added by Damien Daspit 5/7/01 /** RSV1 flag */ public boolean rsv1; /** RSV2 flag */ public boolean rsv2; // ***************************** /** Window size */ public int window; /** Urgent pointer */ public short urgent_pointer; /** TCP option */ public byte[] option; /** Creates a TCP packet. * @param rsv1 RSV1 flag * @param rsv2 RSV2 flag * @param src_port Source port number * @param dst_port Destination port number * @param sequence sequence number * @param ack_num ACK number * @param urg URG flag * @param ack ACK flag * @param psh PSH flag * @param rst RST flag * @param syn SYN flag * @param fin FIN flag * @param window window size * @param urgent urgent pointer */ public TCPPacket(int src_port,int dst_port,long sequence,long ack_num, boolean urg,boolean ack,boolean psh,boolean rst, boolean syn,boolean fin,boolean rsv1,boolean rsv2, int window,int urgent){ this.src_port=src_port;this.dst_port=dst_port; this.sequence=sequence; this.ack_num=ack_num; this.urg=urg;this.ack=ack;this.psh=psh;this.rst=rst; this.syn=syn;this.fin=fin; // added by Damien Daspit 5/7/01 this.rsv1=rsv1;this.rsv2=rsv2; // ***************************** this.window=window; urgent_pointer=(short)urgent; } void setValue(int src,int dst,long seq,long ack_num,boolean urg,boolean ack, boolean psh,boolean rst,boolean syn,boolean fin,boolean rsv1, boolean rsv2, int win,short urp){ src_port=src;dst_port=dst; sequence=seq; this.ack_num=ack_num; this.urg=urg;this.ack=ack;this.psh=psh;this.rst=rst;this.syn=syn;this.fin=fin; // added by Damien Daspit 5/7/01 this.rsv1=rsv1;this.rsv2=rsv2; // ***************************** window=win; urgent_pointer=urp; } void setOption(byte[] option){ this.option=option; } /** Returns a string representation of this packet<BR> * * <BR> * Format: src_port > dst_port seq(sequence) win(window) [ack ack_num] [S][F][P] * @return a string representation of this packet */ public String toString(){ return super.toString()+" TCP "+ src_port+" > "+dst_port+" seq("+sequence+ ") win("+window+")"+(ack?" ack "+ack_num:"")+" "+ (syn?" S":"")+(fin?" F":"")+(psh?" P":"")+ (rst?" R":"")+(urg?" U":""); } } --- NEW FILE: IPPacket.java --- package jpcap.packet; import java.net.InetAddress; import java.net.UnknownHostException; /** This class represents an IP packet.<P> * Both IPv4 and IPv6 are supported. */ public class IPPacket extends Packet { /** IP version (v4/v6) */ public byte version; /** Priority (class) (v4/v6) */ public byte priority; /** IP flag bit: [D]elay (v4) */ public boolean d_flag; /** IP flag bit: [T]hrough (v4) */ public boolean t_flag; /** IP flag bit: [R]eliability (v4) */ public boolean r_flag; // added by Damien Daspit 5/7/01 /** Type of Service (TOS) (v4/v6) */ public byte rsv_tos; // ***************************** /** Packet length (v4/v6) */ public short length; /** Fragmentation reservation flag (v4) */ public boolean rsv_frag; /** Don't fragment flag (v4) */ public boolean dont_frag; /** More fragment flag (v4) */ public boolean more_frag; /** Fragment offset (v4) */ public short offset; /** Hop Limit, Time To Live (TTL) (v4/v6) */ public short hop_limit; /** Protocol (v4/v6) */ public short protocol; /** Protocol number for ICMP */ public static final short IPPROTO_ICMP=1; /** Protocol number for IGMP */ public static final short IPPROTO_IGMP=2; /** Protocol number for IP in IP */ public static final short IPPROTO_IP=4; /** Protocol number for TCP */ public static final short IPPROTO_TCP=6; /** Protocol number for UDP */ public static final short IPPROTO_UDP=17; /** Protocol number for IPv6 */ public static final short IPPROTO_IPv6=41; /** Protocol number for IPv6 hop-by-hop option */ public static final short IPPROTO_HOPOPT=0; /** Protocol number for routing header for IPv6 */ public static final short IPPROTO_IPv6_Route=43; /** Protocol number for fragment header for IPv6 */ public static final short IPPROTO_IPv6_Frag=44; /** Protocol number for IPv6 ICMP*/ public static final short IPPROTO_IPv6_ICMP=58; /** Protocol number for no next header header for IPv6 */ public static final short IPPROTO_IPv6_NoNxt=59; /** Protocol number for destination option for IPv6 */ public static final short IPPROTO_IPv6_Opts=60; /** IDENTIFICATION (v4) */ public int ident; /** Flow label (v6) */ public int flow_label; /** Source IP address */ public InetAddress src_ip; /** Destination IP address */ public InetAddress dst_ip; /** Option in IPv4 header (v4) */ public byte[] option; /** Option headers in IPv6Option (v6) */ public java.util.List options=null; /** Sets the IPv4 parameters * @param d_flag IP flag bit: [D]elay * @param t_flag IP flag bit: [T]hrough * @param r_flag IP flag bit: [R]eliability * @param rsv_tos Type of Service (TOS) * @param priority Priority * @param rsv_frag Fragmentation Reservation flag * @param dont_frag Don't fragment flag * @param more_frag More fragment flag * @param offset Offset * @param ident Identifier * @param ttl Time To Live * @param protocol Protocol <BR> * This value is ignored when this packets * inherits a higher layer protocol(e.g. TCPPacket) * @param src Source IP address * @param dst Destination IP address */ public void setIPv4Parameter(int priority, boolean d_flag,boolean t_flag,boolean r_flag, int rsv_tos, boolean rsv_frag,boolean dont_frag,boolean more_frag, int offset,int ident,int ttl, int protocol,InetAddress src,InetAddress dst){ this.version=4; this.priority=(byte)priority; this.d_flag=d_flag;this.t_flag=t_flag;this.r_flag=r_flag; // added by Damien Daspit 5/7/01 this.rsv_tos=(byte)rsv_tos; // ***************************** this.rsv_frag=rsv_frag;this.dont_frag=dont_frag; this.more_frag=more_frag; offset=(short)offset; this.ident=ident; this.hop_limit=(short)ttl; this.protocol=(short)protocol; this.src_ip=src; this.dst_ip=dst; } /** Sets the IPv6 parameters * @param cls class * @param flowlabel flow label * @param nxt_hdr next header * @param hop_limit hop limit * @param src source address * @param dst destination address */ public void setIPv6Parameter(int cls,int flowlabel,int nxt_hdr, int hop_limit,InetAddress src,InetAddress dst){ this.version=6; this.priority=(byte)cls; this.flow_label=flowlabel; this.protocol=(short)nxt_hdr; this.hop_limit=(short)hop_limit; this.src_ip=src; this.dst_ip=dst; } void setIPv4Value(byte ver,byte pri,boolean d,boolean t,boolean r,byte rsv_tos, boolean rf,boolean df,boolean mf,short offset, short len,short ident,short ttl,short proto, byte[] src,byte[] dst){ this.version=ver; this.priority=pri; d_flag=d;t_flag=t;r_flag=r; // added by Damien Daspit 5/7/01 this.rsv_tos=rsv_tos; // ***************************** rsv_frag=rf;dont_frag=df;more_frag=mf; this.offset=offset; this.length=len; this.ident=ident; this.hop_limit=ttl; this.protocol=proto; try { this.src_ip=InetAddress.getByAddress(src); this.dst_ip=InetAddress.getByAddress(dst); } catch (UnknownHostException e) { } } void setOption(byte[] option){ this.option=option; } void setIPv6Value(byte ver,byte v6class,int flow, short payload,byte nxt,short hlim, byte[] src,byte[] dst){ this.version=ver; this.priority=v6class; this.flow_label=flow; this.length=payload; this.protocol=nxt; this.hop_limit=hlim; try { this.src_ip=InetAddress.getByAddress(src); this.dst_ip=InetAddress.getByAddress(dst); } catch (UnknownHostException e) { } } void addOptionHeader(IPv6Option header){ if(options==null) options=new java.util.ArrayList(); options.add(header); } byte[] getSourceAddress(){ return src_ip.getAddress(); } byte[] getDestinationAddress(){ return dst_ip.getAddress(); } /** Returns a string represenation of this packet.<P> * Format(IPv4): src_ip->dst_ip protocol(protocol) priority(priority) * [D][T][R] hop(hop_limit) [RF/][DF/][MF] offset(offset) ident(ident)<P> * * Format(IPv6): src_ip->dst_ip protocol(protocol) priority(priority) * flowlabel(flow_label) hop(hop_limit) * @return a string represenation of this packet */ public String toString(){ if(version==4){ return super.toString()+" "+src_ip+"->"+ dst_ip+" protocol("+protocol+ ") priority("+priority+") "+(d_flag?"D":"")+(t_flag?"T":"")+ (r_flag?"R":"")+" hop("+hop_limit+") "+(rsv_frag?"RF/":"")+ (dont_frag?"DF/":"")+(more_frag?"MF":"")+" offset("+offset+ ") ident("+ident+")"; }else{ return super.toString()+" "+src_ip+"->"+ dst_ip+" protocol("+protocol+") priority("+priority+ ") flowlabel("+flow_label+") hop("+hop_limit+")"; } } } --- NEW FILE: ICMPPacket.java --- package jpcap.packet; import java.net.InetAddress; import java.net.UnknownHostException; /** * This class represents ICMP packet. */ public class ICMPPacket extends IPPacket { /** * echo reply */ public static final short ICMP_ECHOREPLY = 0; /** * dest unreachable */ public static final short ICMP_UNREACH = 3; /** * dest unreachable code: bad net */ public static final short ICMP_UNREACH_NET = 0; /** * dest unreachable code: bad host */ public static final short ICMP_UNREACH_HOST = 1; /** * dest unreachable code: bad protocol */ public static final short ICMP_UNREACH_PROTOCOL = 2; /** * dest unreachable code: bad port */ public static final short ICMP_UNREACH_PORT = 3; /** * dest unreachable code: IP_DF caused drop */ public static final short ICMP_UNREACH_NEEDFRAG = 4; /** * dest unreachable code: src route failed */ public static final short ICMP_UNREACH_SRCFAIL = 5; /** * dest unreachable code: unknown net */ public static final short ICMP_UNREACH_NET_UNKNOWN = 6; /** * dest unreachable code: unknown host */ public static final short ICMP_UNREACH_HOST_UNKNOWN = 7; /** * dest unreachable code: src host isolated */ public static final short ICMP_UNREACH_ISOLATED = 8; /** * dest unreachable code: prohibited access */ public static final short ICMP_UNREACH_NET_PROHIB = 9; /** * dest unreachable code: ditto */ public static final short ICMP_UNREACH_HOST_PROHIB = 10; /** * dest unreachable code: bad tos for net */ public static final short ICMP_UNREACH_TOSNET = 11; /** * dest unreachable code: bad tos for host */ public static final short ICMP_UNREACH_TOSHOST = 12; /** * dest unreachable code: admin prohib */ public static final short ICMP_UNREACH_FILTER_PROHIB = 13; /** * dest unreachable code: host prec vio. */ public static final short ICMP_UNREACH_HOST_PRECEDENCE = 14; /** * dest unreachable code: prec cutoff */ public static final short ICMP_UNREACH_PRECEDENCE_CUTOFF = 15; /** * packet lost, slow down */ public static final short ICMP_SOURCEQUENCH = 4; /** * redirect */ public static final short ICMP_REDIRECT = 5; /** * redirect code: for network */ public static final short ICMP_REDIRECT_NET = 0; /** * redirect code: for host */ public static final short ICMP_REDIRECT_HOST = 1; /** * redirect code: for tos and net */ public static final short ICMP_REDIRECT_TOSNET = 2; /** * redirect code: for tos and host */ public static final short ICMP_REDIRECT_TOSHOST = 3; /** * echo request */ public static final short ICMP_ECHO = 8; /** * router advertisement */ public static final short ICMP_ROUTERADVERT = 9; /** * router solicitation */ public static final short ICMP_ROUTERSOLICIT = 10; /** * time exceeded */ public static final short ICMP_TIMXCEED = 11; /** * time exceeded code: ttl==0 in transit */ public static final short ICMP_TIMXCEED_INTRANS = 0; /** * time exceeded code: ttl==0 in reass */ public static final short ICMP_TIMXCEED_REASS = 1; /** * ip header bad */ public static final short ICMP_PARAMPROB = 12; /** * ip header bad code: error at param ptr */ public static final short ICMP_PARAMPROB_ERRATPTR = 0; /** * ip header bad code: req. opt. absent */ public static final short ICMP_PARAMPROB_OPTABSENT = 1; /** * ip header bad code: bad length */ public static final short ICMP_PARAMPROB_LENGTH = 2; /** * timestamp request */ public static final short ICMP_TSTAMP = 13; /** * timestamp reply */ public static final short ICMP_TSTAMPREPLY = 14; /** * information request */ public static final short ICMP_IREQ = 15; /** * information reply */ public static final short ICMP_IREQREPLY = 16; /** * address mask request */ public static final short ICMP_MASKREQ = 17; /** * address mask reply */ public static final short ICMP_MASKREPLY = 18; /** ICMP type */ public byte type; /** ICMP code */ public byte code; /** Checksum */ public short checksum; /** * ID */ public int id; /** Sequence number */ public int seq; /** Subnet mask */ public int subnetmask; /** Originate timestamp */ public int orig_timestamp; /** Receive timestamp */ public int recv_timestamp; /** Transmit timestamp */ public int trans_timestamp; /** * MTU */ public short mtu; /** Returned IP packet */ public IPPacket ippacket; /** Redirect address */ public InetAddress redir_ip; /** The number of advertised addresses */ public byte addr_num; /** Address entry size */ public byte addr_entry_size; /** Address alive time */ public short alive_time; /** Advertised addresses */ public InetAddress[] router_ip; /** Preference */ public int[] preference; void setValue(byte type, byte code, short checksum, short id, short seq) { this.type = type; this.code = code; this.checksum = checksum; this.id = id; this.seq = seq; } void setID(int id, int seq) { this.id = id; this.seq = seq; } void setTimestampValue(int orig, int recv, int trans) { this.orig_timestamp = orig; this.recv_timestamp = recv; this.trans_timestamp = trans; } void setRedirectIP(byte[] ip) { try { redir_ip = InetAddress.getByAddress(ip); } catch (UnknownHostException e) { } } byte[] getRedirectIP(){ return redir_ip.getAddress(); } void setRouterAdValue(byte addr_num, byte entry_size, short alive_time, String[] addr, int[] pref) { this.addr_num = addr_num; this.addr_entry_size = entry_size; this.alive_time = alive_time; for (int i = 0; i < addr_num; i++) { try { router_ip[i] = InetAddress.getByName(addr[i]); } catch (java.net.UnknownHostException e) { } preference[i] = pref[i]; } } /** * Returns a string representation of this ICMP packet.<BR> * <BR> * FormatFtype(type) code(code) * * @return string representation of this ICMP packet */ public String toString() { return super.toString() + "type(" + type + ") code(" + code + ")"; } } --- NEW FILE: IPv6Option.java --- package jpcap.packet; import java.net.InetAddress; /** This class represents IPv6 option headers. */ public class IPv6Option{ /** Hop by hop option */ public static final byte HOP_BY_HOP_OPTION=0; /** Routing option */ public static final byte ROUTING_OPTION=43; /** Fragment option */ public static final byte FRAGMENT_OPTION=44; /** Security payload option */ public static final byte ESP_OPTION=50; /** Authentication option */ public static final byte AH_OPTION=51; /** No next option header */ public static final byte NONE_OPTION=59; /** Destination option */ public static final byte DESTINATION_OPTION=60; /** Type */ public byte type; /** Next header */ public byte next_header; /** Header length */ public byte hlen; /** Option */ public byte[] option; /** Routing type (Routing option) */ public byte routing_type; /** Hop number left (Routing option) */ public byte hop_left; /** Route addresses (Routing option) */ public InetAddress[] addrs; /** Offset (Fragment option) */ public short offset; /** More flag (fragment option) */ public boolean m_flag; /** Identification (fragment option) */ public int identification; /** SPI (AH option) */ public int spi; /** Sequence number (AH option) */ public int sequence; void setValue(byte type,byte next,byte hlen){ this.type=type; this.next_header=next; this.hlen=hlen; } void setOptionData(byte[] option){ this.option=option; } void setRoutingOption(byte type,byte left,String[] addrs){ this.routing_type=type; this.hop_left=left; this.addrs=new InetAddress[addrs.length]; for(int i=0;i<addrs.length;i++){ try{ this.addrs[i]=InetAddress.getByName(addrs[i]); }catch(java.net.UnknownHostException e){} } } void setFragmentOption(short offset,boolean m,int ident){ this.offset=offset; this.m_flag=m; this.identification=ident; } void setAHOption(int spi,int seq){ this.spi=spi; this.sequence=seq; } } --- NEW FILE: Packet.java --- package jpcap.packet; import jpcap.JpcapCaptor; /** This is a root class of the all the packets captured by {@link JpcapCaptor Jpcap}. */ public class Packet { /** Captured timestamp (sec) */ public long sec; /** Captured timestamp (micro sec) */ public long usec; /** Captured length */ public int caplen; /** Length of this packet */ public int len; /** Datalink layer header */ public DatalinkPacket datalink; /** Header data */ public byte[] header; /** Packet data (excluding the header) */ public byte[] data; void setPacketValue(long sec,long usec,int caplen,int len){ this.sec=sec;this.usec=usec; this.caplen=caplen; this.len=len; } void setDatalinkPacket(DatalinkPacket p){ datalink=p; } void setPacketData(byte[] data){ this.data=data; } void setPacketHeader(byte[] header){ this.header=header; } /** Returns a string representation of this packet<BR> * Format: sec:usec * @return a string representation of this packet */ public String toString(){ return sec+":"+usec; } } |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:51:03
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/sample In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13312/lib/jpcap-0.5.1-lib/sample Added Files: Tcpdump.java SendICMP.java ARP.java SendTCP.java SendUDP.java Traceroute.java Log Message: Added remaining Jpcap files (java sources + docs) --- NEW FILE: Traceroute.java --- import java.net.Inet4Address; import java.net.InetAddress; import java.net.URL; import java.util.Arrays; import jpcap.JpcapCaptor; import jpcap.JpcapSender; import jpcap.NetworkInterface; import jpcap.NetworkInterfaceAddress; import jpcap.packet.EthernetPacket; import jpcap.packet.ICMPPacket; import jpcap.packet.IPPacket; import jpcap.packet.Packet; public class Traceroute { public static void main(String[] args) throws Exception{ if(args.length<2){ System.out.println("Usage: java Traceroute <device index (e.g., 0, 1..)> <target host address>"); System.exit(0); } //initialize Jpcap NetworkInterface device=JpcapCaptor.getDeviceList()[Integer.parseInt(args[0])]; JpcapCaptor captor=JpcapCaptor.openDevice(device,2000,false,5000); InetAddress thisIP=null; for(NetworkInterfaceAddress addr:device.addresses) if(addr.address instanceof Inet4Address){ thisIP=addr.address; break; } //obtain MAC address of the default gateway InetAddress pingAddr=InetAddress.getByName("www.microsoft.com"); captor.setFilter("tcp and dst host "+pingAddr.getHostAddress(),true); byte[] gwmac=null; while(true){ new URL("http://www.microsoft.com").openStream().close(); Packet ping=captor.getPacket(); if(ping==null){ System.out.println("cannot obtain MAC address of default gateway."); System.exit(-1); }else if(Arrays.equals(((EthernetPacket)ping.datalink).dst_mac,device.mac_address)) continue; gwmac=((EthernetPacket)ping.datalink).dst_mac; break; } //create ICMP packet ICMPPacket icmp=new ICMPPacket(); icmp.type=ICMPPacket.ICMP_ECHO; icmp.seq=100; icmp.id=0; icmp.setIPv4Parameter(0,false,false,false,0,false,false,false,0,0,0,IPPacket.IPPROTO_ICMP, thisIP,InetAddress.getByName(args[1])); icmp.data="data".getBytes(); EthernetPacket ether=new EthernetPacket(); ether.frametype=EthernetPacket.ETHERTYPE_IP; ether.src_mac=device.mac_address; ether.dst_mac=gwmac; icmp.datalink=ether; captor.setFilter("icmp and dst host "+thisIP.getHostAddress(),true); JpcapSender sender=captor.getJpcapSenderInstance(); //JpcapSender sender=JpcapSender.openDevice(device); sender.sendPacket(icmp); while(true){ ICMPPacket p=(ICMPPacket) captor.getPacket(); //System.out.println("received "+p); if(p==null){ System.out.println("Timeout"); }else if(p.type==ICMPPacket.ICMP_TIMXCEED){ p.src_ip.getHostName(); System.out.println(icmp.hop_limit+": "+p.src_ip); icmp.hop_limit++; }else if(p.type==ICMPPacket.ICMP_UNREACH){ p.src_ip.getHostName(); System.out.println(icmp.hop_limit+": "+p.src_ip); System.exit(0); }else if(p.type==ICMPPacket.ICMP_ECHOREPLY){ p.src_ip.getHostName(); System.out.println(icmp.hop_limit+": "+p.src_ip); System.exit(0); }else continue; sender.sendPacket(icmp); } } } --- NEW FILE: SendICMP.java --- import java.net.InetAddress; import jpcap.*; import jpcap.packet.EthernetPacket; import jpcap.packet.ICMPPacket; import jpcap.packet.IPPacket; class SendICMP { public static void main(String[] args) throws java.io.IOException{ NetworkInterface[] devices = JpcapCaptor.getDeviceList(); if(args.length<1){ System.out.println("Usage: java SentICMP <device index (e.g., 0, 1..)>"); for(int i=0;i<devices.length;i++) System.out.println(i+":"+devices[i].name+"("+devices[i].description+")"); System.exit(0); } int index=Integer.parseInt(args[0]); JpcapSender sender=JpcapSender.openDevice(devices[index]); ICMPPacket p=new ICMPPacket(); p.type=ICMPPacket.ICMP_TSTAMP; p.seq=1000; p.id=999; p.orig_timestamp=123; p.trans_timestamp=456; p.recv_timestamp=789; p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,1010101,100,IPPacket.IPPROTO_ICMP, InetAddress.getByName("www.yahoo.com"),InetAddress.getByName("www.amazon.com")); p.data="data".getBytes(); EthernetPacket ether=new EthernetPacket(); ether.frametype=EthernetPacket.ETHERTYPE_IP; ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5}; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10}; p.datalink=ether; //for(int i=0;i<10;i++) sender.sendPacket(p); } } --- NEW FILE: ARP.java --- (This appears to be a binary file; contents omitted.) --- NEW FILE: Tcpdump.java --- import jpcap.*; import jpcap.packet.Packet; class Tcpdump implements PacketReceiver { public void receivePacket(Packet packet) { System.out.println(packet); } public static void main(String[] args) throws Exception { NetworkInterface[] devices = JpcapCaptor.getDeviceList(); if(args.length<1){ System.out.println("usage: java Tcpdump <select a number from the following>"); for (int i = 0; i < devices.length; i++) { System.out.println(i+" :"+devices[i].name + "(" + devices[i].description+")"); System.out.println(" data link:"+devices[i].datalink_name + "(" + devices[i].datalink_description+")"); System.out.print(" MAC address:"); for (byte b : devices[i].mac_address) System.out.print(Integer.toHexString(b&0xff) + ":"); System.out.println(); for (NetworkInterfaceAddress a : devices[i].addresses) System.out.println(" address:"+a.address + " " + a.subnet + " " + a.broadcast); } }else{ JpcapCaptor jpcap = JpcapCaptor.openDevice(devices[Integer.parseInt(args[0])], 2000, false, 20); jpcap.loopPacket(-1, new Tcpdump()); } } } --- NEW FILE: SendUDP.java --- import java.net.InetAddress; import jpcap.*; import jpcap.packet.EthernetPacket; import jpcap.packet.IPPacket; import jpcap.packet.UDPPacket; class SendUDP { public static void main(String[] args) throws java.io.IOException{ NetworkInterface[] devices = JpcapCaptor.getDeviceList(); if(args.length<1){ System.out.println("Usage: java SentUDP <device index (e.g., 0, 1..)>"); for(int i=0;i<devices.length;i++) System.out.println(i+":"+devices[i].name+"("+devices[i].description+")"); System.exit(0); } int index=Integer.parseInt(args[0]); JpcapSender sender=JpcapSender.openDevice(devices[index]); UDPPacket p=new UDPPacket(12345,54321); p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,1010101,100,IPPacket.IPPROTO_UDP, InetAddress.getByName("www.yahoo.com"),InetAddress.getByName("www.google.com")); p.data="data".getBytes(); EthernetPacket ether=new EthernetPacket(); ether.frametype=EthernetPacket.ETHERTYPE_IP; ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5}; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10}; p.datalink=ether; for(int i=0;i<10;i++) sender.sendPacket(p); } } --- NEW FILE: SendTCP.java --- import java.net.InetAddress; import jpcap.*; import jpcap.packet.EthernetPacket; import jpcap.packet.IPPacket; import jpcap.packet.TCPPacket; class SendTCP { public static void main(String[] args) throws java.io.IOException{ NetworkInterface[] devices = JpcapCaptor.getDeviceList(); if(args.length<1){ System.out.println("Usage: java SentTCP <device index (e.g., 0, 1..)>"); for(int i=0;i<devices.length;i++) System.out.println(i+":"+devices[i].name+"("+devices[i].description+")"); System.exit(0); } int index=Integer.parseInt(args[0]); JpcapSender sender=JpcapSender.openDevice(devices[index]); TCPPacket p=new TCPPacket(12,34,56,78,false,false,false,false,true,true,true,true,10,10); p.setIPv4Parameter(0,false,false,false,0,false,false,false,0,1010101,100,IPPacket.IPPROTO_TCP, InetAddress.getByName("www.microsoft.com"),InetAddress.getByName("www.google.com")); p.data="data".getBytes(); EthernetPacket ether=new EthernetPacket(); ether.frametype=EthernetPacket.ETHERTYPE_IP; ether.src_mac=new byte[]{(byte)0,(byte)1,(byte)2,(byte)3,(byte)4,(byte)5}; ether.dst_mac=new byte[]{(byte)0,(byte)6,(byte)7,(byte)8,(byte)9,(byte)10}; p.datalink=ether; for(int i=0;i<10;i++) sender.sendPacket(p); } } |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:50:51
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/doc/javadoc/jpcap/packet In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13177/lib/jpcap-0.5.1-lib/doc/javadoc/jpcap/packet Log Message: Directory /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/doc/javadoc/jpcap/packet added to the repository |
|
From: Peter P. <pr...@us...> - 2006-11-22 18:50:50
|
Update of /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13177/lib/jpcap-0.5.1-lib/src/java/jpcap Log Message: Directory /cvsroot/pyxida/Pyxida/lib/jpcap-0.5.1-lib/src/java/jpcap added to the repository |