| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #ifndef INET_H |
| #define INET_H |
|
|
| #include "fmgr.h" |
|
|
| |
| |
| |
| |
| typedef struct |
| { |
| unsigned char family; |
| unsigned char bits; |
| unsigned char ipaddr[16]; |
| } inet_struct; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define PGSQL_AF_INET (AF_INET + 0) |
| #define PGSQL_AF_INET6 (AF_INET + 1) |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| typedef struct |
| { |
| char vl_len_[4]; |
| inet_struct inet_data; |
| } inet; |
|
|
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| #define ip_family(inetptr) \ |
| (((inet_struct *) VARDATA_ANY(inetptr))->family) |
|
|
| #define ip_bits(inetptr) \ |
| (((inet_struct *) VARDATA_ANY(inetptr))->bits) |
|
|
| #define ip_addr(inetptr) \ |
| (((inet_struct *) VARDATA_ANY(inetptr))->ipaddr) |
|
|
| #define ip_addrsize(inetptr) \ |
| (ip_family(inetptr) == PGSQL_AF_INET ? 4 : 16) |
|
|
| #define ip_maxbits(inetptr) \ |
| (ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128) |
|
|
| #define SET_INET_VARSIZE(dst) \ |
| SET_VARSIZE(dst, VARHDRSZ + offsetof(inet_struct, ipaddr) + \ |
| ip_addrsize(dst)) |
|
|
|
|
| |
| |
| |
| typedef struct macaddr |
| { |
| unsigned char a; |
| unsigned char b; |
| unsigned char c; |
| unsigned char d; |
| unsigned char e; |
| unsigned char f; |
| } macaddr; |
|
|
| |
| |
| |
| typedef struct macaddr8 |
| { |
| unsigned char a; |
| unsigned char b; |
| unsigned char c; |
| unsigned char d; |
| unsigned char e; |
| unsigned char f; |
| unsigned char g; |
| unsigned char h; |
| } macaddr8; |
|
|
| |
| |
| |
| static inline inet * |
| DatumGetInetPP(Datum X) |
| { |
| return (inet *) PG_DETOAST_DATUM_PACKED(X); |
| } |
|
|
| static inline Datum |
| InetPGetDatum(const inet *X) |
| { |
| return PointerGetDatum(X); |
| } |
|
|
| #define PG_GETARG_INET_PP(n) DatumGetInetPP(PG_GETARG_DATUM(n)) |
| #define PG_RETURN_INET_P(x) return InetPGetDatum(x) |
|
|
| |
| static inline inet * |
| DatumGetInetP(Datum X) |
| { |
| return (inet *) PG_DETOAST_DATUM(X); |
| } |
| #define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n)) |
|
|
| |
| static inline macaddr * |
| DatumGetMacaddrP(Datum X) |
| { |
| return (macaddr *) DatumGetPointer(X); |
| } |
|
|
| static inline Datum |
| MacaddrPGetDatum(const macaddr *X) |
| { |
| return PointerGetDatum(X); |
| } |
|
|
| #define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n)) |
| #define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x) |
|
|
| |
| static inline macaddr8 * |
| DatumGetMacaddr8P(Datum X) |
| { |
| return (macaddr8 *) DatumGetPointer(X); |
| } |
|
|
| static inline Datum |
| Macaddr8PGetDatum(const macaddr8 *X) |
| { |
| return PointerGetDatum(X); |
| } |
|
|
| #define PG_GETARG_MACADDR8_P(n) DatumGetMacaddr8P(PG_GETARG_DATUM(n)) |
| #define PG_RETURN_MACADDR8_P(x) return Macaddr8PGetDatum(x) |
|
|
| |
| |
| |
| extern inet *cidr_set_masklen_internal(const inet *src, int bits); |
| extern int bitncmp(const unsigned char *l, const unsigned char *r, int n); |
| extern int bitncommon(const unsigned char *l, const unsigned char *r, int n); |
|
|
| #endif |
|
|