PostgreSQL Source Code git master
Loading...
Searching...
No Matches
mac.c File Reference
#include "postgres.h"
#include "common/hashfn.h"
#include "libpq/pqformat.h"
#include "port/pg_bswap.h"
#include "utils/fmgrprotos.h"
#include "utils/inet.h"
#include "utils/sortsupport.h"
Include dependency graph for mac.c:

Go to the source code of this file.

Macros

#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

static int macaddr_cmp_internal (macaddr *a1, macaddr *a2)
 
static int macaddr_fast_cmp (Datum x, Datum y, SortSupport ssup)
 
static bool macaddr_abbrev_abort (int memtupcount, SortSupport ssup)
 
static Datum macaddr_abbrev_convert (Datum original, SortSupport ssup)
 
Datum macaddr_in (PG_FUNCTION_ARGS)
 
Datum macaddr_out (PG_FUNCTION_ARGS)
 
Datum macaddr_recv (PG_FUNCTION_ARGS)
 
Datum macaddr_send (PG_FUNCTION_ARGS)
 
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 hashmacaddrextended (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)
 
Datum macaddr_sortsupport (PG_FUNCTION_ARGS)
 

Macro Definition Documentation

◆ hibits

#define hibits (   addr)     ((unsigned long)(((addr)->a<<16)|((addr)->b<<8)|((addr)->c)))

Definition at line 28 of file mac.c.

