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:628
#define SET_VARSIZE(PTR, len)
Definition: postgres.h:343
#define ip_addrsize(inetptr)
Definition: inet.h:80

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 1569 of file network.c.

1570 {
1571  unsigned int lb,
1572  rb;
1573  int x,
1574  b;
1575 
1576  b = n / 8;
1577  x = memcmp(l, r, b);
1578  if (x || (n % 8) == 0)
1579  return x;
1580 
1581  lb = l[b];
1582  rb = r[b];
1583  for (b = n % 8; b > 0; b--)
1584  {
1585  if (IS_HIGHBIT_SET(lb) != IS_HIGHBIT_SET(rb))
1586  {
1587  if (IS_HIGHBIT_SET(lb))
1588  return 1;
1589  return -1;
1590  }
1591  lb <<= 1;
1592  rb <<= 1;
1593  }
1594  return 0;
1595 }
#define IS_HIGHBIT_SET(ch)
Definition: c.h:1094
int b
Definition: isn.c:70
int x
Definition: isn.c:71

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 1603 of file network.c.

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

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 }
Assert(fmt[strlen(fmt) - 1] !='\n')
void * palloc0(Size size)
Definition: mcxt.c:1230
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:660
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:670

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().