Hi,
I am currently writing a program using raw sockets. This program is used to send out ARP reply frames.
The problem that I have is that I do not seem to be able to fill out a structure that is pointing to part of a character array.
Code:
struct eth_header *eth;
struct arp_header *arp;
char buf[8];
eth = (struct eth_header *)buf;
arp = (struct arp_header *)(buf+sizeof(struct arp_header));
Whilst I can fill out the variables of eth, I cannot fill out the variables of arp. If I fill them out and then send the contents of the array using sendto, only the first structure (the ethernet header) is sent out. The rest of the data appears to be the original junk data in the array.
I have checked the address of the structure pointer and it is pointing to the right place in the array.
If I write a raw sockets program that uses an IP header struct and TCP header struct I can point these into the array and write to both of them without any issues.
The difference here is that the call to socket is different:
Code:
/* For ethernet */
fd = socket(AF_INET, SOCK_PACKET, htons(ETH_P_ARP));
/* For IP */
fd = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
If I just create one structure containing all of the varaibles needed this gets around the issue, however, I would like to know what I am doing wrong in the first instance.
Can anyone help?
Cheers