|
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; } } |