X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=KernelLand%2FModules%2FIPStack%2Fmain.c;h=82373ece03c5344ad5ecf97078dc6d090e09a0dd;hb=17b6125504e385c169193f3c8e29ced340425979;hp=bc920f1f6d97af9deff6d7cc64ce4c029fc4d7a2;hpb=d0b4559f2936f6d9f06be0f7c3c51527a480ec0d;p=tpg%2Facess2.git diff --git a/KernelLand/Modules/IPStack/main.c b/KernelLand/Modules/IPStack/main.c index bc920f1f..82373ece 100644 --- a/KernelLand/Modules/IPStack/main.c +++ b/KernelLand/Modules/IPStack/main.c @@ -108,6 +108,26 @@ int IPStack_CompareAddress(int AddressType, const void *Address1, const void *Ad return 0; } +bool IPStack_AddressIsBroadcast(int AddrType, const void *Addr, int SubnetBits) +{ + const size_t addrsize = IPStack_GetAddressSize(AddrType); + const Uint8 *addr = Addr; + + ASSERTC( SubnetBits, >=, 0 ); + ASSERTC( SubnetBits, <=, addrsize * 8 ); + const size_t host_bits = addrsize*8 - SubnetBits; + + for( int i = 0; i < host_bits/8; i ++ ) + { + if( addr[addrsize-i-1] != 0xFF ) + return false; + } + Uint8 mask = 0xFF >> (8-(host_bits%8)); + if( (addr[addrsize-host_bits/8-1] & mask) != mask ) + return false; + return true; +} + const char *IPStack_PrintAddress(int AddressType, const void *Address) { switch( AddressType )