netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0
От | Oleg Sharoiko |
---|---|
Тема | netmask('x.x.x.x/0') is 255.255.255.255 instead of 0.0.0.0 |
Дата | |
Msg-id | Pine.BSF.4.10.9907171121260.14010-100000@fido.rnd.runnet.ru обсуждение исходный текст |
Список | pgsql-bugs |
============================================================================ POSTGRESQL BUG REPORT TEMPLATE ============================================================================ Your name : Oleg Sharoiko Your email address : os@rsu.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@altos.rnd.runnet.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 по дате отправления: