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

From: Paul A Vixie <paul(at)vix(dot)com>
To: pgsql-hackers(at)hub(dot)org
Subject: Re: [HACKERS] Re: inet/cidr/bind
Date: 1998-10-13 18:27:31
Message-ID: 199810131827.LAA08555@bb.rc.vix.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

> From: darcy(at)druid(dot)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);
}
}

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Thomas G. Lockhart 1998-10-13 18:34:44 Re: [HACKERS] dynamic libraries
Previous Message Taral 1998-10-13 17:36:31 RE: [HACKERS] AW: compilation problem on AIX