44{
45 char *str = PG_GETARG_CSTRING(0);
46 Node *escontext = fcinfo->context;
48 int a,
49 b,
50 c,
51 d,
52 e,
53 f;
54 char junk[2];
55 int count;
56
57 /* %1s matches iff there is trailing non-whitespace garbage */
58
59 count = sscanf(str, "%x:%x:%x:%x:%x:%x%1s",
60 &a, &b, &c, &d, &e, &f, junk);
61 if (count != 6)
62 count = sscanf(str, "%x-%x-%x-%x-%x-%x%1s",
63 &a, &b, &c, &d, &e, &f, junk);
64 if (count != 6)
65 count = sscanf(str, "%2x%2x%2x:%2x%2x%2x%1s",
66 &a, &b, &c, &d, &e, &f, junk);
67 if (count != 6)
68 count = sscanf(str, "%2x%2x%2x-%2x%2x%2x%1s",
69 &a, &b, &c, &d, &e, &f, junk);
70 if (count != 6)
71 count = sscanf(str, "%2x%2x.%2x%2x.%2x%2x%1s",
72 &a, &b, &c, &d, &e, &f, junk);
73 if (count != 6)
74 count = sscanf(str, "%2x%2x-%2x%2x-%2x%2x%1s",
75 &a, &b, &c, &d, &e, &f, junk);
76 if (count != 6)
77 count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
78 &a, &b, &c, &d, &e, &f, junk);
79 if (count != 6)
80 ereturn(escontext, (Datum) 0,
82 errmsg("invalid input syntax for type %s: \"%s\"", "macaddr",
83 str)));
84
85 if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
86 (c < 0) || (c > 255) || (d < 0) || (d > 255) ||
87 (e < 0) || (e > 255) || (f < 0) || (f > 255))
88 ereturn(escontext, (Datum) 0,
90 errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str)));
91
93
94 result->a = a;
95 result->b = b;
96 result->c = c;
97 result->d = d;
98 result->e = e;
99 result->f = f;
100
102}
103
104/*
105 * MAC address output function. Fixed format.
106 */
107
108Datum
110{
111 macaddr *addr = PG_GETARG_MACADDR_P(0);
112 char *result;
113
114 result = (char *) palloc(32);
115
116 snprintf(result, 32, "%02x:%02x:%02x:%02x:%02x:%02x",
117 addr->a, addr->b, addr->c, addr->d, addr->e, addr->f);
118
120}
121
122/*
123 * macaddr_recv - converts external binary format to macaddr
124 *
125 * The external representation is just the six bytes, MSB first.
126 */
127Datum
129{
131 macaddr *addr;
132
133 addr = palloc_object(macaddr);
134
135 addr->a = pq_getmsgbyte(buf);
136 addr->b = pq_getmsgbyte(buf);
137 addr->c = pq_getmsgbyte(buf);
138 addr->d = pq_getmsgbyte(buf);
139 addr->e = pq_getmsgbyte(buf);
140 addr->f = pq_getmsgbyte(buf);
141
143}
144
145/*
146 * macaddr_send - converts macaddr to binary format
147 */
148Datum
150{
151 macaddr *addr = PG_GETARG_MACADDR_P(0);
153
155 pq_sendbyte(&buf, addr->a);
156 pq_sendbyte(&buf, addr->b);
157 pq_sendbyte(&buf, addr->c);
158 pq_sendbyte(&buf, addr->d);
159 pq_sendbyte(&buf, addr->e);
160 pq_sendbyte(&buf, addr->f);
162}
163
164
165/*
166 * Comparison function for sorting:
167 */
168
169static int
171{
172 if (hibits(a1) < hibits(a2))
173 return -1;
174 else if (hibits(a1) > hibits(a2))
175 return 1;
176 else if (lobits(a1) < lobits(a2))
177 return -1;
178 else if (lobits(a1) > lobits(a2))
179 return 1;
180 else
181 return 0;
182}
183
184Datum
186{
189
191}
192
193/*
194 * Boolean comparisons.
195 */
196
197Datum
199{
202
204}
205
206Datum
208{
211
213}
214
215Datum
217{
220
222}
223
224Datum
226{
229
231}
232
233Datum
235{
238
240}
241
242Datum
244{
247
249}
250
251/*
252 * Support function for hash indexes on macaddr.
253 */
254Datum
256{
258
259 return hash_any((unsigned char *) key, sizeof(macaddr));
260}
261
262Datum
264{
266
267 return hash_any_extended((unsigned char *) key, sizeof(macaddr),
268 PG_GETARG_INT64(1));
269}
270
271/*
272 * Arithmetic functions: bitwise NOT, AND, OR.
273 */
274Datum
276{
277 macaddr *addr = PG_GETARG_MACADDR_P(0);
279
281 result->a = ~addr->a;
282 result->b = ~addr->b;
283 result->c = ~addr->c;
284 result->d = ~addr->d;
285 result->e = ~addr->e;
286 result->f = ~addr->f;
288}
289
290Datum
292{
296
298 result->a = addr1->a & addr2->a;
299 result->b = addr1->b & addr2->b;
300 result->c = addr1->c & addr2->c;
301 result->d = addr1->d & addr2->d;
302 result->e = addr1->e & addr2->e;
303 result->f = addr1->f & addr2->f;
305}
306
307Datum
309{
313
315 result->a = addr1->a | addr2->a;
316 result->b = addr1->b | addr2->b;
317 result->c = addr1->c | addr2->c;
318 result->d = addr1->d | addr2->d;
319 result->e = addr1->e | addr2->e;
320 result->f = addr1->f | addr2->f;
322}
323
324/*
325 * Truncation function to allow comparing mac manufacturers.
326 * From suggestion by Alex Pilosov <alex@pilosoft.com>
327 */
328Datum
330{
331 macaddr *addr = PG_GETARG_MACADDR_P(0);
333
335
336 result->a = addr->a;
337 result->b = addr->b;
338 result->c = addr->c;
339 result->d = 0;
340 result->e = 0;
341 result->f = 0;
342
344}
345
346/*
347 * SortSupport strategy function. Populates a SortSupport struct with the
348 * information necessary to use comparison by abbreviated keys.
349 */
350Datum
352{
354
356 ssup->ssup_extra = NULL;
357
358 if (ssup->abbreviate)
359 {
364 }
365
367}
368
369/*
370 * SortSupport "traditional" comparison function. Pulls two MAC addresses from
371 * the heap and runs a standard comparison on them.
372 */
373static int
375{
378
380}
381
382/*
383 * Abbreviation is never aborted for macaddr because the 6-byte MAC address
384 * fits entirely within a 64-bit Datum, making the abbreviated key
385 * authoritative.
386 */
387static bool
388macaddr_abbrev_abort(int memtupcount, SortSupport ssup)
389{
390 return false;
391}
392
393/*
394 * SortSupport conversion routine. Converts original macaddr representation
395 * to abbreviated key representation.
396 *
397 * Packs the bytes of a 6-byte MAC address into a Datum and treats it as an
398 * unsigned integer for purposes of comparison. There will be two zeroed bytes
399 * of padding. The integer is converted to native endianness to facilitate
400 * easy comparison.
401 */
402static Datum
404{
406 Datum res;
407
408 /*
409 * Zero out the 8-byte Datum and copy in the 6 bytes of the MAC address.
410 * There will be two bytes of zero padding on the end of the least
411 * significant bits.
412 */
413 StaticAssertDecl(sizeof(res) >= sizeof(macaddr),
414 "Datum is too small for macaddr");
415 memset(&res, 0, sizeof(res));
416 memcpy(&res, authoritative, sizeof(macaddr));
417
418 /*
419 * Byteswap on little-endian machines.
420 *
421 * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer
422 * 3-way comparator) works correctly on all platforms. Without this, the
423 * comparator would have to call memcmp() with a pair of pointers to the
424 * first byte of each abbreviated key, which is slower.
425 */
426 res = DatumBigEndianToNative(res);
427
428 return res;
429}
#define StaticAssertDecl(condition, errmessage)
Definition c.h:1008
uint32 result
memcpy(sums, checksumBaseOffsets, sizeof(checksumBaseOffsets))
int errcode(int sqlerrcode)
Definition elog.c:874
#define ereturn(context, dummy_value,...)
Definition elog.h:280
struct SortSupportData * SortSupport
Definition execnodes.h:61
#define palloc_object(type)
Definition fe_memutils.h:74
#define PG_RETURN_VOID()
Definition fmgr.h:350
#define PG_RETURN_BYTEA_P(x)
Definition fmgr.h:373
#define PG_GETARG_POINTER(n)
Definition fmgr.h:277
#define PG_RETURN_CSTRING(x)
Definition fmgr.h:364
#define PG_GETARG_CSTRING(n)
Definition fmgr.h:278
#define PG_GETARG_INT64(n)
Definition fmgr.h:284
#define PG_RETURN_INT32(x)
Definition fmgr.h:355
#define PG_FUNCTION_ARGS
Definition fmgr.h:193
#define PG_RETURN_BOOL(x)
Definition fmgr.h:360
static Datum hash_any_extended(const unsigned char *k, int keylen, uint64 seed)
Definition hashfn.h:37
static Datum hash_any(const unsigned char *k, int keylen)
Definition hashfn.h:31
const char * str
static const FormData_pg_attribute a1
Definition heap.c:144
static const FormData_pg_attribute a2
Definition heap.c:157
int y
Definition isn.c:76
int b
Definition isn.c:74
int x
Definition isn.c:75
int a
Definition isn.c:73
Datum macaddr_lt(PG_FUNCTION_ARGS)
Definition mac.c:199
#define hibits(addr)
Definition mac.c:28
Datum macaddr_cmp(PG_FUNCTION_ARGS)
Definition mac.c:186
static int macaddr_cmp_internal(macaddr *a1, macaddr *a2)
Definition mac.c:171
Datum hashmacaddrextended(PG_FUNCTION_ARGS)
Definition mac.c:264
Datum hashmacaddr(PG_FUNCTION_ARGS)
Definition mac.c:256
static Datum macaddr_abbrev_convert(Datum original, SortSupport ssup)
Definition mac.c:404
Datum macaddr_or(PG_FUNCTION_ARGS)
Definition mac.c:309
Datum macaddr_recv(PG_FUNCTION_ARGS)
Definition mac.c:129
Datum macaddr_ne(PG_FUNCTION_ARGS)
Definition mac.c:244
Datum macaddr_trunc(PG_FUNCTION_ARGS)
Definition mac.c:330
Datum macaddr_eq(PG_FUNCTION_ARGS)
Definition mac.c:217
Datum macaddr_not(PG_FUNCTION_ARGS)
Definition mac.c:276
static bool macaddr_abbrev_abort(int memtupcount, SortSupport ssup)
Definition mac.c:389
Datum macaddr_and(PG_FUNCTION_ARGS)
Definition mac.c:292
Datum macaddr_send(PG_FUNCTION_ARGS)
Definition mac.c:150
Datum macaddr_sortsupport(PG_FUNCTION_ARGS)
Definition mac.c:352
#define lobits(addr)
Definition mac.c:31
Datum macaddr_ge(PG_FUNCTION_ARGS)
Definition mac.c:226
static int macaddr_fast_cmp(Datum x, Datum y, SortSupport ssup)
Definition mac.c:375
Datum macaddr_le(PG_FUNCTION_ARGS)
Definition mac.c:208
Datum macaddr_out(PG_FUNCTION_ARGS)
Definition mac.c:110
Datum macaddr_gt(PG_FUNCTION_ARGS)
Definition mac.c:235
void * palloc(Size size)
Definition mcxt.c:1387
static char * errmsg
#define DatumBigEndianToNative(x)
Definition pg_bswap.h:145
static char buf[DEFAULT_XLOG_SEG_SIZE]
#define snprintf
Definition port.h:260
uint64_t Datum
Definition postgres.h:70
void pq_begintypsend(StringInfo buf)
Definition pqformat.c:325
int pq_getmsgbyte(StringInfo msg)
Definition pqformat.c:398
bytea * pq_endtypsend(StringInfo buf)
Definition pqformat.c:345
static void pq_sendbyte(StringInfo buf, uint8 byt)
Definition pqformat.h:160
char * c
e
static int fb(int x)
struct StringInfoData * StringInfo
Definition string.h:15
Definition nodes.h:135
int(* comparator)(Datum x, Datum y, SortSupport ssup)
Datum(* abbrev_converter)(Datum original, SortSupport ssup)
int(* abbrev_full_comparator)(Datum x, Datum y, SortSupport ssup)
bool(* abbrev_abort)(int memtupcount, SortSupport ssup)
Definition inet.h:95
unsigned char e
Definition inet.h:100
unsigned char b
Definition inet.h:97
unsigned char f
Definition inet.h:101
unsigned char c
Definition inet.h:98
unsigned char a
Definition inet.h:96
unsigned char d
Definition inet.h:99
int ssup_datum_unsigned_cmp(Datum x, Datum y, SortSupport ssup)
Definition tuplesort.c:3447
#define PG_GETARG_MACADDR_P(n)
Definition inet.h:158
#define PG_RETURN_MACADDR_P(x)
Definition inet.h:159
static macaddr * DatumGetMacaddrP(Datum X)
Definition inet.h:147

