- IGMPv2 capabilities added (report membership, leave group) - ICMP capabilities added (ping) - Tx Message Queue added
43 lines
1.4 KiB
C
43 lines
1.4 KiB
C
//
|
|
// Created by epagris on 2022.12.25..
|
|
//
|
|
|
|
#include "icmp_packet.h"
|
|
#include "../../utils.h"
|
|
#include "ipv4_packet.h"
|
|
|
|
int parse_icmp(const uint8_t *hdr, uint32_t size, PcktHeaderElement *pcktHdrLe, struct EthInterface_ *intf) {
|
|
// parse header
|
|
IcmpProps *icmpProps = HEADER_FETCH_PROPS(IcmpProps, pcktHdrLe);
|
|
FETCH_BYTE_ADVANCE(&icmpProps->type, hdr);
|
|
FETCH_BYTE_ADVANCE(&icmpProps->code, hdr);
|
|
FETCH_WORD_ADVANCE(&icmpProps->checksum, hdr);
|
|
FETCH_WORD_ADVANCE(&icmpProps->identifier, hdr);
|
|
FETCH_WORD_ADVANCE(&icmpProps->sequenceNumber, hdr);
|
|
|
|
// fill-in common fields
|
|
icmpProps->validityOK = true; // TODO...
|
|
icmpProps->containedPacketClass = 0;
|
|
icmpProps->headerSize = ETH_ICMP_HEADER_SIZE;
|
|
|
|
return 0;
|
|
}
|
|
|
|
void insert_icmp_header(uint8_t *hdr, const PcktHeaderElement *headers) {
|
|
uint8_t * hdrStart = hdr;
|
|
IcmpProps *icmpProps = HEADER_FETCH_PROPS(IcmpProps, headers);
|
|
FILL_BYTE_ADVANCE(hdr, &icmpProps->type);
|
|
FILL_BYTE_ADVANCE(hdr, &icmpProps->code);
|
|
uint8_t * ChkSumPtr = hdr;
|
|
icmpProps->checksum = 0;
|
|
FILL_ADVANCE(hdr, &icmpProps->checksum, 2);
|
|
FILL_ADVANCE(hdr, &icmpProps->identifier, 2);
|
|
FILL_ADVANCE(hdr, &icmpProps->sequenceNumber, 2);
|
|
|
|
IPv4Props * ipProps = HEADER_FETCH_PROPS(IPv4Props, headers->prev);
|
|
icmpProps->checksum = chksum(hdrStart, ipProps->TotalLength - ETH_IPv4_HEADER_SIZE);
|
|
FILL_WORD_H2N_ADVANCE(ChkSumPtr, icmpProps->checksum);
|
|
}
|
|
|
|
|