Il sourcecode per i tipi di dati IP mostrarlo:
typedef struct
{
unsigned char family; /* PGSQL_AF_INET or PGSQL_AF_INET6 */
unsigned char bits; /* number of bits in netmask */
unsigned char ipaddr[16]; /* up to 128 bits of address */
} inet_struct;
Ciò significa, che in aggiunta ai dati "grezzi" a ipaddr
(4 byte per IP4, 16 byte per IP6) c'è un byte per la maschera di rete e un byte per la famiglia di indirizzi (fondamentalmente un interruttore per IP4/IP6).
Inoltre v'è la varlena
spese generali di cui si parla nello stesso file:
/*
* Both INET and CIDR addresses are represented within Postgres as varlena
* objects, ie, there is a varlena header in front of the struct type
* depicted above. This struct depicts what we actually have in memory
* in "uncompressed" cases. Note that since the maximum data size is only
* 18 bytes, INET/CIDR will invariably be stored into tuples using the
* 1-byte-header varlena format. However, we have to be prepared to cope
* with the 4-byte-header format too, because various code may helpfully
* try to "decompress" 1-byte-header datums.
*/
typedef struct
{
char vl_len_[4]; /* Do not touch this field directly! */
inet_struct inet_data;
} inet;
Quindi l'equazione per IP4 è questo:
1 byte varlena
1 byte address family
1 byte netmask
4 raw bytes
===========
7 byte total
Per IP6 la stessa formula ti dà 19 byte.
EDIT Le versioni precedenti di PostgreSQL avevano solo una rappresentazione di varlena di 4 byte. Pertanto è possibile aggiungere 3 byte per ogni tipo (IP4: 10, IP6: 22). Inoltre, c'era un padding fino al prossimo bordo da 4 byte. Questo ti dà 2 byte per ogni tipo aggiungendo fino a 12 o 24 byte.
This mail getta luce sullo sviluppo della versione più corta.
fonte
2012-07-18 19:18:57
Ha bisogno di almeno +1 byte per i bit maschera di rete, ad esempio "10.1.0.0/8" è valido per la maschera 10.1.0.0 255.0.0.0 –