/* * BayonneMon * * A simple application to monitor Bayonne status * * (C) 2002 Jason Spence, * * Released under the GPL */ import java.io.*; import java.net.*; import java.awt.*; import java.awt.event.*; class BayonneMon { static String[] hosts = new String[1024]; static int hosts_len = 0; static GridLayout hostLayout = new GridLayout(2, 2); static public void main(String args[]) throws Exception { DatagramSocket socket = new DatagramSocket(7000); for(int i = 0; i < 1024; ++i) { hosts[i] = ""; } System.out.println("UDP SERVER LISTENING"); Frame f = new Frame("Bayonne status monitor"); f.setSize(300,300); f.setLayout(hostLayout); f.addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent e) { System.exit(0); } }); f.show(); while(true) { byte[] in = new byte[1536]; byte[] name = new byte[16]; byte[] stats = new byte[255]; char[] status = new char[1]; DatagramPacket packet = new DatagramPacket(in, in.length); socket.receive(packet); InetAddress address = packet.getAddress(); int port = packet.getPort(); for(int i = 0; i < 16; ++i) { if(in[i + 4] < 0x20 || name[i + 4] > 0x7e) { break; } name[i] = in[i + 4]; } for(int i = 0; i < 255; ++i) { stats[i] = in[i + 27]; } String s = new String(in, 0, packet.getLength(), "ISO-8859-1"); String n = new String(name, 0, 16, "ISO-8859-1"); String st = new String(stats, 0, 255, "ISO-8859-1"); String st2 = new String(); for(int i = 0; i < st.length(); ++i) { if(st.charAt(i) < 0x20 || st.charAt(i) > 0x7e) { break; } st2 = st2 + st.charAt(i); } System.out.println("UDPReceive FROM CLIENT " + n + ": " + st); if(seenHost(n)) { f.repaint(); } else { Container c = new Container(); addHost(n); f.add(new Label(n)); f.add(c); c.setLayout(new GridLayout(st2.length(), 2)); for(int i = 0; i < st2.length(); ++i) { c.add(new Label("Port " + i)); status[0] = st2.charAt(i); c.add(new Label(new String(status))); } f.pack(); f.repaint(); } } } static boolean seenHost(String host) { for(int i = 0; i < hosts_len; ++i) { if(hosts[i].equals(host)) { return true; } } return false; } static void addHost(String host) { hosts[hosts_len] = host; hosts_len++; hostLayout.setRows(hosts_len); } }