network/netmask problem

Wessel Dankers wsl at fruit.eu.org
Fri Jun 7 13:17:14 CEST 2002


On 2002-06-07 11:17:17+0200, Johannes Lode wrote:
> Please find an other fix for that because I think the maskcheck itself
> make sense. Unfortunately I am no good C programmer but an better
> assembler programmer. My fix of the maskcheck function would not be
> elegant C code.
> In assembler language I would create code that serves for the following
> function (IPv4):
> 
> netmask := ( 0xffffffff00000000 rshiftby netmasklength ) and 0xffffffff
> 
> OK := (netaddress and not(netmask)) = 0

I just changed it to this:

int maskcheck(char *a, int masklen, int len)
{
  int i;

  i = masklen / 8;
  masklen %= 8;

  if(a[i++] & (0xff >> masklen))
    return -1;

  for(; i < len; i++)
    if(a[i] != 0)
      return -2;

  return 0;
}

...which I hope will work better.

Have fun,

--
Wessel Dankers <wsl at fruit.eu.org>

Dew on the telephone lines.
--
TINC development list, tinc-devel at nl.linux.org
Archive: http://mail.nl.linux.org/tinc-devel/




More information about the Tinc-devel mailing list