Check if an adress is in a subnet - C

0

I have this python code from a project i'm rebasing...

def addressInNetwork(ip, net):
   ipaddr = int(''.join([ '%02x' % int(x) for x in ip.split('.') ]), 16)
   netstr, bits = net.split('/')
   netaddr = int(''.join([ '%02x' % int(x) for x in netstr.split('.') ]), 16)
   mask = (0xffffffff << (32 - int(bits))) & 0xffffffff
   return (ipaddr & mask) == (netaddr & mask)

Which checks if an ip is part of a subnet... I'm not sure what exactly it does, but I do know it works... Could someone explain this to me, so that I can rewrite it in C or Assembly (depending how confident I feel lol)

python
networking
asked on Stack Overflow Aug 20, 2020 by Lewis Farnworth • edited Aug 20, 2020 by KamilCuk

0 Answers

Nobody has answered this question yet.


User contributions licensed under CC BY-SA 3.0