Re: inet/cidr/bind

Поиск
Список
Период
Сортировка
От Paul A Vixie
Тема Re: inet/cidr/bind
Дата
Msg-id 199810130811.BAA01916@bb.rc.vix.com
обсуждение исходный текст
Ответы Re: [HACKERS] Re: inet/cidr/bind
Список pgsql-hackers
> From: darcy@druid.net (D'Arcy J.M. Cain)
> Date: Sun, 11 Oct 1998 07:17:58 -0400 (EDT)
>
> Thus spake Paul A Vixie
> >     int
> >     inet_cidr_pton(af, src, dst, size, int *used)
> >
> > this would work very much the same as inet_net_pton() except for three
> > things: (1) nonzero trailing mantissas (host parts) would be allowed; (2)
> > the number of consumed octets of dst would be set into *used; and (3) there
> > would be absolutely no classful assumptions made if the pfxlen is not
> > specified in the input.
>
> Is there also agreement on the use of -1 to mean unspecified netmask?

ok.  this means we have to return octets and use an argument for *bits.

> How about the optional input form h.h.h.h:m.m.m.m to specify netmask?

i'd rather avoid this, since cidr does not allow noncontiguous netmasks
and i'd rather not create another error return case unless it's REALLY
important.  is it?  as currently specified:

/*
 * static int
 * inet_cidr_pton(af, src, dst, size, *bits)
 *      convert network address from presentation to network format.
 *      accepts hex octets, hex strings, decimal octets, and /CIDR.
 *      "size" is in bytes and describes "dst".  "bits" is set to the
 *      /CIDR prefix length if one was specified, or -1 otherwise.
 * return:
 *      number of octets consumed of "dst", 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_net_pton(int af, const char *src,
              void *dst, size_t size,
              int *bits)
{
        switch (af) {
        case AF_INET:
                return (inet_cidr_pton_ipv4(src, dst, size, bits));
        default:
                errno = EAFNOSUPPORT;
                return (-1);
        }
}

> >     int
> >     inet_cidr_ntop(ag, src, len, bits, dst, size)
> >
> > this would work very much the same as inet_net_ntop() except that the
> > size (in octets) of src's mantissa would be given in the new "len" argument
> > and not imputed from "bits" as occurs now.  "bits" would just be output
> > as the "/NN" at the end of the string, and would never be optional.
>
> And if bits is -1 then don't print the /NN part, right?

ok.  here's what that looks like, for comments before i write it:

/*
 * char *
 * inet_cidr_ntop(af, src, len, bits, dst, size)
 *      convert network address from network to presentation format.
 *      generates "/CIDR" style result unless "bits" is -1.
 * 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, size_t len, int bits,
               char *dst, size_t size)
{
        switch (af) {
        case AF_INET:
                return (inet_cidr_ntop_ipv4(src, len, bits, dst, size));
        default:
                errno = EAFNOSUPPORT;
                return (NULL);
        }
}

> From: darcy@druid.net (D'Arcy J.M. Cain)
> Date: Sun, 11 Oct 1998 07:40:41 -0400 (EDT)
>
> Thus spake Paul A Vixie
> >     int
> >     inet_cidr_pton(af, src, dst, size, int *used)
> >
> > this would work very much the same as inet_net_pton() except for three
> > things: (1) nonzero trailing mantissas (host parts) would be allowed; (2)
> > the number of consumed octets of dst would be set into *used; and (3) there
> > would be absolutely no classful assumptions made if the pfxlen is not
> > specified in the input.
>
> I have another question.  What is the point of "used?"  Can't I just
> assume 4 octets for ipv4 and 6 for ipv6?  Can I set it to NULL if I
> don't care about the value?

we probably could have done this until we had to return octets and fill *used
with the bits.  but more importantly, i think we should still only touch the
octets in *dst that are nec'y.  this is consistent with the _ntop() as well.

> From: darcy@druid.net (D'Arcy J.M. Cain)
> Date: Sun, 11 Oct 1998 20:22:25 -0400 (EDT)
>
> ...  [One] more thing.  I built my stuff on the assumption that the
> inet_cidr_ntop function returned char *, not int.  I assume that was
> just an error in your message.  In fact, here is the way I added the
> prototypes to builtins.h.

Yes.

> char *inet_cidr_ntop(int af, const void *src, size_t len, int bits, char *dst, size_t size);
> int inet_cidr_pton(int af, const void *src, void *dst, size_t size, int *used);
>
> Is this what you had in mind?

Yes.  But note that as now proposed, inet_cidr_pton() returns octets not bits
as earlier proposed, and sets *used to the bits not the octets as earlier
proposed.

If there are no further comments?

(In case y'all are wondering, this is how BIND's other library functions
got specified, though the driving application wasn't PostGreSQL last time.)

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

Предыдущее
От: jwieck@debis.com (Jan Wieck)
Дата:
Сообщение: Re: [HACKERS] dynamic libraries
Следующее
От: jwieck@debis.com (Jan Wieck)
Дата:
Сообщение: Re: [HACKERS] TCL/TK library glitches in configure.in