1998-10-03 07:41:01 +02:00
|
|
|
/*-------------------------------------------------------------------------
|
|
|
|
*
|
2000-07-06 07:48:31 +02:00
|
|
|
* inet.h
|
|
|
|
* Declarations for operations on INET datatypes.
|
1998-10-03 07:41:01 +02:00
|
|
|
*
|
|
|
|
*
|
2009-01-01 18:24:05 +01:00
|
|
|
* Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
|
2000-01-26 06:58:53 +01:00
|
|
|
* Portions Copyright (c) 1994, Regents of the University of California
|
1998-10-03 07:41:01 +02:00
|
|
|
*
|
2009-01-01 18:24:05 +01:00
|
|
|
* $PostgreSQL: pgsql/src/include/utils/inet.h,v 1.30 2009/01/01 17:24:02 momjian Exp $
|
1998-10-03 07:41:01 +02:00
|
|
|
*
|
|
|
|
*-------------------------------------------------------------------------
|
|
|
|
*/
|
2000-08-04 01:07:51 +02:00
|
|
|
#ifndef INET_H
|
|
|
|
#define INET_H
|
1998-10-03 07:41:01 +02:00
|
|
|
|
2006-07-11 15:54:25 +02:00
|
|
|
#include "fmgr.h"
|
|
|
|
|
1998-10-03 07:41:01 +02:00
|
|
|
/*
|
2000-08-04 01:07:51 +02:00
|
|
|
* This is the internal storage format for IP addresses
|
|
|
|
* (both INET and CIDR datatypes):
|
1998-10-03 07:41:01 +02:00
|
|
|
*/
|
|
|
|
typedef struct
|
|
|
|
{
|
2004-06-13 23:57:28 +02:00
|
|
|
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 */
|
1999-05-26 00:43:53 +02:00
|
|
|
} inet_struct;
|
1998-10-03 07:41:01 +02:00
|
|
|
|
2003-06-25 00:21:24 +02:00
|
|
|
/*
|
|
|
|
* Referencing all of the non-AF_INET types to AF_INET lets us work on
|
|
|
|
* machines which may not have the appropriate address family (like
|
|
|
|
* inet6 addresses when AF_INET6 isn't present) but doesn't cause a
|
|
|
|
* dump/reload requirement. Existing databases used AF_INET for the family
|
|
|
|
* type on disk.
|
|
|
|
*/
|
|
|
|
#define PGSQL_AF_INET (AF_INET + 0)
|
|
|
|
#define PGSQL_AF_INET6 (AF_INET + 1)
|
|
|
|
|
2000-08-04 01:07:51 +02:00
|
|
|
/*
|
|
|
|
* Both INET and CIDR addresses are represented within Postgres as varlena
|
2007-04-06 06:21:44 +02:00
|
|
|
* objects, ie, there is a varlena header in front of the struct type
|
2007-11-15 22:14:46 +01:00
|
|
|
* depicted above. This struct depicts what we actually have in memory
|
2007-04-06 06:21:44 +02:00
|
|
|
* 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.
|
2000-08-04 01:07:51 +02:00
|
|
|
*/
|
2007-04-06 06:21:44 +02:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-02-23 20:11:45 +01:00
|
|
|
char vl_len_[4]; /* Do not touch this field directly! */
|
2007-11-15 22:14:46 +01:00
|
|
|
inet_struct inet_data;
|
2007-04-06 06:21:44 +02:00
|
|
|
} inet;
|
1998-10-03 07:41:01 +02:00
|
|
|
|
2000-08-04 01:07:51 +02:00
|
|
|
|
1998-10-03 07:41:01 +02:00
|
|
|
/*
|
|
|
|
* This is the internal storage format for MAC addresses:
|
|
|
|
*/
|
|
|
|
typedef struct macaddr
|
|
|
|
{
|
|
|
|
unsigned char a;
|
|
|
|
unsigned char b;
|
|
|
|
unsigned char c;
|
|
|
|
unsigned char d;
|
|
|
|
unsigned char e;
|
|
|
|
unsigned char f;
|
1999-05-25 18:15:34 +02:00
|
|
|
} macaddr;
|
1998-10-03 07:41:01 +02:00
|
|
|
|
2000-08-04 01:07:51 +02:00
|
|
|
/*
|
|
|
|
* fmgr interface macros
|
|
|
|
*/
|
2007-04-06 06:21:44 +02:00
|
|
|
#define DatumGetInetP(X) ((inet *) PG_DETOAST_DATUM_PACKED(X))
|
2001-03-22 05:01:46 +01:00
|
|
|
#define InetPGetDatum(X) PointerGetDatum(X)
|
2000-08-04 01:07:51 +02:00
|
|
|
#define PG_GETARG_INET_P(n) DatumGetInetP(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_RETURN_INET_P(x) return InetPGetDatum(x)
|
|
|
|
/* macaddr is a fixed-length pass-by-reference datatype */
|
|
|
|
#define DatumGetMacaddrP(X) ((macaddr *) DatumGetPointer(X))
|
|
|
|
#define MacaddrPGetDatum(X) PointerGetDatum(X)
|
|
|
|
#define PG_GETARG_MACADDR_P(n) DatumGetMacaddrP(PG_GETARG_DATUM(n))
|
|
|
|
#define PG_RETURN_MACADDR_P(x) return MacaddrPGetDatum(x)
|
|
|
|
|
2001-11-05 18:46:40 +01:00
|
|
|
#endif /* INET_H */
|