ReactOS 0.4.15-dev-7942-gd23573b
iputils.c
Go to the documentation of this file.
1#include <headers.h>
2#include <datatypes.h>
3#include <options.h>
4#include <utils.h>
5
6int split_ip( char *text, u8b *dest, int place )
7{
8 int dotcount;
9
10 /* Don't touch this, unless you like pointer aritmethic */
11
12 *dest = 0;
13
14 if( !text )
15 return -1;
16
17 for( dotcount = 0; (dotcount < place) && ( text ); text++ )
18 if( *text == '.' )
19 dotcount++;
20
21 if( !text )
22 return -2;
23
24 while(( *text != '.' ) && ( *text != '\0' ))
25 {
26 *dest *= 10;
27 *dest += (u8b)(*text-48);
28 /* 48 is not a hack, is just the code of 0 */
29 text++;
30 }
31
32 return 0;
33}
34
35int get_ip( char *text, u32b *dest )
36{
37 /* Don't touch this, unless you like pointer aritmethic */
38
39 *dest = 0;
40
41 if( !text )
42 return -1;
43
44 while( *text != '\0' )
45 {
46 if( *text == '.' )
47 {
48 *dest = *dest << 8;
49 text++;
50 continue;
51 }
52 *dest *= 10;
53 *dest += (u8b)(*text-48);
54 /* 48 is not a hack, is just the code of 0 */
55 text++;
56 }
57
58 return 0;
59}
unsigned int u32b
Definition: datatypes.h:6
unsigned char u8b
Definition: datatypes.h:4
const WCHAR * text
Definition: package.c:1799
int get_ip(char *text, u32b *dest)
Definition: iputils.c:35
int split_ip(char *text, u8b *dest, int place)
Definition: iputils.c:6
static char * dest
Definition: rtl.c:135
static char * place
Definition: getopt.c:55