◆ lobits

#define lobits (   addr)     ((unsigned long)(((addr)->d<<16)|((addr)->e<<8)|((addr)->f)))

Definition at line 31 of file mac.c.

Function Documentation

◆ hashmacaddr()

Datum hashmacaddr ( PG_FUNCTION_ARGS  )

Definition at line 256 of file mac.c.

257{
259
260 return hash_any((unsigned char *) key, sizeof(macaddr));
261}

References hash_any(), and PG_GETARG_MACADDR_P.

◆ hashmacaddrextended()

Datum hashmacaddrextended ( PG_FUNCTION_ARGS  )

Definition at line 264 of file mac.c.

265{
267
268 return hash_any_extended((unsigned char *) key, sizeof(macaddr),
269 PG_GETARG_INT64(1));
270}

References hash_any_extended(), PG_GETARG_INT64, and PG_GETARG_MACADDR_P.

◆ macaddr_abbrev_abort()

static bool macaddr_abbrev_abort ( int  memtupcount,
SortSupport  ssup 
)
static

Definition at line 389 of file mac.c.

390{
391 return false;
392}

Referenced by macaddr_sortsupport().

◆ macaddr_abbrev_convert()

static Datum macaddr_abbrev_convert ( Datum  original,
SortSupport  ssup 
)
static

