Reputation: 170
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
Upvotes: 1
Views: 4119
Reputation: 126
Check type always from bpf.h file you are really using. This is a bpf.h:
#ifdef MSDOS /* must be 32-bit */
typedef long bpf_int32;
typedef unsigned long bpf_u_int32;
#else
typedef int bpf_int32;
typedef u_int bpf_u_int32;
#endif
Upvotes: 1
Reputation: 279265
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 by typeid(u_int32_t) == typeid(bpf_u_int32)
.
On some implementations there's at least the possibility that one is unsigned int
and the other is unsigned 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 _t
suffix 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.
Upvotes: 3
Reputation: 155046
Both types are most likely typedefs to a 32-bit unsigned type. As such, they can be considered equivalent and there is no useful difference between them.
Upvotes: 1