1 /*-------------------------------------------------------------------------
4 * Declarations for operations on INET datatypes.
7 * Portions Copyright (c) 1996-2008, PostgreSQL Global Development Group
8 * Portions Copyright (c) 1994, Regents of the University of California
12 *-------------------------------------------------------------------------
20 * This is the internal storage format for IP addresses
21 * (both INET and CIDR datatypes):
25 unsigned char family
; /* PGSQL_AF_INET or PGSQL_AF_INET6 */
26 unsigned char bits
; /* number of bits in netmask */
27 unsigned char ipaddr
[16]; /* up to 128 bits of address */
31 * Referencing all of the non-AF_INET types to AF_INET lets us work on
32 * machines which may not have the appropriate address family (like
33 * inet6 addresses when AF_INET6 isn't present) but doesn't cause a
34 * dump/reload requirement. Existing databases used AF_INET for the family
37 #define PGSQL_AF_INET (AF_INET + 0)
38 #define PGSQL_AF_INET6 (AF_INET + 1)
41 * Both INET and CIDR addresses are represented within Postgres as varlena
42 * objects, ie, there is a varlena header in front of the struct type
43 * depicted above. This struct depicts what we actually have in memory
44 * in "uncompressed" cases. Note that since the maximum data size is only
45 * 18 bytes, INET/CIDR will invariably be stored into tuples using the
46 * 1-byte-header varlena format. However, we have to be prepared to cope
47 * with the 4-byte-header format too, because various code may helpfully
48 * try to "decompress" 1-byte-header datums.
52 char vl_len_
[4]; /* Do not touch this field directly! */
53 inet_struct inet_data
;
58 * This is the internal storage format for MAC addresses:
60 typedef struct macaddr
71 * fmgr interface macros
73 #define DatumGetInetP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X))
74 #define InetPGetDatum(X) PointerGetDatum(X)
75 #define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n))
76 #define PG_RETURN_INET_P(x) return InetPGetDatum(x)
77 /* macaddr is a fixed-length pass-by-reference datatype */
78 #define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X))
79 #define MacaddrPGetDatum(X) PointerGetDatum(X)
80 #define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n))
81 #define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x)