
This is a low-level network debugging utility that utilizes raw packet i/o to construct and deconstruct tcp, udp, ipv4, arp, and icmp packets over ethernet.
Revision 5:c56386b9fc33, committed 2010-10-12
- Comitter:
- etherealflaim
- Date:
- Tue Oct 12 06:37:21 2010 +0000
- Parent:
- 4:88fc7fa58931
- Child:
- 6:66c4cd9073aa
- Commit message:
- Documentation enhancements
Changed in this revision
--- a/net/arp.h Tue Oct 12 06:21:05 2010 +0000 +++ b/net/arp.h Tue Oct 12 06:37:21 2010 +0000 @@ -1,10 +1,16 @@ -/// ARP Packet - #ifndef ARP_H #define ARP_H #include "net.h" +/** + \file + \brief ARP packet + + This file contains the memory map and associated functions for ARP packet + creation and deconstruction. +*/ + #define ETHERTYPE_ARP 0x0806 /// ARP Packet memory map
--- a/net/net.h Tue Oct 12 06:21:05 2010 +0000 +++ b/net/net.h Tue Oct 12 06:37:21 2010 +0000 @@ -1,3 +1,12 @@ +/** + @file net.h + @brief This file encompasses all of the networking headers and includes them automatically + + This file has some utility functions and definitions used by all of the networking headers, + and includes them all. This is the only file necessary to include to use all of the networking + facilities in nettool +*/ + #ifndef NETWORK_H #define NETWORK_H @@ -6,8 +15,6 @@ #include "ctype.h" -/// \file Overall networking header - Includes all other net/ headers - /// General networking checksum - Used for IP, TCP, UDP, ICMP, etc. /// Computes the one's complement of the one's complement sum of all of the given bytes except for the memory /// at skip_byte for skip_count bytes (e.g. the checksum). Optionally resumes computation from the (given) last checksum.
--- a/scanner.h Tue Oct 12 06:21:05 2010 +0000 +++ b/scanner.h Tue Oct 12 06:37:21 2010 +0000 @@ -31,12 +31,14 @@ LocalFileSystem local; public: + /// Constructor inline Scanner(Sniffer *_sniffer) : sniffer(_sniffer), local("local") { sniffer->attach_tcp(this, &Scanner::handle_tcp); } + /// Handle incoming TCP packets inline void handle_tcp(TCP_SegmentHeader *packet, u32 data_bytes) { if (packet->syn && packet->ack) @@ -45,6 +47,7 @@ } } + /// Handle the conclusion of the port scan (should not be called externally) inline void finish() { FILE *fp = fopen("/local/PortScan.txt", "w"); @@ -63,6 +66,7 @@ main_log.printf("Port scan complete."); } + /// Start a TCP port scan inline void start(Ethernet_MAC src, Ethernet_MAC dst, IP_Address srcip, IP_Address dstip) { // Create the ethernet frame, IP packet, and TCP segment memory mapping @@ -107,8 +111,10 @@ //scan(); } + /// Incremental scan updates (should not be called externally) inline void scan() { + // Common ports... currently unused static u16 ports[] = {1, 2, 3, 5, 7, 9, 11, 13, 17, 18, 19, 20, 21, 22, 23, 24, 25, 35, 37, 39, 41, 42, 43, 47, 49, 50, 51, 52, 53, 54, 56, 58, 70, 79, 80, 83, 88, 90, 101, 102, 104, 105, 107, 108, 109, 110, 111, 113, 113, 115, 117, 118, 119, 135, 137, 138, 139, 143, 152, 153,
--- a/sniffer.h Tue Oct 12 06:21:05 2010 +0000 +++ b/sniffer.h Tue Oct 12 06:37:21 2010 +0000 @@ -64,29 +64,29 @@ Ethernet_FrameHeader *outframe_header; public: - // Ethernet Frame Header + /// Ethernet Frame Header (incoming) Ethernet_FrameHeader *frame_header; - // IP Packet Header + /// IP Packet Header (incoming) IP_PacketHeader *ip_packet; - // ARP Packet + /// ARP Packet (incoming) ARP_Packet *arp_packet; - // TCP Packet + /// TCP Packet (incoming) TCP_SegmentHeader *tcp_packet; - // UDP Packet + /// UDP Packet (incoming) UDP_Packet *udp_packet; - // ICMP Packet + /// ICMP Packet (incoming) ICMP_Packet *icmp_packet; - // Generic + /// Generic - total data bytes unsigned int data_bytes; public: - // Constructor + /// Constructor inline Sniffer() : linked(LED1), received(LED2) { @@ -94,6 +94,7 @@ eth.address((char *)mac.octet); } + /// Inject the raw ethernet frame inline bool inject(void *data, unsigned int bytes) { // Send the packet @@ -105,6 +106,7 @@ return send_status; } + /// Inject the raw payload into an ethernet frame with the given destination and ethertype inline bool inject(Ethernet_MAC dest, u16 ethertype, void *packet, unsigned int bytes) { memset(outframe, 0x00, bytes); @@ -140,6 +142,7 @@ return send_status; } + /// Wait until there is more data to receive inline void wait_for_data() { while (true) @@ -158,7 +161,7 @@ } } - // Wait for an ethernet frame + /// Wait for an ethernet frame (will be stored in appropriate class member pointers) inline void next() { wait_for_data(); @@ -174,6 +177,7 @@ decode_ethernet(frame); } + /// Decode the given ethernet frame inline void decode_ethernet(void *frame) { Ethernet_FrameHeader *header = frame_header = (Ethernet_FrameHeader*)frame; @@ -193,6 +197,7 @@ } } + /// Decode the given ARP packet inline void decode_arp(ARP_Packet *packet) { fix_endian_arp(packet); @@ -200,6 +205,7 @@ arp_packet = packet; } + /// Decode the given IPv4 packet inline void decode_ip(IP_PacketHeader *packet) { u16 chk = checksum(packet, sizeof(IP_PacketHeader), &packet->header_checksum, 2); @@ -238,12 +244,14 @@ if (tcp_handler) (*tcp_handler)(tcp_packet,data_bytes); } + /// Attach a member function to be called on all TCP packets template <class T> inline void attach_tcp(T *inst, void (T::*func)(TCP_SegmentHeader *tcp_packet, u32 data_bytes)) { tcp_handler = new member_handler<T,TCP_SegmentHeader*,u32,void>(inst, func); } + /// Attach a non-member function to be called on all TCP packets inline void attach_tcp(void (*func)(TCP_SegmentHeader *tcp_packet, u32 data_bytes)) { tcp_handler = new function_handler<TCP_SegmentHeader*,u32,void>(func);