Re: New cast between inet/cidr and bytea

From: Zoltan Boszormenyi <zb(at)cybertec(dot)at>
To: Bruce Momjian <bruce(at)momjian(dot)us>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: New cast between inet/cidr and bytea
Date: 2007-05-31 05:31:48
Message-ID: 465E5DC4.9050501@cybertec.at
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-hackers

Bruce Momjian írta:
> Zoltan Boszormenyi wrote:
>
>> Hi,
>>
>> we at Cybertec have developed cast functions in C between
>> inet/cidr <-> bytea for a client and we would like to submit it.
>>
>> This is how it works:
>> - IPv4 inet/cidr value will return 4 bytes if the netmask covers all 32
>> bits.
>> It returns 5 bytes if the netmask is shorter than 32 bits.
>> - Similarly for IPv6, 12[+1] bytes is returned.
>> - 4, 5, 12 or 13 bytes long bytea values are converted
>> to an inet/cidr value, the 5th or 13th byte is range-checked
>> to be a valid netmask value.
>>
>> What are the requirements for it to be accepted
>> as a core cast function or as a contrib module?
>>
>
> You discuss it on the hackers list.

That's what I am trying to.

> Have you read the developer's FAQ?
>

Not yet in its entireness.

> What is the use case for such a cast?
>
e.g.:
# select '192.168.0.1'::inet::bytea;
bytea
------------------
\300\250\000\001
(1 row)

# select '192.168.0.0/24'::inet::bytea;
bytea
----------------------
\300\250\000\000\030
(1 row)

# select decode('\\300\\250\\000\\001', 'escape')::inet;
decode
-------------
192.168.0.1
(1 row)

# select decode('\\300\\250\\000\\000\\030', 'escape')::inet;
decode
----------------
192.168.0.2/24
(1 row)

Similarly for IPv6 addresses.
The application doesn't want to parse the textual IP address
when all the parsing and checking intelligence is already there
in the inet/cidr type checks. The reverse when you pass in bytes
is only a logical extension.

--
----------------------------------
Zoltán Böszörményi
Cybertec Geschwinde & Schönig GmbH
http://www.postgresql.at/

In response to

Responses

Browse pgsql-hackers by date

  From Date Subject
Next Message Zoltan Boszormenyi 2007-05-31 05:50:15 Re: New cast between inet/cidr and bytea
Previous Message Jon Colverson 2007-05-31 04:58:26 Re: Attempt to re-archive existing WAL logs after restoring from backup