Skip site navigation (1) Skip section navigation (2)

netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0

From: Oleg Sharoiko <os(at)rsu(dot)ru>
To: pgsql-bugs(at)postgresql(dot)org
Subject: netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0
Date: 1999-07-17 07:24:34
Message-ID: Pine.BSF.4.10.9907171121260.14010-100000@fido.rnd.runnet.ru (view raw or flat)
Thread:
Lists: pgsql-bugs
============================================================================
                        POSTGRESQL BUG REPORT TEMPLATE
============================================================================


Your name               : Oleg Sharoiko
Your email address      : os(at)rsu(dot)ru

Category                : runtime: back-end
Severity                : serious

Summary: netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0

System Configuration
--------------------
  Operating System   : FreeBSD 2.2.8-STABLE

  PostgreSQL version : 6.5

  Compiler used      : gcc version egcs-2.91.66 19990314 (egcs-1.1.2 release)

Hardware:
---------
Intel Pentium 200 Mhz, 64 Mb RAM
# uname -a
FreeBSD altos.rnd.runnet.ru 2.2.8-STABLE FreeBSD 2.2.8-STABLE #0: Sun Feb 14
20:13:50 MSK 1999     krs(at)altos(dot)rnd(dot)runnet(dot)ru:/usr/src/sys/compile/ALTOS  i386


Versions of other tools:
------------------------
GNU Make version 3.76.1

--------------------------------------------------------------------------

Problem Description:
--------------------
netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0
This is because (-1) << 32 is -1 (Only intel arc. has been checked)

--------------------------------------------------------------------------

Test Case:
----------
network=> create table test (ip inet);
CREATE
network=> insert into test values('0.0.0.0/0');
INSERT 21513 1
network=> select ip, netmask(ip) from test;
ip |        netmask
---+---------------
0/0|255.255.255.255
(1 row)


--------------------------------------------------------------------------

Solution:
---------
*** network.c   Sat Jul 17 11:01:02 1999
--- network_fixed.c     Sat Jul 17 11:08:29 1999
***************
*** 452,458 ****
        if (ip_family(ip) == AF_INET)
        {
                /* It's an IP V4 address: */
!               int                     addr = htonl((-1 << (32 -
ip_bits(ip))) & 0xffffffff);
  
                if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) ==
NULL)
                        elog(ERROR, "unable to print netmask (%s)",
strerror(errno));
--- 452,458 ----
        if (ip_family(ip) == AF_INET)
        {
                /* It's an IP V4 address: */
!               int                     addr = htonl(ip_bits(ip) ? (-1 << (32
- ip_bits(ip))) & 0xffffffff : 0x00000000);
  
                if (inet_net_ntop(AF_INET, &addr, 32, tmp, sizeof(tmp)) ==
NULL)
                        elog(ERROR, "unable to print netmask (%s)",
strerror(errno));


--------------------------------------------------------------------------

-- 
Oleg.


pgsql-bugs by date

Next:From: LeonDate: 1999-07-18 09:47:45
Subject: Re: [BUGS] Frontend coredumps on NOTICE
Previous:From: Wayne PiekarskiDate: 1999-07-17 03:23:22
Subject: Re: Oversize proc sources (was Re: [BUGS] Backend dies creating plpgsql procedures (with reproducible example!))

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group