I’ve been busy doing some network programming over the past couple of days and I cant seem to figure out a difference between the data types u_int32_t abd bpf_u_int32.
u_int32_t means 32 unsigned bits. Doesnt bpf_u_int32 mean the same?
Because some functions read the IP address in one form or the other.
Some functions in the pcap library like pcap_lookupnet require the net address to be of the form bpf_u_int32.
I am curious to know the difference
Programmers add layers of indirection for a living. They’re almost certainly the same type, you can check that in C++ with
#include <typeinfo>followed bytypeid(u_int32_t) == typeid(bpf_u_int32).On some implementations there’s at least the possibility that one is
unsigned intand the other isunsigned long.What’s happened is that two different people have independently chosen a name for a 32 bit unsigned type (or maybe the same person for two slightly different purposes). One of them has used a “bpf” prefix, which in this context stands for Berkeley Packet Filter since that’s relevant to packet capture. The other one hasn’t. One has used the
_tsuffix that indicates a type name, the other hasn’t. Aside from that, they picked similar names.C99 and C++11 both introduce a standard name for a 32 bit unsigned type:
uint32_t. That won’t stop people creating their own aliases for it, though.