Changeset 46e2152 in mainline
- Timestamp:
- 2024-12-28T18:44:18Z (10 months ago)
- Children:
- 503ce85
- Parents:
- caac052
- Location:
- uspace
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/pcapcat/eth_parser.c
rcaac052 r46e2152 69 69 #define BIG_END_16(buffer, idx) buffer[idx] << BYTE_SIZE | buffer[idx + 1] 70 70 71 /** Offsets of interesting fields in packet. */ 72 73 #define ARP_SENDER_MAC 22 74 #define ARP_SENDER_IP 28 75 #define ARP_TARGET_MAC 32 76 #define ARP_TARGET_IP 38 77 78 #define TCP_SRC_PORT 34 79 #define TCP_DST_PORT 36 80 81 #define IP_HEADER_LEN 14 82 #define IP_TOTAL_LEN 16 83 #define IP_PROTOCOL 23 84 #define IP_SRC_ADDR 26 85 #define IP_DST_ADDR 30 86 71 87 /** Read count bytes from char buffer. 72 88 * @param buffer of bytes to read from. … … 88 104 static void parse_arp(unsigned char *buffer, size_t size) 89 105 { 90 size_t sender_mac_offset = 22; 91 size_t sender_ip_offset = 28; 92 size_t target_mac_offset = 32; 93 size_t target_ip_offset = 38; 94 if (size < target_ip_offset + IPV4_ADDR_SIZE) { 106 if (size < ARP_TARGET_IP + IPV4_ADDR_SIZE) { 95 107 printf("%s %s", ARP_TEXT, MALFORMED_PACKET); 96 108 return; … … 102 114 uint8_t target_ip[IPV4_ADDR_SIZE]; 103 115 104 read_from_buffer(buffer, sender_mac_offset, ETH_ADDR_SIZE, sender_mac);105 read_from_buffer(buffer, sender_ip_offset, IPV4_ADDR_SIZE, sender_ip);106 read_from_buffer(buffer, target_mac_offset, ETH_ADDR_SIZE, target_mac);107 read_from_buffer(buffer, target_ip_offset, IPV4_ADDR_SIZE, target_ip);116 read_from_buffer(buffer, ARP_SENDER_MAC, ETH_ADDR_SIZE, sender_mac); 117 read_from_buffer(buffer, ARP_SENDER_IP, IPV4_ADDR_SIZE, sender_ip); 118 read_from_buffer(buffer, ARP_TARGET_MAC, ETH_ADDR_SIZE, target_mac); 119 read_from_buffer(buffer, ARP_TARGET_IP, IPV4_ADDR_SIZE, target_ip); 108 120 109 121 PRINT_MAC("Sender", sender_mac, ", "); … … 119 131 static void parse_tcp(unsigned char *buffer, size_t size) 120 132 { 121 size_t src_port_offset = 34; 122 size_t dst_port_offset = 36; 123 124 if (size < dst_port_offset + TCP_PORT_SIZE) { 133 if (size < TCP_DST_PORT + TCP_PORT_SIZE) { 125 134 printf("%s %s\n", TCP_TEXT, MALFORMED_PACKET); 126 135 return; 127 136 } 128 137 129 uint16_t src_port = BIG_END_16(buffer, src_port_offset);130 uint16_t dst_port = BIG_END_16(buffer, dst_port_offset);138 uint16_t src_port = BIG_END_16(buffer, TCP_SRC_PORT); 139 uint16_t dst_port = BIG_END_16(buffer, TCP_DST_PORT); 131 140 printf(" [%s] source port: %d, destination port: %d\n", TCP_TEXT, src_port, dst_port); 132 141 } … … 146 155 uint8_t dst_ip[IPV4_ADDR_SIZE]; 147 156 148 size_t hdr_length_offset = 14; 149 size_t total_len_offset = 16; 150 size_t protocol_offset = 23; 151 size_t src_ip_offset = 26; 152 size_t dst_ip_offset = 30; 153 154 if (size < dst_ip_offset + IPV4_ADDR_SIZE) { 157 if (size < IP_DST_ADDR + IPV4_ADDR_SIZE) { 155 158 printf("%s %s", IP_TEXT, MALFORMED_PACKET); 156 159 return; 157 160 } 158 161 159 header_length = (buffer[ hdr_length_offset] & LOWER_4_BITS) * HDR_SIZE_COEF;160 total_length = BIG_END_16(buffer, total_len_offset);162 header_length = (buffer[IP_HEADER_LEN] & LOWER_4_BITS) * HDR_SIZE_COEF; 163 total_length = BIG_END_16(buffer, IP_TOTAL_LEN); 161 164 payload_length = total_length - header_length; 162 ip_protocol = buffer[ protocol_offset];163 164 read_from_buffer(buffer, src_ip_offset, IPV4_ADDR_SIZE, src_ip);165 read_from_buffer(buffer, dst_ip_offset, IPV4_ADDR_SIZE, dst_ip);165 ip_protocol = buffer[IP_PROTOCOL]; 166 167 read_from_buffer(buffer, IP_SRC_ADDR, IPV4_ADDR_SIZE, src_ip); 168 read_from_buffer(buffer, IP_DST_ADDR, IPV4_ADDR_SIZE, dst_ip); 166 169 167 170 printf("%s header: %dB, payload: %dB, protocol: 0x%x, ", IP_TEXT, header_length, payload_length, ip_protocol); … … 250 253 read_bytes = fread(&hdr, 1, sizeof(pcap_packet_header_t), pcap_file); 251 254 } 252 253 fclose(pcap_file);254 255 } 255 256 -
uspace/app/pcapcat/main.c
rcaac052 r46e2152 86 86 parsers[parser_index].parse_file_header(&hdr); 87 87 parsers[parser_index].parse_packets(f, packet_count, verbose_flag); 88 89 fclose(f); 88 90 return 0; 89 91 } -
uspace/app/pcapctl/main.c
rcaac052 r46e2152 115 115 { "append", required_argument, 0, 'A' }, /* file as argument and ops 0 if not exist and 2 if exists */ 116 116 { "new", required_argument, 0, 'N' }, /* file name as argument */ 117 { "truncated", required_argument, 0, 'T' }, / / truncated ops118 { "usb", required_argument, 0, 'U' }, / /??117 { "truncated", required_argument, 0, 'T' }, /* file as an argument with device 0 and dump truncated packets (for debugging purposes) */ 118 { "usb", required_argument, 0, 'U' }, /* todo: dump usb packets (not fully implemnted)*/ 119 119 { "device", required_argument, 0, 'd' }, 120 120 { "list", no_argument, 0, 'l' }, … … 148 148 NAME " --list | -l \n" 149 149 "\tList of devices\n" 150 NAME " --new= | -N <outfile>\n" 151 "\tStart dumping with ops - 0, on device - 0\n" 152 NAME " --append= | -A <outfile>\n" 153 "\tContinue dumping on device - 0 to already existing file\n" 154 NAME " --truncated= | -T <outfile>\n" 155 "\tStart dumping truncated packets to file on device - 0\n" 150 156 NAME " --start | -r --device= | -d <device number from list> --outfile= | -o <outfile> --ops= | p <ops index>\n" 151 157 "\tPackets dumped from device will be written to <outfile>\n" -
uspace/lib/pcap/src/pcap_dumper.c
rcaac052 r46e2152 227 227 { 228 228 fibril_mutex_lock(&dumper->mutex); 229 errno_t rc = EOK;230 229 dumper->writer.ops = &ops[index]; 231 230 fibril_mutex_unlock(&dumper->mutex); 232 return rc;231 return EOK; 233 232 } 234 233
Note:
See TracChangeset
for help on using the changeset viewer.