Reputation: 119
I'm trying to build a raw data with ethernet frame via C code. I built a packet (included Ethernet->IP->UDP->DHCP protocols) and sent it via the WiFi interface. I followed it via the Wireshark which prints out: Ethernet2 -> Frame Check Sequence -> Incorrect, should be XXX.
I did not build an FCS data in my packet, I left the field blank. Now, I can't find any simple function/code in C which does that. All the codes I found gave me a bad output.
Someone done it before and can share how to implement the FCS in the Ethernet packet?
Thank you in advance
Upvotes: 0
Views: 2076
Reputation: 1
try:
#define BYTE unsigned char
int fcs(BYTE* paquete,int n){
int byte,sum=0;
n++;
for(int j=0;j<=n;j++){
byte=paquete[j];
for(int i=0;i<8;i++){
if(j!=n && i<7){
sum = sum+(byte & 0x01);
byte = byte >> 1;
}
}
}
return sum;
}
Upvotes: 0
Reputation: 119
FIX: it seems that FCS calculation is only optional, I added the IP checksum calculation instead and that was enough for the DHCP to pass.
Thanks.
Upvotes: 2