/* Handle the first character */ if (*ptr > 127) goto invalid_input;
lookup = hexlookup[*ptr]; if (lookup < 0) goto invalid_input;
ret = lookup << 4;
/* Move to the second character */
ptr++;
if (*ptr > 127) goto invalid_input;
lookup = hexlookup[*ptr]; if (lookup < 0) goto invalid_input;
ret += lookup;
return ret;
invalid_input:
*badhex = true; return0;
}
/* *MACaddress(EUI-48andEUI-64)reader.Acceptsseveralcommonnotations.
*/
Datum
macaddr8_in(PG_FUNCTION_ARGS)
{ constunsignedchar *str = (unsignedchar *) PG_GETARG_CSTRING(0);
Node *escontext = fcinfo->context; constunsignedchar *ptr = str; bool badhex = false;
macaddr8 *result; unsignedchar a = 0,
b = 0,
c = 0,
d = 0,
e = 0,
f = 0,
g = 0,
h = 0; int count = 0; unsignedchar spacer = '\0';
/* skip leading spaces */ while (*ptr && isspace(*ptr))
ptr++;
/* digits must always come in pairs */ while (*ptr && *(ptr + 1))
{ /* *Attempttodecodeeachbyte,whichmustbe2hexdigitsinarow. *Ifeitherdigitisnothex,hex2_to_ucharwillthrowereport()for *us.Either6or8byteMACaddressesaresupported.
*/
/* Attempt to collect a byte */
count++;
switch (count)
{ case1:
a = hex2_to_uchar(ptr, &badhex); break; case2:
b = hex2_to_uchar(ptr, &badhex); break; case3:
c = hex2_to_uchar(ptr, &badhex); break; case4:
d = hex2_to_uchar(ptr, &badhex); break; case5:
e = hex2_to_uchar(ptr, &badhex); break; case6:
f = hex2_to_uchar(ptr, &badhex); break; case7:
g = hex2_to_uchar(ptr, &badhex); break; case8:
h = hex2_to_uchar(ptr, &badhex); break; default: /* must be trailing garbage... */ goto fail;
}
if (badhex) goto fail;
/* Move forward to where the next byte should be */
ptr += 2;
/* Check for a spacer, these are valid, anything else is not */ if (*ptr == ':' || *ptr == '-' || *ptr == '.')
{ /* remember the spacer used, if it changes then it isn't valid */ if (spacer == '\0')
spacer = *ptr;
/* Have to use the same spacer throughout */ elseif (spacer != *ptr) goto fail;
/* move past the spacer */
ptr++;
}
/* allow trailing whitespace after if we have 6 or 8 bytes */ if (count == 6 || count == 8)
{ if (isspace(*ptr))
{ while (*++ptr && isspace(*ptr));
/* If we found a space and then non-space, it's invalid */ if (*ptr) goto fail;
}
}
}
/* Convert a 6 byte MAC address to macaddr8 */ if (count == 6)
{
h = f;
g = e;
f = d;
d = 0xFF;
e = 0xFE;
} elseif (count != 8) goto fail;
Datum
macaddr8tomacaddr(PG_FUNCTION_ARGS)
{
macaddr8 *addr = PG_GETARG_MACADDR8_P(0);
macaddr *result;
result = (macaddr *) palloc0(sizeof(macaddr));
if ((addr->d != 0xFF) || (addr->e != 0xFE))
ereport(ERROR,
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
errmsg("macaddr8 data out of range to convert to macaddr"),
errhint("Only addresses that have FF and FE as values in the " "4th and 5th bytes from the left, for example " "xx:xx:xx:ff:fe:xx:xx:xx, are eligible to be converted " "from macaddr8 to macaddr.")));
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.