// Compare addresses: // return Z such that Z < 0 if X < Y, Z == 0 if X == Y, Z > 0 if X > Y int compare_address(const string& x, const string& y) { unsigned int px = 0; unsigned int py = 0; while (px < x.length() && is_leading_zero(x[px])) px++; while (py < y.length() && is_leading_zero(y[py])) py++; unsigned int lx = x.length() - px; unsigned int ly = y.length() - py; while (lx > 0 && is_trailing_zero(x[px + lx - 1])) lx--; while (ly > 0 && is_trailing_zero(y[py + ly - 1])) ly--; int ret = lx - ly; for (unsigned i = 0; ret == 0 && i < lx; i++) ret = xdigit(x[px + i]) - xdigit(y[py + i]); #if 0 if (ret < 0) std::clog << x << " < " << y << "\n"; else if (ret > 0) std::clog << x << " > " << y << "\n"; else std::clog << x << " = " << y << "\n"; #endif return ret; }
/* * Convert Ethernet address in the standard hex-digits-and-colons to binary * representation. * Re-entrant version (GNU extensions) */ struct ether_addr * ether_aton_r (const char *asc, struct ether_addr * addr) { int i, val0, val1; for (i = 0; i < ETHER_ADDR_LEN; ++i) { val0 = xdigit(*asc); asc++; if (val0 < 0) return NULL; val1 = xdigit(*asc); asc++; if (val1 < 0) return NULL; addr->ether_addr_octet[i] = (u_int8_t)((val0 << 4) + val1); if (i < ETHER_ADDR_LEN - 1) { if (*asc != ':') return NULL; asc++; } } if (*asc != '\0') return NULL; return addr; }
unsigned long int hex(char *ptr) { unsigned long result = 0; while (*ptr) { result *= 16; result += xdigit(*ptr++); } return result; }
//--------------------------------------------------------------------------- // Convert the ascii representation of a hex number to an integer int htoi(char *Value) { int i; int Result; Result = 0; i = 0; while ((Value[i] != 0) && (Value[i] == ' ')) i++; while ((Value[i] != 0) && isxDigit(Value[i])) { Result = Result * 16 + xdigit(Value[i]); i++; } return(Result); }
LOGICAL hex2char(const char *hex, char *buf) { int ch = 0; char *p = (char *)hex; while(*p) { if (!isxdigit(*p)) return ERROR; ch <<= 4; ch += xdigit(*p); ++p; } *buf = (char)ch; return SUCCESS; }
Boolean_T hex2char(const char *hex, char *buf) { int ch = 0; char *p = (char *)hex; while(*p) { if (!isxdigit(*p)) return Error_; ch <<= 4; ch += xdigit(*p); ++p; } *buf = (char)ch; return Success_; }
__regargs BOOL ReadInt(char **data, LONG *numptr) { char *str = *data; char c; LONG num = 0; BOOL minus = FALSE; BOOL hex = FALSE; /* Skip white spaces. */ if (!NextWord(&str)) return FALSE; /* Read optional sign character. */ if (*str == '-') str++, minus = TRUE; if (*str == '$') str++, hex = TRUE; /* Read at least one digit. */ c = *str; if (hex) { if (!isxdigit(c)) return FALSE; while (isxdigit(c)) { num = num * 16 + xdigit(c); c = *(++str); } } else { if (!isdigit(c)) return FALSE; while (isdigit(c)) { num = num * 10 + digit(c); c = *(++str); } } *data = str; if (numptr) *numptr = minus ? -num : num; return TRUE; }