Evening,
I have been learning C these last few days and trying examples from a book I have, One such program is giving me trouble with segmentation errors. I have found the two lines that are causing it by using GDB and a bit of trial and error.
I have checked the source code distributed with the book and it also has the same segmentation error upon compilation.
Here is the function the issue is occurring in:
I have commented the two lines that cause the segmentation error- everything runs fine when they're commented out.
Any help would be great, I am quite new to C.
I have been learning C these last few days and trying examples from a book I have, One such program is giving me trouble with segmentation errors. I have found the two lines that are causing it by using GDB and a bit of trial and error.
I have checked the source code distributed with the book and it also has the same segmentation error upon compilation.
Here is the function the issue is occurring in:
Code:
void decode_ip(const u_char *header_start) {
const struct ip_hdr *ip_header;
ip_header = (const struct ip_hdr *)header_start;
printf("\t(( Layer 3 ::: IP Header ))\n");
printf("\t( Source: %s\t", inet_ntoa(ip_header->ip_src_addr)); // Problem
printf("Dest: %s )\n", inet_ntoa(ip_header->ip_dest_addr)); // Problem
printf("\t( Type: %u\t", (u_int) ip_header->ip_type);
printf("ID: %hu\tLength: %hu )\n", ntohs(ip_header->ip_id), ntohs(ip_header->ip_len));
}
I have commented the two lines that cause the segmentation error- everything runs fine when they're commented out.
Any help would be great, I am quite new to C.