it is ok if I do ?
on what I am working it displays just fine... but I want to know if I would encounter any problems if this gets on another workstationCode:fprintf(OUTPUT,"Source_Port=\t%d\n",((pkt_data[34])<<8)|pkt_data[35]);
Thankyou!
it is ok if I do ?
on what I am working it displays just fine... but I want to know if I would encounter any problems if this gets on another workstationCode:fprintf(OUTPUT,"Source_Port=\t%d\n",((pkt_data[34])<<8)|pkt_data[35]);
Thankyou!
Don't assume the byte order. Use hton[ls]() and ntoh[ls]() to "normalize" the data in the packet stream.
gg
It's not like "network order" is going to change. However, I also agree that ntohs() is a simpler way of converting it.
Also, if the data order was little-endian instead (dumb, but possible) there is no standard function which converts it for you. ntohs() isn't even that standard anyway (not part of standard C, anyway).
The stream that I use is from a pcap file (i use for processing winpcap) and the host is always a pc x86.. i belive that they have always the same endianness. I know that is a good practice to use the conversion function but in this case I can work with this.
Yes, x86 is guaranteed to stay little endian for the foreseeable future.
Making it portable just means that if you end up re-using this bit of code for something else, it will then work "automagically" when someone decides to run the same thing on a different processor architecture.
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.