Sfoglia il codice sorgente

added variable to-rag part to mitigate dropping TM-owned ACKs

Jiri Kuthan 23 anni fa
parent
commit
fa377d6bd6
4 ha cambiato i file con 86 aggiunte e 38 eliminazioni
  1. 42 0
      crc.c
  2. 5 0
      crc.h
  3. 0 38
      modules/tm/t_lookup.c
  4. 39 0
      ut.h

+ 42 - 0
crc.c

@@ -5,6 +5,8 @@
  */
 
 #include <stdio.h>
+#include "str.h"
+#include "ut.h"
 #include "crc.h"
 
 #define OK 0
@@ -179,6 +181,46 @@ unsigned short int crc_16_tab[] = { /* CRC polynomial 0xA001 */
 0x8201, 0x42C0, 0x4380, 0x8341, 0x4100, 0x81C1, 0x8081, 0x4040,
 };
 
+unsigned short crcitt_string( char *s, int len )
+{
+	register unsigned short ccitt;
+	
+	ccitt = 0xFFFF;
+
+	while( len ) {
+		ccitt = UPDCIT(*s, ccitt);
+		s++; len--;
+	}
+	return ~ccitt;
+}
+
+void crcitt_string_array( char *dst, str src[], int size )
+{
+	register int i;
+	register unsigned short ccitt;
+	register char *c;
+	register int len;
+	int str_len;
+
+	ccitt = 0xFFFF;
+	str_len=CRC16_LEN;
+	for (i=0; i<size; i++ ) {
+		c=src[i].s;
+		len=src[i].len;
+		while(len) {
+			ccitt = UPDCIT( *c, ccitt );
+			c++;len--;
+		}
+	}
+	ccitt = ~ccitt;
+	if (int2reverse_hex( &dst, &str_len, ccitt )==-1) {
+		/* bug ... printed ccitt value longer than CRC32_LEN */
+		LOG(L_CRIT, "ERROR: crcitt_string_array: string conversion incomplete\n");
+	}
+}
+		
+				
+
 int crc32file (char *name)
 {
 	register FILE *fin;

+ 5 - 0
crc.h

@@ -3,9 +3,14 @@
 #ifndef _CRC_H_
 #define _CRC_H_
 
+#define CRC16_LEN	4
+
 extern unsigned long int crc_32_tab[];
 extern unsigned short int ccitt_tab[];
 extern unsigned short int crc_16_tab[];
 
+unsigned short crcitt_string( char *s, int len );
+void crcitt_string_array( char *dst, str src[], int size );
+
 #endif
 

+ 0 - 38
modules/tm/t_lookup.c

@@ -60,44 +60,6 @@
 	)==0 )
 
 
-static int reverse_hex2int( char *c, int len )
-{
-	char *pc;
-	int r;
-	char mychar;
-
-	r=0;
-	for (pc=c+len-1; len>0; pc--, len--) {
-		r <<= 4 ;
-		mychar=*pc;
-		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
-		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
-		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
-		else return -1;
-	}
-	return r;
-}
-
-inline static int int2reverse_hex( char **c, int *size, int nr )
-{
-	unsigned short digit;
-
-	if (*size && nr==0) {
-		**c = '0';
-		(*c)++;
-		(*size)--;
-		return 1;
-	}
-
-	while (*size && nr ) {
-		digit = nr & 0xf ;
-		**c= digit >= 10 ? digit + 'a' - 10 : digit + '0';
-		nr >>= 4;
-		(*c)++;
-		(*size)--;
-	}
-	return nr ? -1 /* number not processed; too little space */ : 1;
-}
 
 /* function returns:
  *      -1 - transaction wasn't found

+ 39 - 0
ut.h

@@ -156,5 +156,44 @@ static inline char* q_memchr(char* p, int c, unsigned int size)
 }
 	
 
+static int reverse_hex2int( char *c, int len )
+{
+	char *pc;
+	int r;
+	char mychar;
+
+	r=0;
+	for (pc=c+len-1; len>0; pc--, len--) {
+		r <<= 4 ;
+		mychar=*pc;
+		if ( mychar >='0' && mychar <='9') r+=mychar -'0';
+		else if (mychar >='a' && mychar <='f') r+=mychar -'a'+10;
+		else if (mychar  >='A' && mychar <='F') r+=mychar -'A'+10;
+		else return -1;
+	}
+	return r;
+}
+
+inline static int int2reverse_hex( char **c, int *size, int nr )
+{
+	unsigned short digit;
+
+	if (*size && nr==0) {
+		**c = '0';
+		(*c)++;
+		(*size)--;
+		return 1;
+	}
+
+	while (*size && nr ) {
+		digit = nr & 0xf ;
+		**c= digit >= 10 ? digit + 'a' - 10 : digit + '0';
+		nr >>= 4;
+		(*c)++;
+		(*size)--;
+	}
+	return nr ? -1 /* number not processed; too little space */ : 1;
+}
+
 
 #endif