Re: [HACKERS] CIDR type and functions
От | darcy@druid.net (D'Arcy J.M. Cain) |
---|---|
Тема | Re: [HACKERS] CIDR type and functions |
Дата | |
Msg-id | m0zRkRp-0000exC@druid.net обсуждение исходный текст |
Ответ на | Re: [HACKERS] CIDR type and functions (Bruce Momjian <maillist@candle.pha.pa.us>) |
Список | pgsql-hackers |
Thus spake Bruce Momjian > > Here are the functions I had suggested. > > > > netmask('192.3.4.5/24::cidr') == 255.255.255.0 > > masklen('192.3.4.5/24::cidr') == 24 > > host('192.3.4.5/24::cidr') == 192.3.4.5 > > network('192.3.4.5/24::cidr') == 192.3.4.0 I forgot broadcast('192.3.4.5/24::cidr') == 192.3.4.255 > > and perhaps; > > > > class('192.3.4.5/24::cidr') == C > > classnet('192.3.4.5/24::cidr') == 192.3.4 I'll leave these for the moment as I'm not sure what to do with invalid classful addresses such as 192.3.4.5/16. I'll bring it up again after 6.4 is released. > > Can I help code up some of this stuff? > > Yes, we need those. Code them up, and I will add them as standard > types. OK, I started but I could use a small change to inet_net_ntop.c which I think impliments something we discussed anyway. I just need to know if this is going to affect anything else. Basically it allows for the number of bits to be -1 which is interpreted as a host with unspecified netmask. The changes cause all outputs to leave of the netmask part if it is -1. I realize that I will have to change some of the other functions in inet.c but is there anything else that might bite me? If there is no problem I'll resubmit this to the patches list. *** ../src.original/./backend/utils/adt/inet_net_ntop.c Fri Oct 9 17:37:27 1998 --- ./backend/utils/adt/inet_net_ntop.c Fri Oct 9 17:39:05 1998 *************** *** 85,90 **** --- 85,97 ---- char *t; u_int m; int b; + int print_bits = 1; + + if (bits == -1) + { + bits = 32; + print_bits = 0; + } if (bits < 0 || bits > 32) { *************** *** 129,137 **** } /* Format CIDR /width. */ ! if (size < sizeof "/32") ! goto emsgsize; ! dst += SPRINTF((dst, "/%u", bits)); return (odst); emsgsize: --- 136,147 ---- } /* Format CIDR /width. */ ! if (print_bits) ! { ! if (size < sizeof "/32") ! goto emsgsize; ! dst += SPRINTF((dst, "/%u", bits)); ! } return (odst); emsgsize: -- D'Arcy J.M. Cain <darcy@{druid|vex}.net> | Democracy is three wolves http://www.druid.net/darcy/ | and a sheep voting on +1 416 424 2871 (DoD#0082) (eNTP) | what's for dinner.
В списке pgsql-hackers по дате отправления: