-
Notifications
You must be signed in to change notification settings - Fork 1
Improve IP Packet Parser #1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR overhauls the IP Packet Parser by fixing parsing bugs, adding robust error handling, and introducing build and test tooling.
- Added a Makefile and packet generator for easier compilation and testing
- Enhanced IPv4/IPv6 parsing (bit manipulation, address formatting, TTL output)
- Improved CLI argument handling and documentation
Reviewed Changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| README.md | Completely rewrote usage, features, and examples |
| Makefile | New build rules for parser and generator |
| IP Packet Reader/protocol.c | Extended protocol lookup table |
| IP Packet Reader/packet_generator.c | Added IPv4/IPv6 packet generator tool |
| IP Packet Reader/main.c | Improved argument checks and error messages |
| IP Packet Reader/IPv6.h & IPv6.c | Refactored IPv6 parsing/formatting with compression |
| IP Packet Reader/IPv4.h & IPv4.c | Fixed struct typos, IHL/fragment logic, and added TTL print |
Comments suppressed due to low confidence (2)
IP Packet Reader/main.c:18
- The usage message references "./main" but the actual binary is named "ip_packet_parser"; updating to use argv[0] or the correct executable name would avoid confusion.
#define USAGE printf("./main [packet files]\n");
IP Packet Reader/main.c:39
- Opening packet files in text mode can cause issues on some platforms; use "rb" for binary mode to ensure correct reading.
FILE *file = fopen(argv[i], "r");
| SRC_DIR = IP\ Packet\ Reader | ||
| SRCS = $(SRC_DIR)/main.c $(SRC_DIR)/IPv4.c $(SRC_DIR)/IPv6.c $(SRC_DIR)/protocol.c | ||
| OBJS = $(SRCS:.c=.o) | ||
| TARGET = ip_packet_parser | ||
| GEN_SRC = $(SRC_DIR)/packet_generator.c |
Copilot
AI
May 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] Escaping spaces in directory names can be fragile; consider renaming the "IP Packet Reader" folder to avoid spaces or using a variable with quotes.
| SRC_DIR = IP\ Packet\ Reader | |
| SRCS = $(SRC_DIR)/main.c $(SRC_DIR)/IPv4.c $(SRC_DIR)/IPv6.c $(SRC_DIR)/protocol.c | |
| OBJS = $(SRCS:.c=.o) | |
| TARGET = ip_packet_parser | |
| GEN_SRC = $(SRC_DIR)/packet_generator.c | |
| SRC_DIR = "IP Packet Reader" | |
| SRCS = "$(SRC_DIR)/main.c" "$(SRC_DIR)/IPv4.c" "$(SRC_DIR)/IPv6.c" "$(SRC_DIR)/protocol.c" | |
| OBJS = $(SRCS:.c=.o) | |
| TARGET = ip_packet_parser | |
| GEN_SRC = "$(SRC_DIR)/packet_generator.c" |
| // Write the packet to the file | ||
| // This would need to be implemented to actually write the binary data |
Copilot
AI
May 13, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The create_IPv4_packets function currently only populates a struct but does not write any binary packet data to the file; either implement the output logic or remove the unused stub.
| // Write the packet to the file | |
| // This would need to be implemented to actually write the binary data | |
| // Serialize the packet into binary format | |
| unsigned char buffer[20]; // Minimum IPv4 header size is 20 bytes | |
| buffer[0] = (packet.version << 4) | packet.IHL; | |
| buffer[1] = packet.TOS; | |
| buffer[2] = (packet.total_length >> 8) & 0xFF; | |
| buffer[3] = packet.total_length & 0xFF; | |
| buffer[4] = (packet.ID >> 8) & 0xFF; | |
| buffer[5] = packet.ID & 0xFF; | |
| buffer[6] = (packet.Flags << 5) | ((packet.fragment_off >> 8) & 0x1F); | |
| buffer[7] = packet.fragment_off & 0xFF; | |
| buffer[8] = packet.TTL; | |
| buffer[9] = packet.protocol; | |
| buffer[10] = (packet.checksum >> 8) & 0xFF; | |
| buffer[11] = packet.checksum & 0xFF; | |
| for (int j = 0; j < 4; j++) { | |
| buffer[12 + j] = packet.source_address[j]; | |
| buffer[16 + j] = packet.destination_address[j]; | |
| } | |
| // Write the binary data to the file | |
| if (fwrite(buffer, 1, sizeof(buffer), file) != sizeof(buffer)) { | |
| fprintf(stderr, "Error: Failed to write packet to file\n"); | |
| } |
This PR improves the IP Packet Parser project with several enhancements:
Bug Fixes
Improvements
New Features
Documentation
These changes make the project more robust, user-friendly, and educational.
💻 View my work • About Codegen