I found this piece of code online and it works as part of my project, but I'm not sure why. I don't want to just use it without understanding what it does.
type = (packet_data[12] << 8) | packet_data[13];
if I use it I get the proper type (0x0800 for IPv4) and can use it for comparison on printing out whether it's IPv4 or IPv6. If I don't use it and try something like:
if(packet_data[12] == 08 && packet_data[13] == 00)
print out IPv4
it doesn't work (compiling errors).
Also if I just print out the values like
printf"%02X", packet_data[12];
printf"%02X", packet_data[13];
it prints out the proper value in the form 0800, but I need to print out that it's an IPv4 type. Which is why I need to comparison in the first place. Thanks for any piece of advice or explanation on what this does would be much appreciated. Thanks