PostgreSQL Source Code git master
inet.h File Reference
#include "fmgr.h"
Include dependency graph for inet.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  inet_struct
 
struct  inet
 
struct  macaddr
 
struct  macaddr8
 

Macros

#define PGSQL_AF_INET   (AF_INET + 0)
 
#define PGSQL_AF_INET6   (AF_INET + 1)
 
#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)
 
#define PG_GETARG_INET_PP(n)   DatumGetInetPP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_INET_P(x)   return InetPGetDatum(x)
 
#define PG_GETARG_INET_P(n)   DatumGetInetP(PG_GETARG_DATUM(n))
 
#define PG_GETARG_MACADDR_P(n)   DatumGetMacaddrP(PG_GETARG_DATUM(n))
 
#define PG_RETURN_MACADDR_P(x)   return MacaddrPGetDatum(x)
 
#define PG_GETARG_MACADDR8_P(n)   DatumGetMacaddr8P(PG_GETARG_DATUM(n))
 
#define PG_RETURN_MACADDR8_P(x)   return Macaddr8PGetDatum(x)
 

Typedefs

typedef struct macaddr macaddr
 
typedef struct macaddr8 macaddr8
 

Functions

static inetDatumGetInetPP (Datum X)
 
static Datum InetPGetDatum (const inet *X)
 
static inetDatumGetInetP (Datum X)
 
static macaddrDatumGetMacaddrP (Datum X)
 
static Datum MacaddrPGetDatum (const macaddr *X)
 
static macaddr8DatumGetMacaddr8P (Datum X)
 
static Datum Macaddr8PGetDatum (const macaddr8 *X)
 
inetcidr_set_masklen_internal (const inet *src, int bits)
 
int bitncmp (const unsigned char *l, const unsigned char *r, int n)
 
int bitncommon (const unsigned char *l, const unsigned char *r, int n)
 

Macro Definition Documentation

◆ ip_addr

#define ip_addr (   inetptr)     (((inet_struct *) VARDATA_ANY(inetptr))->ipaddr)

Definition at line 77 of file inet.h.

◆ ip_addrsize

#define ip_addrsize (   inetptr)     (ip_family(inetptr) == PGSQL_AF_INET ? 4 : 16)

Definition at line 80 of file inet.h.

◆ ip_bits

#define ip_bits (   inetptr)     (((inet_struct *) VARDATA_ANY(inetptr))->bits)

Definition at line 74 of file inet.h.

◆ ip_family

#define ip_family (   inetptr)     (((inet_struct *) VARDATA_ANY(inetptr))->family)

Definition at line 71 of file inet.h.

◆ ip_maxbits

#define ip_maxbits (   inetptr)     (ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)

Definition at line 83 of file inet.h.

◆ PG_GETARG_INET_P

#define PG_GETARG_INET_P (   n)    DatumGetInetP(PG_GETARG_DATUM(n))

Definition at line 143 of file inet.h.

◆ PG_GETARG_INET_PP

#define PG_GETARG_INET_PP (   n)    DatumGetInetPP(PG_GETARG_DATUM(n))

Definition at line 134 of file inet.h.

◆ PG_GETARG_MACADDR8_P

#define PG_GETARG_MACADDR8_P (   n)    DatumGetMacaddr8P(PG_GETARG_DATUM(n))

Definition at line 174 of file inet.h.

◆ PG_GETARG_MACADDR_P

#define PG_GETARG_MACADDR_P (   n)    DatumGetMacaddrP(PG_GETARG_DATUM(n))

Definition at line 158 of file inet.h.

◆ PG_RETURN_INET_P

#define PG_RETURN_INET_P (   x)    return InetPGetDatum(x)

Definition at line 135 of file inet.h.

◆ PG_RETURN_MACADDR8_P

#define PG_RETURN_MACADDR8_P (   x)    return Macaddr8PGetDatum(x)

Definition at line 175 of file inet.h.

◆ PG_RETURN_MACADDR_P

#define PG_RETURN_MACADDR_P (   x)    return MacaddrPGetDatum(x)

Definition at line 159 of file inet.h.

◆ PGSQL_AF_INET

#define PGSQL_AF_INET   (AF_INET + 0)

Definition at line 39 of file inet.h.

◆ PGSQL_AF_INET6

#define PGSQL_AF_INET6   (AF_INET + 1)

Definition at line 40 of file inet.h.

◆ SET_INET_VARSIZE