Definition at line 404 of file mac.c.

405{
407 Datum res;
408
409 /*
410 * Zero out the 8-byte Datum and copy in the 6 bytes of the MAC address.
411 * There will be two bytes of zero padding on the end of the least
412 * significant bits.
413 */
414 StaticAssertDecl(sizeof(res) >= sizeof(macaddr),
415 "Datum is too small for macaddr");
416 memset(&res, 0, sizeof(res));
417 memcpy(&res, authoritative, sizeof(macaddr));
418
419 /*
420 * Byteswap on little-endian machines.
421 *
422 * This is needed so that ssup_datum_unsigned_cmp() (an unsigned integer
423 * 3-way comparator) works correctly on all platforms. Without this, the
424 * comparator would have to call memcmp() with a pair of pointers to the
425 * first byte of each abbreviated key, which is slower.
426 */
427 res = DatumBigEndianToNative(res);
428
429 return res;
430}

References DatumBigEndianToNative, DatumGetMacaddrP(), fb(), memcpy(), and StaticAssertDecl.

Referenced by macaddr_sortsupport().

◆ macaddr_and()

Datum macaddr_and ( PG_FUNCTION_ARGS  )

Definition at line 292 of file mac.c.

293{
297
299 result->a = addr1->a & addr2->a;
300 result->b = addr1->b & addr2->b;
301 result->c = addr1->c & addr2->c;
302 result->d = addr1->d & addr2->d;
303 result->e = addr1->e & addr2->e;
304 result->f = addr1->f & addr2->f;
306}

