/*
* Gamers Own Instant Messenger
* Copyright (C) 2005-2006 Herbert Poul (kahless@sphene.net)
* http://goim.sphene.net
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
*/
package net.sphene.goim.rcp.sniffer;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.UnknownHostException;
import java.util.Map;
import net.sphene.goim.rcp.beans.GOIMGameItem;
import net.sphene.goim.sniffudpconns.SniffUdpConns;
public class GOIMSniffer extends SniffUdpConns {
private Map<Integer, Object> apps;
@Override
public void setApps(Map<Integer, Object> apps, int[][] arg1) {
super.setApps(apps, arg1);
this.apps = apps;
}
@Override
public void gotOutgoing(int id, long ip, int port, int sourceport) {
GOIMGameItem obj = (GOIMGameItem)apps.get(id);
//short portval = (short) port;
//System.out.println("Got outgoing(" + id + "): " + (obj == null ? "null?!":obj.toString()));
//System.out.println("Port: " + Integer.toString(port));
byte myip[] = new byte[] { (byte)((ip >> 24) & 0xFF),
(byte)((ip >> 16) & 0xFF),
(byte)((ip >> 8) & 0xFF),
(byte)((ip & 0xFF)) };
try {
if(obj != null)
obj.retrieveExtensionProxy().sniffedPacketFromGame(obj,new InetSocketAddress(InetAddress.getByAddress(myip),port), sourceport);
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (NullPointerException e) {
e.printStackTrace();
System.err.println("Null pointer exception ... obj: " + obj);
if(obj != null)
System.err.println("obj: " + obj.toString() + " ... obj.retrieveExtensionProxy: " + obj.retrieveExtensionProxy());
}
//System.out.printf("I got a connection from %s to " + myip[0] + "." + myip[1] + "." + myip[2] + "." + myip[3] + ":%d\n",obj.name,myip[0],myip[1],myip[2],myip[3],port);
//System.out.printf("Got Outgoing (%d) by %s to %d,%d,%d,%d:%d\n",id,(obj == null ? "null" : obj.toString()),
//
// port
// );
}
}