1 /**************************************************************************
3 **************************************************************************/
10 /**************************************************************************
11 IPCHKSUM - Checksum IP Header
12 **************************************************************************/
13 uint16_t ipchksum(const void *data
, unsigned long length
)
19 /* In the most straight forward way possible,
20 * compute an ip style checksum.
24 for(i
= 0; i
< length
; i
++) {
30 /* Add the new value */
32 /* Wrap around the carry */
34 sum
= (sum
+ (sum
>> 16)) & 0xFFFF;
37 return (~cpu_to_le16(sum
)) & 0xFFFF;
40 uint16_t add_ipchksums(unsigned long offset
, uint16_t sum
, uint16_t new)
42 unsigned long checksum
;
46 /* byte swap the sum if it came from an odd offset
47 * since the computation is endian independant this
53 if (checksum
> 0xFFFF) {
56 return (~checksum
) & 0xFFFF;
59 /**************************************************************************
61 **************************************************************************/
62 unsigned int sleep(unsigned int secs
)
66 for (tmo
= currticks()+secs
*TICKS_PER_SEC
; currticks() < tmo
; ) {
71 /**************************************************************************
73 **************************************************************************/
74 void interruptible_sleep(int secs
)
80 /**************************************************************************
81 STRCASECMP (not entirely correct, but this will do for our purposes)
82 **************************************************************************/
83 int strcasecmp(const char *a
, const char *b
)
85 while (*a
&& *b
&& (*a
& ~0x20) == (*b
& ~0x20)) {a
++; b
++; }
86 return((*a
& ~0x20) - (*b
& ~0x20));
89 /**************************************************************************
90 INET_ATON - Convert an ascii x.x.x.x to binary form
91 **************************************************************************/
92 int inet_aton ( const char *cp
, struct in_addr
*inp
) {
94 const char *digits_start
;
98 for(j
= 0; j
<= 3; j
++) {
100 val
= strtoul(p
, ( char ** ) &p
, 10);
101 if ((p
== digits_start
) || (val
> 255)) return 0;
102 if ( ( j
< 3 ) && ( *(p
++) != '.' ) ) return 0;
103 ip
= (ip
<< 8) | val
;
106 inp
->s_addr
= htonl(ip
);
112 int isspace ( int c
) {
126 unsigned long strtoul ( const char *p
, char **endp
, int base
) {
127 unsigned long ret
= 0;
128 unsigned int charval
;
130 while ( isspace ( *p
) )
138 if ( ( *p
| 0x20 ) == 'x' ) {
147 if ( charval
>= 'a' ) {
148 charval
= ( charval
- 'a' + 10 );
149 } else if ( charval
>= 'A' ) {
150 charval
= ( charval
- 'A' + 10 );
152 charval
= ( charval
- '0' );
154 if ( charval
>= ( unsigned int ) base
)
156 ret
= ( ( ret
* base
) + charval
);
161 *endp
= ( char * ) p
;