Author: mladen.turk(a)jboss.com
Date: 2007-09-07 04:03:05 -0400 (Fri, 07 Sep 2007)
New Revision: 986
Modified:
trunk/sight/native/share/jnu.c
Log:
Added hex to binary function for translating hex addreses
Modified: trunk/sight/native/share/jnu.c
===================================================================
--- trunk/sight/native/share/jnu.c 2007-09-07 07:01:55 UTC (rev 985)
+++ trunk/sight/native/share/jnu.c 2007-09-07 08:03:05 UTC (rev 986)
@@ -224,7 +224,7 @@
if ((b = malloc(rd))) {
rd = fread(b, 1, rd - 2, f);
- if (rd > 0) {
+ if (rd > 0) {
/* Remove all trailing zero and space characters */
for (i = rd - 1; i >= 0 && (apr_iscntrl(b[i]) ||
apr_isspace(b[i])); i--)
@@ -585,7 +585,7 @@
* to use pointer overlays. All the world's not a VAX.
*/
char tmp[sizeof "ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255"], *tp;
- struct { int base, len; }best = {-1, 0}, cur = {-1, 0};
+ struct { int base, len; } best = {-1, 0}, cur = {-1, 0};
unsigned int words[IN6ADDRSZ / INT16SZ];
int i;
const unsigned char *next_src, *src_end;
@@ -883,3 +883,46 @@
return *str ? str : NULL;
}
}
+
+static unsigned char uch4hex(unsigned char i)
+{
+ if (apr_isdigit(i))
+ return i - '0';
+ else if (apr_isupper(i))
+ return i - 'A';
+ else
+ return i - 'a';
+}
+
+/*
+ * Convert hex to array
+ */
+const unsigned char *sight_hex2bin(const unsigned char *src, unsigned char *dst,
+ size_t size)
+{
+ char tmp[64], *tp;
+ int i;
+ char *next = src;
+
+ tp = tmp;
+ for (i = 0; i < 62; i++) {
+ unsigned char ch;
+ if (!*next || !apr_isxdigit(*next)
+ break;
+ ch = (uch4hex(*next++) << 4);
+ if (!*next || !apr_isxdigit(*next)
+ break;
+ ch |= uch4hex(*next++);
+ *tp++ = ch;
+ }
+ *tp = '\0';
+ /*
+ * Check for overflow, copy, and we're done.
+ */
+ if ((size_t)(tp - tmp) > size) {
+ errno = ENOSPC;
+ return NULL;
+ }
+ strcpy(dst, tmp);
+ return dst;
+}
Show replies by date