The linux/ folder contains the ip.h header file, wherein part of the structure of IP header is defined as follows:
struct iphdr
{
// ...
__be32 saddr;
__be32 daddr;
};
I have a situation wherein I have a source netmask of type char*. I want to check whether a IP address of type __be32 belongs to a network with address of type char*. I can convert netmask and network address to __be32 using in_aton() provided in linux/inet.h.
char * network_addr = "192.166.0.0";
char * netmask = "255.255.0.0";
Can someone please tell how can I take the boolean && of addresses being type __be32 or just applying && operator will give correct result.
Thanks.
You are looking for the bitwise AND operator
&and not the logical AND operator&&:Remember IPv4 adresses are 32-bit number: 4 x 8-bit bytes