References fb(), palloc_object, PG_GETARG_MACADDR_P, PG_RETURN_MACADDR_P, and result.

◆ macaddr_cmp()

Datum macaddr_cmp ( PG_FUNCTION_ARGS  )

◆ macaddr_cmp_internal()

static int macaddr_cmp_internal ( macaddr a1,
macaddr a2 
)
static

Definition at line 171 of file mac.c.

172{
173 if (hibits(a1) < hibits(a2))
174 return -1;
175 else if (hibits(a1) > hibits(a2))
176 return 1;
177 else if (lobits(a1) < lobits(a2))
178 return -1;
179 else if (lobits(a1) > lobits(a2))
180 return 1;
181 else
182 return 0;
183}

References a1, a2, hibits, and lobits.

Referenced by macaddr_cmp(), macaddr_eq(), macaddr_fast_cmp(), macaddr_ge(), macaddr_gt(), macaddr_le(), macaddr_lt(), and macaddr_ne().

◆ macaddr_eq()

Datum macaddr_eq ( PG_FUNCTION_ARGS  )

Definition at line 217 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

Referenced by gbt_macadeq().

◆ macaddr_fast_cmp()

static int macaddr_fast_cmp ( Datum  x,
Datum  y,
SortSupport  ssup 
)
static

Definition at line 375 of file mac.c.

376{
379
381}

References DatumGetMacaddrP(), fb(), macaddr_cmp_internal(), x, and y.

Referenced by macaddr_sortsupport().

◆ macaddr_ge()

Datum macaddr_ge ( PG_FUNCTION_ARGS  )

Definition at line 226 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

Referenced by gbt_macadge().

◆ macaddr_gt()

Datum macaddr_gt ( PG_FUNCTION_ARGS  )

Definition at line 235 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

Referenced by gbt_macadgt().

◆ macaddr_in()

Datum macaddr_in ( PG_FUNCTION_ARGS  )

Definition at line 44 of file mac.c.

45{
46 char *str = PG_GETARG_CSTRING(0);
47 Node *escontext = fcinfo->context;
49 int a,
50 b,
51 c,
52 d,
53 e,
54 f;
55 char junk[2];
56 int count;
57
58 /* %1s matches iff there is trailing non-whitespace garbage */
59
60 count = sscanf(str, "%x:%x:%x:%x:%x:%x%1s",
61 &a, &b, &c, &d, &e, &f, junk);
62 if (count != 6)
63 count = sscanf(str, "%x-%x-%x-%x-%x-%x%1s",
64 &a, &b, &c, &d, &e, &f, junk);
65 if (count != 6)
66 count = sscanf(str, "%2x%2x%2x:%2x%2x%2x%1s",
67 &a, &b, &c, &d, &e, &f, junk);
68 if (count != 6)
69 count = sscanf(str, "%2x%2x%2x-%2x%2x%2x%1s",
70 &a, &b, &c, &d, &e, &f, junk);
71 if (count != 6)
72 count = sscanf(str, "%2x%2x.%2x%2x.%2x%2x%1s",
73 &a, &b, &c, &d, &e, &f, junk);
74 if (count != 6)
75 count = sscanf(str, "%2x%2x-%2x%2x-%2x%2x%1s",
76 &a, &b, &c, &d, &e, &f, junk);
77 if (count != 6)
78 count = sscanf(str, "%2x%2x%2x%2x%2x%2x%1s",
79 &a, &b, &c, &d, &e, &f, junk);
80 if (count != 6)
81 ereturn(escontext, (Datum) 0,
83 errmsg("invalid input syntax for type %s: \"%s\"", "macaddr",
84 str)));
85
86 if ((a < 0) || (a > 255) || (b < 0) || (b > 255) ||
87 (c < 0) || (c > 255) || (d < 0) || (d > 255) ||
88 (e < 0) || (e > 255) || (f < 0) || (f > 255))
89 ereturn(escontext, (Datum) 0,
91 errmsg("invalid octet value in \"macaddr\" value: \"%s\"", str)));
92
94
95 result->a = a;
96 result->b = b;
97 result->c = c;
98 result->d = d;
99 result->e = e;
100 result->f = f;
101
103}

