~ubuntu-branches/ubuntu/hardy/postgresql-8.4/hardy-backports

« back to all changes in this revision

Viewing changes to src/include/utils/inet.h

  • Committer: Bazaar Package Importer
  • Author(s): Martin Pitt
  • Date: 2009-03-20 12:00:13 UTC
  • Revision ID: james.westby@ubuntu.com-20090320120013-hogj7egc5mjncc5g
Tags: upstream-8.4~0cvs20090328
ImportĀ upstreamĀ versionĀ 8.4~0cvs20090328

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*-------------------------------------------------------------------------
 
2
 *
 
3
 * inet.h
 
4
 *        Declarations for operations on INET datatypes.
 
5
 *
 
6
 *
 
7
 * Portions Copyright (c) 1996-2009, PostgreSQL Global Development Group
 
8
 * Portions Copyright (c) 1994, Regents of the University of California
 
9
 *
 
10
 * $PostgreSQL$
 
11
 *
 
12
 *-------------------------------------------------------------------------
 
13
 */
 
14
#ifndef INET_H
 
15
#define INET_H
 
16
 
 
17
#include "fmgr.h"
 
18
 
 
19
/*
 
20
 *      This is the internal storage format for IP addresses
 
21
 *      (both INET and CIDR datatypes):
 
22
 */
 
23
typedef struct
 
24
{
 
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 */
 
28
} inet_struct;
 
29
 
 
30
/*
 
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
 
35
 * type on disk.
 
36
 */
 
37
#define PGSQL_AF_INET   (AF_INET + 0)
 
38
#define PGSQL_AF_INET6  (AF_INET + 1)
 
39
 
 
40
/*
 
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.
 
49
 */
 
50
typedef struct
 
51
{
 
52
        char            vl_len_[4];             /* Do not touch this field directly! */
 
53
        inet_struct inet_data;
 
54
} inet;
 
55
 
 
56
 
 
57
/*
 
58
 *      This is the internal storage format for MAC addresses:
 
59
 */
 
60
typedef struct macaddr
 
61
{
 
62
        unsigned char a;
 
63
        unsigned char b;
 
64
        unsigned char c;
 
65
        unsigned char d;
 
66
        unsigned char e;
 
67
        unsigned char f;
 
68
} macaddr;
 
69
 
 
70
/*
 
71
 * fmgr interface macros
 
72
 */
 
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)
 
82
 
 
83
#endif   /* INET_H */