#define SET_INET_VARSIZE (   dst)
Value:
SET_VARSIZE(dst, VARHDRSZ + offsetof(inet_struct, ipaddr) + \
#define VARHDRSZ
Definition: c.h:649
#define ip_addrsize(inetptr)
Definition: inet.h:80
#define SET_VARSIZE(PTR, len)
Definition: varatt.h:305

Definition at line 86 of file inet.h.

Typedef Documentation

◆ macaddr

typedef struct macaddr macaddr

◆ macaddr8

typedef struct macaddr8 macaddr8

Function Documentation

◆ bitncmp()

int bitncmp ( const unsigned char *  l,
const unsigned char *  r,
int  n 
)

Definition at line 1563 of file network.c.

1564{
1565 unsigned int lb,
1566 rb;
1567 int x,
1568 b;
1569
1570 b = n / 8;
1571 x = memcmp(l, r, b);
1572 if (x || (n % 8) == 0)
1573 return x;
1574
1575 lb = l[b];
1576 rb = r[b];
1577 for (b = n % 8; b > 0; b--)
1578 {
1579 if (IS_HIGHBIT_SET(lb) != IS_HIGHBIT_SET(rb))
1580 {
1581 if (IS_HIGHBIT_SET(lb))
1582 return 1;
1583 return -1;
1584 }
1585 lb <<= 1;
1586 rb <<= 1;
1587 }
1588 return 0;
1589}
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1112
int b
Definition: isn.c:69
int x
Definition: isn.c:70

References b, IS_HIGHBIT_SET, and x.

Referenced by inet_gist_consistent(), inet_inclusion_cmp(), inet_spg_choose(), inet_spg_consistent_bitmap(), network_cmp_internal(), network_overlap(), network_sub(), network_subeq(), network_sup(), and network_supeq().

◆ bitncommon()

int bitncommon ( const unsigned char *  l,
const unsigned char *  r,
int  n 
)

Definition at line 1597 of file network.c.

1598{
1599 int byte,
1600 nbits;
1601
1602 /* number of bits to examine in last byte */
1603 nbits = n % 8;
1604
1605 /* check whole bytes */
1606 for (byte = 0; byte < n / 8; byte++)
1607 {
1608 if (l[byte] != r[byte])
1609 {
1610 /* at least one bit in the last byte is not common */
1611 nbits = 7;
1612 break;
1613 }
1614 }
1615
1616 /* check bits in last partial byte */
1617 if (nbits != 0)
1618 {
1619 /* calculate diff of first non-matching bytes */
1620 unsigned int diff = l[byte] ^ r[byte];
1621
1622 /* compare the bits from the most to the least */
1623 while ((diff >> (8 - nbits)) != 0)
1624 nbits--;
1625 }
1626
1627 return (8 * byte) + nbits;
1628}

Referenced by calc_inet_union_params(), calc_inet_union_params_indexed(), inet_gist_penalty(), inet_hist_match_divider(), inet_merge(), inet_spg_choose(), and inet_spg_picksplit().

◆ cidr_set_masklen_internal()

inet * cidr_set_masklen_internal ( const inet src,
int  bits 
)

Definition at line 368 of file network.c.

369{
370 inet *dst = (inet *) palloc0(sizeof(inet));
371
372 ip_family(dst) = ip_family(src);
373 ip_bits(dst) = bits;
374
375 if (bits > 0)
376 {
377 Assert(bits <= ip_maxbits(dst));
378
379 /* Clone appropriate bytes of the address, leaving the rest 0 */
380 memcpy(ip_addr(dst), ip_addr(src), (bits + 7) / 8);
381
382 /* Clear any unwanted bits in the last partial byte */
383 if (bits % 8)
384 ip_addr(dst)[bits / 8] &= ~(0xFF >> (bits % 8));
385 }
386
387 /* Set varlena header correctly */
388 SET_INET_VARSIZE(dst);
389
390 return dst;
391}
#define Assert(condition)
Definition: c.h:815
void * palloc0(Size size)
Definition: mcxt.c:1347
Definition: inet.h:53
#define ip_addr(inetptr)
Definition: inet.h:77
#define SET_INET_VARSIZE(dst)
Definition: inet.h:86
#define ip_family(inetptr)
Definition: inet.h:71
#define ip_maxbits(inetptr)
Definition: inet.h:83
#define ip_bits(inetptr)
Definition: inet.h:74

References Assert, ip_addr, ip_bits, ip_family, ip_maxbits, palloc0(), and SET_INET_VARSIZE.

Referenced by cidr_set_masklen(), inet_merge(), inet_spg_choose(), inet_spg_picksplit(), and inet_to_cidr().

◆ DatumGetInetP()

static inet * DatumGetInetP ( Datum  X)
inlinestatic

Definition at line 139 of file inet.h.

140{
141 return (inet *) PG_DETOAST_DATUM(X);
142}
#define PG_DETOAST_DATUM(datum)
Definition: fmgr.h:240

References PG_DETOAST_DATUM.

◆ DatumGetInetPP()

◆ DatumGetMacaddr8P()

static macaddr8 * DatumGetMacaddr8P ( Datum  X)
inlinestatic

Definition at line 163 of file inet.h.

164{
165 return (macaddr8 *) DatumGetPointer(X);
166}
static Pointer DatumGetPointer(Datum X)
Definition: postgres.h:317
Definition: inet.h:108

References DatumGetPointer().

Referenced by convert_network_to_scalar().

◆ DatumGetMacaddrP()

static macaddr * DatumGetMacaddrP ( Datum  X)
inlinestatic

Definition at line 147 of file inet.h.

148{
149 return (macaddr *) DatumGetPointer(X);
150}
Definition: inet.h:95

References DatumGetPointer().

Referenced by convert_network_to_scalar(), macaddr_abbrev_convert(), and macaddr_fast_cmp().

◆ InetPGetDatum()

static Datum InetPGetDatum ( const inet X)
inlinestatic

Definition at line 129 of file inet.h.

130{
131 return PointerGetDatum(X);
132}
static Datum PointerGetDatum(const void *X)
Definition: postgres.h:327

References PointerGetDatum().

Referenced by inet_gist_fetch(), inet_spg_choose(), inet_spg_leaf_consistent(), and inet_spg_picksplit().

◆ Macaddr8PGetDatum()

static Datum Macaddr8PGetDatum ( const macaddr8 X)
inlinestatic

Definition at line 169 of file inet.h.

170{
171 return PointerGetDatum(X);
172}

References PointerGetDatum().

Referenced by gbt_macad8key_cmp(), and leftmostvalue_macaddr8().

◆ MacaddrPGetDatum()

static Datum MacaddrPGetDatum ( const macaddr X)
inlinestatic

Definition at line 153 of file inet.h.

154{
155 return PointerGetDatum(X);
156}

References PointerGetDatum().

Referenced by gbt_macadkey_cmp(), and leftmostvalue_macaddr().