References a, b, ereturn, errcode(), errmsg, fb(), palloc_object, PG_GETARG_CSTRING, PG_RETURN_MACADDR_P, result, and str.

◆ macaddr_le()

Datum macaddr_le ( PG_FUNCTION_ARGS  )

Definition at line 208 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

Referenced by gbt_macadle().

◆ macaddr_lt()

Datum macaddr_lt ( PG_FUNCTION_ARGS  )

Definition at line 199 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

Referenced by gbt_macadlt().

◆ macaddr_ne()

Datum macaddr_ne ( PG_FUNCTION_ARGS  )

Definition at line 244 of file mac.c.

References a1, a2, macaddr_cmp_internal(), PG_GETARG_MACADDR_P, and PG_RETURN_BOOL.

◆ macaddr_not()

Datum macaddr_not ( PG_FUNCTION_ARGS  )

Definition at line 276 of file mac.c.

277{
278 macaddr *addr = PG_GETARG_MACADDR_P(0);
280
282 result->a = ~addr->a;
283 result->b = ~addr->b;
284 result->c = ~addr->c;
285 result->d = ~addr->d;
286 result->e = ~addr->e;
287 result->f = ~addr->f;
289}

References fb(), palloc_object, PG_GETARG_MACADDR_P, PG_RETURN_MACADDR_P, and result.

◆ macaddr_or()

Datum macaddr_or ( PG_FUNCTION_ARGS  )

Definition at line 309 of file mac.c.

310{
314
316 result->a = addr1->a | addr2->a;
317 result->b = addr1->b | addr2->b;
318 result->c = addr1->c | addr2->c;
319 result->d = addr1->d | addr2->d;
320 result->e = addr1->e | addr2->e;
321 result->f = addr1->f | addr2->f;
323}

References fb(), palloc_object, PG_GETARG_MACADDR_P, PG_RETURN_MACADDR_P, and result.

◆ macaddr_out()

Datum macaddr_out ( PG_FUNCTION_ARGS  )

Definition at line 110 of file mac.c.

111{
112 macaddr *addr = PG_GETARG_MACADDR_P(0);
113 char *result;
114
115 result = (char *) palloc(32);
116
117 snprintf(result, 32, "%02x:%02x:%02x:%02x:%02x:%02x",
118 addr->a, addr->b, addr->c, addr->d, addr->e, addr->f);
119
121}

References macaddr::a, macaddr::b, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc(), PG_GETARG_MACADDR_P, PG_RETURN_CSTRING, result, and snprintf.

◆ macaddr_recv()

Datum macaddr_recv ( PG_FUNCTION_ARGS  )

Definition at line 129 of file mac.c.

130{
132 macaddr *addr;
133
134 addr = palloc_object(macaddr);
135
136 addr->a = pq_getmsgbyte(buf);
137 addr->b = pq_getmsgbyte(buf);
138 addr->c = pq_getmsgbyte(buf);
139 addr->d = pq_getmsgbyte(buf);
140 addr->e = pq_getmsgbyte(buf);
141 addr->f = pq_getmsgbyte(buf);
142
144}

References macaddr::a, macaddr::b, buf, macaddr::c, macaddr::d, macaddr::e, macaddr::f, palloc_object, PG_GETARG_POINTER, PG_RETURN_MACADDR_P, and pq_getmsgbyte().

◆ macaddr_send()

Datum macaddr_send ( PG_FUNCTION_ARGS  )

Definition at line 150 of file mac.c.

151{
152 macaddr *addr = PG_GETARG_MACADDR_P(0);
154
156 pq_sendbyte(&buf, addr->a);
157 pq_sendbyte(&buf, addr->b);
158 pq_sendbyte(&buf, addr->c);
159 pq_sendbyte(&buf, addr->d);
160 pq_sendbyte(&buf, addr->e);
161 pq_sendbyte(&buf, addr->f);
163}

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

◆ macaddr_trunc()

Datum macaddr_trunc ( PG_FUNCTION_ARGS  )

Definition at line 330 of file mac.c.

331{
332 macaddr *addr = PG_GETARG_MACADDR_P(0);
334
336
337 result->a = addr->a;
338 result->b = addr->b;
339 result->c = addr->c;
340 result->d = 0;
341 result->e = 0;
342 result->f = 0;
343
345}

References macaddr::a, macaddr::b, macaddr::c, palloc_object, PG_GETARG_MACADDR_P, PG_RETURN_MACADDR_P, and result.