Skip to content
Snippets Groups Projects
Commit fe80c00d authored by Jan Kadlec's avatar Jan Kadlec
Browse files

Commented out old b32pton.

Refs #706
parent 8d77fd38
No related branches found
No related tags found
No related merge requests found
......@@ -62,48 +62,48 @@ int inet_pton(int af, const char *src, void *dst)
/* NOTREACHED */
}
int my_b32_pton(const char *src, uint8_t *target, size_t tsize)
{
char ch;
size_t p = 0;
memset(target, '\0', tsize);
while ((ch = *src++)) {
uint8_t d;
size_t b;
size_t n;
if (p + 5 >= tsize * 8) {
return -1;
}
if (isspace(ch)) {
continue;
}
if (ch >= '0' && ch <= '9') {
d = ch - '0';
} else if (ch >= 'A' && ch <= 'V') {
d = ch - 'A' + 10;
} else if (ch >= 'a' && ch <= 'v') {
d = ch - 'a' + 10;
} else {
return -1;
}
b = 7 - p % 8;
n = p / 8;
if (b >= 4) {
target[n] |= d << (b - 4);
} else {
target[n] |= d >> (4 - b);
target[n+1] |= d << (b + 4);
}
p += 5;
}
return (p + 7) / 8;
}
//int my_b32_pton(const char *src, uint8_t *target, size_t tsize)
//{
// char ch;
// size_t p = 0;
// memset(target, '\0', tsize);
// while ((ch = *src++)) {
// uint8_t d;
// size_t b;
// size_t n;
// if (p + 5 >= tsize * 8) {
// return -1;
// }
// if (isspace(ch)) {
// continue;
// }
// if (ch >= '0' && ch <= '9') {
// d = ch - '0';
// } else if (ch >= 'A' && ch <= 'V') {
// d = ch - 'A' + 10;
// } else if (ch >= 'a' && ch <= 'v') {
// d = ch - 'a' + 10;
// } else {
// return -1;
// }
// b = 7 - p % 8;
// n = p / 8;
// if (b >= 4) {
// target[n] |= d << (b - 4);
// } else {
// target[n] |= d >> (4 - b);
// target[n+1] |= d << (b + 4);
// }
// p += 5;
// }
// return (p + 7) / 8;
//}
#define Assert(Cond) if (!(Cond)) abort()
......
......@@ -32,7 +32,7 @@
int inet_pton4(const char *src, uint8_t *dst);
int inet_pton6(const char *src, uint8_t *dst);
int my_b32_pton(const char *src, uint8_t *target, size_t tsize);
//int my_b32_pton(const char *src, uint8_t *target, size_t tsize);
const char *inet_ntop4(const u_char *src, char *dst, size_t size);
const char *inet_ntop6(const u_char *src, char *dst, size_t size);
int inet_pton(int af, const char *src, void *dst);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment