From: aland Date: Mon, 15 Sep 2003 20:16:53 +0000 (+0000) Subject: Patches to print/parse IPv6 interface ID's. X-Git-Tag: release_1_0_0_pre1~729 X-Git-Url: http://www.project-moonshot.org/gitweb/?a=commitdiff_plain;h=6593f8df047a793cd13c54df52e010ff13feacb6;p=freeradius.git Patches to print/parse IPv6 interface ID's. Patch from Hajimu UMEMOTO Next, we do IPv6 addresses & prefixes... --- diff --git a/src/include/libradius.h b/src/include/libradius.h index e06d15b..558448e 100644 --- a/src/include/libradius.h +++ b/src/include/libradius.h @@ -259,6 +259,8 @@ char * ip_hostname (char *buf, size_t buflen, uint32_t ipaddr); uint32_t ip_getaddr (const char *); char * ip_ntoa(char *, uint32_t); uint32_t ip_addr(const char *); +char *ifid_ntoa(char *buffer, size_t size, uint8_t *ifid); +uint8_t *ifid_aton(const char *ifid_str, uint8_t *ifid); char *strNcpy(char *dest, const char *src, int n); void rad_lowercase(char *str); void rad_rmspace(char *str); diff --git a/src/lib/misc.c b/src/lib/misc.c index 94f1947..79f1b73 100644 --- a/src/lib/misc.c +++ b/src/lib/misc.c @@ -284,3 +284,62 @@ int rad_unlockfd(int fd, int lock_len) return fcntl(fd, F_UNLCK, (void *)&fl); #endif } + +/* + * Return an interface-id in standard colon notation + */ +char *ifid_ntoa(char *buffer, size_t size, uint8_t *ifid) +{ + snprintf(buffer, size, "%x:%x:%x:%x", + (ifid[0] << 8) + ifid[1], (ifid[2] << 8) + ifid[3], + (ifid[4] << 8) + ifid[5], (ifid[6] << 8) + ifid[7]); + return buffer; +} + + +/* + * Return an interface-id from + * one supplied in standard colon notation. + */ +uint8_t *ifid_aton(const char *ifid_str, uint8_t *ifid) +{ + static const char xdigits[] = "0123456789abcdef"; + char *p, *pch; + int num_id = 0, val = 0, idx = 0; + + for (p = ifid_str; ; ++p) { + if (*p == ':' || *p == '\0') { + if (num_id <= 0) + return NULL; + + /* + * Drop 'val' into the array. + */ + ifid[idx] = (val >> 8) & 0xff; + ifid[idx + 1] = val & 0xff; + if (*p == '\0') { + /* + * Must have all entries before + * end of the string. + */ + if (idx != 6) + return NULL; + break; + } + val = 0; + num_id = 0; + if ((idx += 2) > 6) + return NULL; + } else if ((pch = strchr(xdigits, tolower(*p))) != NULL) { + if (++num_id > 4) + return NULL; + /* + * Dumb version of 'scanf' + */ + val <<= 4; + val |= (pch - xdigits); + } else + return NULL; + } + return ifid; + } diff --git a/src/lib/print.c b/src/lib/print.c index 1257531..162db03 100644 --- a/src/lib/print.c +++ b/src/lib/print.c @@ -189,6 +189,10 @@ int vp_prints_value(char * out, int outlen, VALUE_PAIR *vp, int delimitst) a = buf; break; + case PW_TYPE_IFID: + a = ifid_ntoa(buf, sizeof(buf), vp->strvalue); + break; + default: a = 0; break; diff --git a/src/lib/valuepair.c b/src/lib/valuepair.c index 4749022..c82d7b3 100644 --- a/src/lib/valuepair.c +++ b/src/lib/valuepair.c @@ -674,6 +674,16 @@ VALUE_PAIR *pairparsevalue(VALUE_PAIR *vp, const char *value) } break; + case PW_TYPE_IFID: + if (ifid_aton(value, vp->strvalue) == NULL) { + librad_log("failed to parse interface-id " + "string \"%s\"", value); + return NULL; + } + vp->length = 8; + vp->strvalue[vp->length] = '\0'; + break; + /* * Anything else. */