IPv4 header generation bug fixed; utils MSG(...) fixed

This commit is contained in:
Wiesner András 2022-11-13 15:54:28 +01:00
parent a46b3a8564
commit 586a9ba733
2 changed files with 4 additions and 5 deletions

View File

@ -77,11 +77,11 @@ void insert_ipv4_header(uint8_t *hdr, const PcktHeaderElement *headers) {
FILL_ADVANCE(hdr, &ipProps->DSF, 1); FILL_ADVANCE(hdr, &ipProps->DSF, 1);
FILL_WORD_H2N_ADVANCE(hdr, ipProps->TotalLength); FILL_WORD_H2N_ADVANCE(hdr, ipProps->TotalLength);
FILL_WORD_H2N_ADVANCE(hdr, ipProps->Identification); FILL_WORD_H2N_ADVANCE(hdr, ipProps->Identification);
uint16_t flags_fragOffset = ((ipProps->Flags & 0x07) << 13) | (flags_fragOffset & ~(0x07 << 13)); uint16_t flags_fragOffset = ((ipProps->Flags & 0x07) << 13) | (ipProps->FragmentOffset & ~(0x07 << 13));
FILL_ADVANCE(hdr, &ipProps->TTL, 1); FILL_ADVANCE(hdr, &ipProps->TTL, 1);
FILL_ADVANCE(hdr, &ipProps->Protocol, 1); FILL_ADVANCE(hdr, &ipProps->Protocol, 1);
uint16_t checksum = ip_checksum(ipProps); uint16_t checksum = ip_checksum(ipProps);
FILL_WORD_H2N_ADVANCE(hdr, checksum); FILL_WORD_H2N_ADVANCE(hdr, checksum);
FILL_ADVANCE(hdr, &ipProps->SourceIPAddr, 4); FILL_ADVANCE(hdr, &ipProps->SourceIPAddr, 4);
FILL_ADVANCE(hdr, &ipProps->DestIPAddr, 4); FILL_ADVANCE(hdr, &ipProps->DestIPAddr, 4);
} }

View File

@ -31,9 +31,8 @@
#define ntohs(a) htons((a)) #define ntohs(a) htons((a))
#endif #endif
#define ERROR(...) printf(__VA_ARGS__) #define ERROR(...) MSG(__VA_ARGS__)
#define INFO(...) printf(__VA_ARGS__) #define INFO(...) MSG(__VA_ARGS__)
#define MSG(...) printf(__VA_ARGS__)
#define IPv4(a,b,c,d) ((a) | (b << 8) | (c << 16) | (d << 24)) #define IPv4(a,b,c,d) ((a) | (b << 8) | (c << 16) | (d << 24))
#define PRINT_IPv4(ip) MSG("%u.%u.%u.%u", (ip & 0xFF), ((ip >> 8) & 0xFF), ((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF)) #define PRINT_IPv4(ip) MSG("%u.%u.%u.%u", (ip & 0xFF), ((ip >> 8) & 0xFF), ((ip >> 16) & 0xFF), ((ip >> 24) & 0xFF))