00001 /*------------------------------------------------------------------------- 00002 * 00003 * inet.h 00004 * Declarations for operations on INET datatypes. 00005 * 00006 * 00007 * Portions Copyright (c) 1996-2013, PostgreSQL Global Development Group 00008 * Portions Copyright (c) 1994, Regents of the University of California 00009 * 00010 * src/include/utils/inet.h 00011 * 00012 *------------------------------------------------------------------------- 00013 */ 00014 #ifndef INET_H 00015 #define INET_H 00016 00017 #include "fmgr.h" 00018 00019 /* 00020 * This is the internal storage format for IP addresses 00021 * (both INET and CIDR datatypes): 00022 */ 00023 typedef struct 00024 { 00025 unsigned char family; /* PGSQL_AF_INET or PGSQL_AF_INET6 */ 00026 unsigned char bits; /* number of bits in netmask */ 00027 unsigned char ipaddr[16]; /* up to 128 bits of address */ 00028 } inet_struct; 00029 00030 /* 00031 * Referencing all of the non-AF_INET types to AF_INET lets us work on 00032 * machines which may not have the appropriate address family (like 00033 * inet6 addresses when AF_INET6 isn't present) but doesn't cause a 00034 * dump/reload requirement. Existing databases used AF_INET for the family 00035 * type on disk. 00036 */ 00037 #define PGSQL_AF_INET (AF_INET + 0) 00038 #define PGSQL_AF_INET6 (AF_INET + 1) 00039 00040 /* 00041 * Both INET and CIDR addresses are represented within Postgres as varlena 00042 * objects, ie, there is a varlena header in front of the struct type 00043 * depicted above. This struct depicts what we actually have in memory 00044 * in "uncompressed" cases. Note that since the maximum data size is only 00045 * 18 bytes, INET/CIDR will invariably be stored into tuples using the 00046 * 1-byte-header varlena format. However, we have to be prepared to cope 00047 * with the 4-byte-header format too, because various code may helpfully 00048 * try to "decompress" 1-byte-header datums. 00049 */ 00050 typedef struct 00051 { 00052 char vl_len_[4]; /* Do not touch this field directly! */ 00053 inet_struct inet_data; 00054 } inet; 00055 00056 00057 /* 00058 * This is the internal storage format for MAC addresses: 00059 */ 00060 typedef struct macaddr 00061 { 00062 unsigned char a; 00063 unsigned char b; 00064 unsigned char c; 00065 unsigned char d; 00066 unsigned char e; 00067 unsigned char f; 00068 } macaddr; 00069 00070 /* 00071 * fmgr interface macros 00072 */ 00073 #define DatumGetInetP(X) ((inet *) PG_DETOAST_DATUM(X)) 00074 #define DatumGetInetPP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X)) 00075 #define InetPGetDatum(X) PointerGetDatum(X) 00076 #define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) 00077 #define PG_GETARG_INET_PP(n) DatumGetInetPP(PG_GETARG_DATUM(n)) 00078 #define PG_RETURN_INET_P(x) return InetPGetDatum(x) 00079 /* macaddr is a fixed-length pass-by-reference datatype */ 00080 #define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X)) 00081 #define MacaddrPGetDatum(X) PointerGetDatum(X) 00082 #define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n)) 00083 #define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x) 00084 00085 #endif /* INET_H */