Skip to content
Snippets Groups Projects
Select Git revision
  • benchmark-tools
  • postgres-lambda
  • master default
  • REL9_4_25
  • REL9_5_20
  • REL9_6_16
  • REL_10_11
  • REL_11_6
  • REL_12_1
  • REL_12_0
  • REL_12_RC1
  • REL_12_BETA4
  • REL9_4_24
  • REL9_5_19
  • REL9_6_15
  • REL_10_10
  • REL_11_5
  • REL_12_BETA3
  • REL9_4_23
  • REL9_5_18
  • REL9_6_14
  • REL_10_9
  • REL_11_4
23 results

network.c

Blame
  • network.c 29.74 KiB
    /*
     *	PostgreSQL type definitions for the INET and CIDR types.
     *
     *	$PostgreSQL: pgsql/src/backend/utils/adt/network.c,v 1.65 2006/02/11 20:39:58 tgl Exp $
     *
     *	Jon Postel RIP 16 Oct 1998
     */
    
    #include "postgres.h"
    
    #include <sys/socket.h>
    #include <netinet/in.h>
    #include <arpa/inet.h>
    
    #include "access/hash.h"
    #include "catalog/pg_type.h"
    #include "libpq/ip.h"
    #include "libpq/libpq-be.h"
    #include "libpq/pqformat.h"
    #include "miscadmin.h"
    #include "utils/builtins.h"
    #include "utils/inet.h"
    
    
    static inet *text_network(text *src, bool is_cidr);
    static int32 network_cmp_internal(inet *a1, inet *a2);
    static int	bitncmp(void *l, void *r, int n);
    static bool addressOK(unsigned char *a, int bits, int family);
    static int	ip_addrsize(inet *inetptr);
    static inet *internal_inetpl(inet *ip, int64 addend);
    
    /*
     *	Access macros.
     */
    
    #define ip_family(inetptr) \
    	(((inet_struct *)VARDATA(inetptr))->family)
    
    #define ip_bits(inetptr) \
    	(((inet_struct *)VARDATA(inetptr))->bits)
    
    #define ip_addr(inetptr) \
    	(((inet_struct *)VARDATA(inetptr))->ipaddr)
    
    #define ip_maxbits(inetptr) \
    	(ip_family(inetptr) == PGSQL_AF_INET ? 32 : 128)
    
    /*
     * Return the number of bytes of storage needed for this data type.
     */
    static int
    ip_addrsize(inet *inetptr)
    {
    	switch (ip_family(inetptr))
    	{
    		case PGSQL_AF_INET:
    			return 4;
    		case PGSQL_AF_INET6:
    			return 16;
    		default:
    			return 0;
    	}
    }
    
    /*
     * Common INET/CIDR input routine
     */
    static inet *
    network_in(char *src, bool is_cidr)
    {