Hello everybody,
I'm coding a test program for ARP protocol, and i don't know why i'm getting a SIGSEGV, i traced it with gdb and it says it's due to the memcpy function from /lib/libc.so.6.
Program received signal SIGSEGV, Segmentation fault.
0xb7e9e327 in memcpy () from /lib/libc.so.6
This segmentation fault came when i decided to change the protocol headers, i was using a buffer to store two structures, containing ethernet & arp headers, and i decided to use just one structure, containing both headers structure.
This is the code:
struct ethernet{
unsigned char target[6];
unsigned char source[6];
unsigned short type;
};
struct arp{
unsigned short ar$hrd;
unsigned short ar$pro;
unsigned char ar$hln;
unsigned char ar$pln;
unsigned short ar$op;
unsigned char ar$sha[6];
unsigned char ar$spa[4];
unsigned char ar$tha[6];
unsigned char ar$tpa[4];
};
struct arpmsg{
struct ethernet ethernet;
struct arp arp;
};
And i get the segmentation fault in the main program when i use memcpy to store the addresses in their respective field, here's an example:
char mac[]={0x01,0x00,0x5E,0x03,0x03,0x08};
memcpy(arpmsg->arp.ar$sha, mac, 6);
Please, could anyone tell me what am i doing wrong? This is a weird error, gcc gives me no warnings.
Oh!, i changed the memcpy function to strncpy, strcpy, and i keep getting the same SIGSEGV.
I'll appreciate any answers, thank you.