Re: [HACKERS] Re: inet/cidr/bind

Поиск
Список
Период
Сортировка
От Paul A Vixie
Тема Re: [HACKERS] Re: inet/cidr/bind
Дата
Msg-id 199810131827.LAA08555@bb.rc.vix.com
обсуждение исходный текст
Ответ на Re: [HACKERS] Re: inet/cidr/bind  (darcy@druid.net (D'Arcy J.M. Cain))
Ответы Re: [HACKERS] Re: inet/cidr/bind  (darcy@druid.net (D'Arcy J.M. Cain))
Список pgsql-hackers
> From: darcy@druid.net (D'Arcy J.M. Cain)
> Date: Tue, 13 Oct 1998 12:58:03 -0400 (EDT)
>
> Well, I don't mind filling in the whole structure.  It would simplify
> a few things and we wouldn't need to add a size element to the structure.

ok.

> The network function will output it correctly, I think.
>
> inet_network_with_bits('192.5/16')     => '192.5/16'
> inet_network_with_bits('192.5.5.1/16') => '192.5/16'
> inet_network_with_bits('192.5/24')     => '192.5.0/16'
>
> Does this seem right?

for networks, yes.

> > > Does this mean we need to add a size element to the inet structure?
> > i think so, yes.
>
> Unless we zero-pad, right?

ok.  here's the current proposal.  any further comments?

/*
 * char *
 * inet_cidr_ntop(af, src, bits, dst, size)
 *      convert network address from network to presentation format.
 *      generates "/CIDR" style result unless "bits" is -1.  "src"'s
 *      size is determined from its "af".
 * return:
 *      pointer to dst, or NULL if an error occurred (check errno).
 * note:
 *      192.5.5.1/28 has a nonzero host part, which means it isn't a network
 *      as called for by inet_net_pton() but it can be a host address with
 *      an included netmask.
 * author:
 *      Paul Vixie (ISC), October 1998
 */
char *
inet_cidr_ntop(int af, const void *src, int bits, char *dst, size_t size) {
        switch (af) {
        case AF_INET:
                return (inet_cidr_ntop_ipv4(src, bits, dst, size));
        default:
                errno = EAFNOSUPPORT;
                return (NULL);
        }
}

...

/*
 * int
 * inet_cidr_pton(af, src, dst, *bits)
 *      convert network address from presentation to network format.
 *      accepts hex octets, hex strings, decimal octets, and /CIDR.
 *      "dst" is assumed large enough for its "af".  "bits" is set to the
 *      /CIDR prefix length if one was specified, or -1 otherwise.
 * return:
 *      0 on success, or -1 if some failure occurred (check errno).
 *      ENOENT means it was not a valid network address.
 * note:
 *      192.5.5.1/28 has a nonzero host part, which means it isn't a network
 *      as called for by inet_net_pton() but it can be a host address with
 *      an included netmask.
 * author:
 *      Paul Vixie (ISC), October 1998
 */
int
inet_cidr_pton(int af, const char *src, void *dst, int *bits) {
        switch (af) {
        case AF_INET:
                return (inet_cidr_pton_ipv4(src, dst, bits));
        default:
                errno = EAFNOSUPPORT;
                return (-1);
        }
}

В списке pgsql-hackers по дате отправления:

Предыдущее
От: "Taral"
Дата:
Сообщение: RE: [HACKERS] AW: compilation problem on AIX
Следующее
От: "Thomas G. Lockhart"
Дата:
Сообщение: Re: [HACKERS] dynamic libraries