/* File : misc.c */ /* Copyright (C) 1992 Indian Institute of Technology, Bombay Written by V. Srinivas and Vishwas Joglekar, Dept of Computer Science and Engineering. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 1, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ #include "yapcbr.h" #include "ipxwatch.h" #define uchar(x) (unsigned char) (x) WORD getword(BYTE *cp); BYTE *putword(WORD x, BYTE *s); int hash_addr(BYTE *dest_addr,int len); int hex_toascii(unsigned char *str); /* Get a short in host order from a char array in network order */ WORD getword(cp) register BYTE *cp; { register WORD x; x = uchar(*cp++); x <<= 8; x |= uchar(*cp); return x; } /* Put a short in host order into a char array in network order */ BYTE * putword(x,s) WORD x; register BYTE *s; { BYTE *tmp; tmp = s; *s++=x>>8; *s=x; return(tmp); } /* hash function, function hashpjw ? */ int hash_addr(BYTE *dest_addr,int len) { int c; unsigned h=0,g; for(c=0;c> 24); h = h ^ g; } } return h % MAX_PRIME; } /* Convert hex-ascii to integer */ int hex_toascii(unsigned char *str) { int i = 0; unsigned char ch; while((ch = toupper(*str++)) != '\0'){ if(ch == 'X') continue; if(ch >= '0' && ch <= '9') i = (i * 16) + (ch - '0'); else if(ch >= 'A' && ch <= 'F') i = (i * 16) + (ch - 'A' + 10); else break; } return i; }