#include "postgres.h"
#include "access/hash.h"
#include "libpq/pqformat.h"
#include "utils/builtins.h"
#include "utils/inet.h"
Go to the source code of this file.
Defines | |
#define | hibits(addr) ((unsigned long)(((addr)->a<<16)|((addr)->b<<8)|((addr)->c))) |
#define | lobits(addr) ((unsigned long)(((addr)->d<<16)|((addr)->e<<8)|((addr)->f))) |
Functions | |
Datum | macaddr_in (PG_FUNCTION_ARGS) |
Datum | macaddr_out (PG_FUNCTION_ARGS) |
Datum | macaddr_recv (PG_FUNCTION_ARGS) |
Datum | macaddr_send (PG_FUNCTION_ARGS) |
static int32 | macaddr_cmp_internal (macaddr *a1, macaddr *a2) |
Datum | macaddr_cmp (PG_FUNCTION_ARGS) |
Datum | macaddr_lt (PG_FUNCTION_ARGS) |
Datum | macaddr_le (PG_FUNCTION_ARGS) |
Datum | macaddr_eq (PG_FUNCTION_ARGS) |
Datum | macaddr_ge (PG_FUNCTION_ARGS) |
Datum | macaddr_gt (PG_FUNCTION_ARGS) |
Datum | macaddr_ne (PG_FUNCTION_ARGS) |
Datum | hashmacaddr (PG_FUNCTION_ARGS) |
Datum | macaddr_not (PG_FUNCTION_ARGS) |
Datum | macaddr_and (PG_FUNCTION_ARGS) |
Datum | macaddr_or (PG_FUNCTION_ARGS) |
Datum | macaddr_trunc (PG_FUNCTION_ARGS) |
#define hibits | ( | addr | ) | ((unsigned long)(((addr)->a<<16)|((addr)->b<<8)|((addr)->c))) |
Definition at line 19 of file mac.c.
Referenced by macaddr_cmp_internal().
#define lobits | ( | addr | ) | ((unsigned long)(((addr)->d<<16)|((addr)->e<<8)|((addr)->f))) |
Definition at line 22 of file mac.c.
Referenced by macaddr_cmp_internal().
Datum hashmacaddr | ( | PG_FUNCTION_ARGS | ) |
Definition at line 237 of file mac.c.
References hash_any(), and PG_GETARG_MACADDR_P.
{ macaddr *key = PG_GETARG_MACADDR_P(0); return hash_any((unsigned char *) key, sizeof(macaddr)); }
Datum macaddr_and | ( | PG_FUNCTION_ARGS | ) |
Definition at line 264 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, and PG_RETURN_MACADDR_P.
{ macaddr *addr1 = PG_GETARG_MACADDR_P(0); macaddr *addr2 = PG_GETARG_MACADDR_P(1); macaddr *result; result = (macaddr *) palloc(sizeof(macaddr)); result->a = addr1->a & addr2->a; result->b = addr1->b & addr2->b; result->c = addr1->c & addr2->c; result->d = addr1->d & addr2->d; result->e = addr1->e & addr2->e; result->f = addr1->f & addr2->f; PG_RETURN_MACADDR_P(result); }
Datum macaddr_cmp | ( | PG_FUNCTION_ARGS | ) |
Definition at line 167 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_INT32.
Referenced by gbt_macadkey_cmp().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_INT32(macaddr_cmp_internal(a1, a2)); }
Definition at line 152 of file mac.c.
References hibits, and lobits.
Referenced by macaddr_cmp(), macaddr_eq(), macaddr_ge(), macaddr_gt(), macaddr_le(), macaddr_lt(), and macaddr_ne().
Datum macaddr_eq | ( | PG_FUNCTION_ARGS | ) |
Definition at line 198 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
Referenced by gbt_macadeq().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) == 0); }
Datum macaddr_ge | ( | PG_FUNCTION_ARGS | ) |
Definition at line 207 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
Referenced by gbt_macadge().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) >= 0); }
Datum macaddr_gt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 216 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
Referenced by gbt_macadgt().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) > 0); }
Datum macaddr_in | ( | PG_FUNCTION_ARGS | ) |
Definition at line 30 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, ereport, errcode(), errmsg(), ERROR, macaddr::f, palloc(), PG_GETARG_CSTRING, and PG_RETURN_MACADDR_P.
{ char *str = PG_GETARG_CSTRING(0); macaddr *result; int a, b, c, d, e, f; char junk[2]; int count; /* %1s matches iff there is trailing non-whitespace garbage */ count = sscanf(str, "%x:%x:%x:%x:%x:%x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) count = sscanf(str, "%x-%x-%x-%x-%x-%x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) count = sscanf(str, "%2x%2x%2x:%2x%2x%2x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) count = sscanf(str, "%2x%2x%2x-%2x%2x%2x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) count = sscanf(str, "%2x%2x.%2x%2x.%2x%2x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s", &a, &b, &c, &d, &e, &f, junk); if (count != 6) ereport(ERROR, (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), errmsg("invalid input syntax for type macaddr: \"%s\"", str))); if ((a < 0) || (a > 255) || (b < 0) || (b > 255) || (c < 0) || (c > 255) || (d < 0) || (d > 255) || (e < 0) || (e > 255) || (f < 0) || (f > 255)) ereport(ERROR, (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str))); result = (macaddr *) palloc(sizeof(macaddr)); result->a = a; result->b = b; result->c = c; result->d = d; result->e = e; result->f = f; PG_RETURN_MACADDR_P(result); }
Datum macaddr_le | ( | PG_FUNCTION_ARGS | ) |
Definition at line 189 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
Referenced by gbt_macadle().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) <= 0); }
Datum macaddr_lt | ( | PG_FUNCTION_ARGS | ) |
Definition at line 180 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
Referenced by gbt_macadlt().
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) < 0); }
Datum macaddr_ne | ( | PG_FUNCTION_ARGS | ) |
Definition at line 225 of file mac.c.
References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.
{ macaddr *a1 = PG_GETARG_MACADDR_P(0); macaddr *a2 = PG_GETARG_MACADDR_P(1); PG_RETURN_BOOL(macaddr_cmp_internal(a1, a2) != 0); }
Datum macaddr_not | ( | PG_FUNCTION_ARGS | ) |
Definition at line 248 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, and PG_RETURN_MACADDR_P.
Datum macaddr_or | ( | PG_FUNCTION_ARGS | ) |
Definition at line 281 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, and PG_RETURN_MACADDR_P.
{ macaddr *addr1 = PG_GETARG_MACADDR_P(0); macaddr *addr2 = PG_GETARG_MACADDR_P(1); macaddr *result; result = (macaddr *) palloc(sizeof(macaddr)); result->a = addr1->a | addr2->a; result->b = addr1->b | addr2->b; result->c = addr1->c | addr2->c; result->d = addr1->d | addr2->d; result->e = addr1->e | addr2->e; result->f = addr1->f | addr2->f; PG_RETURN_MACADDR_P(result); }
Datum macaddr_out | ( | PG_FUNCTION_ARGS | ) |
Definition at line 91 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, PG_RETURN_CSTRING, and snprintf().
Datum macaddr_recv | ( | PG_FUNCTION_ARGS | ) |
Definition at line 110 of file mac.c.
References macaddr::a, macaddr::b, buf, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_POINTER, PG_RETURN_MACADDR_P, and pq_getmsgbyte().
{ StringInfo buf = (StringInfo) PG_GETARG_POINTER(0); macaddr *addr; addr = (macaddr *) palloc(sizeof(macaddr)); addr->a = pq_getmsgbyte(buf); addr->b = pq_getmsgbyte(buf); addr->c = pq_getmsgbyte(buf); addr->d = pq_getmsgbyte(buf); addr->e = pq_getmsgbyte(buf); addr->f = pq_getmsgbyte(buf); PG_RETURN_MACADDR_P(addr); }
Datum macaddr_send | ( | PG_FUNCTION_ARGS | ) |
Definition at line 131 of file mac.c.
References macaddr::a, macaddr::b, buf, macaddr::c, macaddr::d, macaddr::e, macaddr::f, PG_GETARG_MACADDR_P, PG_RETURN_BYTEA_P, pq_begintypsend(), pq_endtypsend(), and pq_sendbyte().
{ macaddr *addr = PG_GETARG_MACADDR_P(0); StringInfoData buf; pq_begintypsend(&buf); pq_sendbyte(&buf, addr->a); pq_sendbyte(&buf, addr->b); pq_sendbyte(&buf, addr->c); pq_sendbyte(&buf, addr->d); pq_sendbyte(&buf, addr->e); pq_sendbyte(&buf, addr->f); PG_RETURN_BYTEA_P(pq_endtypsend(&buf)); }
Datum macaddr_trunc | ( | PG_FUNCTION_ARGS | ) |
Definition at line 302 of file mac.c.
References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, and PG_RETURN_MACADDR_P.