[DHCPSVC]: It's a service, move it in the correct directory.
[reactos.git] / reactos / base / services / dhcpcsvc / dhcp / compat.c
1 #include <rosdhcp.h>
2
3 size_t strlcpy(char *d, const char *s, size_t bufsize)
4 {
5 size_t len = strlen(s);
6 size_t ret = len;
7 if (bufsize > 0) {
8 if (len >= bufsize)
9 len = bufsize-1;
10 memcpy(d, s, len);
11 d[len] = 0;
12 }
13 return ret;
14 }
15
16 // not really random :(
17 u_int32_t arc4random()
18 {
19 static int did_srand = 0;
20 u_int32_t ret;
21
22 if (!did_srand) {
23 srand(0);
24 did_srand = 1;
25 }
26
27 ret = rand() << 10 ^ rand();
28 return ret;
29 }
30
31
32 int inet_aton(const char *cp, struct in_addr *inp)
33 /* inet_addr code from ROS, slightly modified. */
34 {
35 ULONG Octets[4] = {0,0,0,0};
36 ULONG i = 0;
37
38 if(!cp)
39 return 0;
40
41 while(*cp)
42 {
43 CHAR c = *cp;
44 cp++;
45
46 if(c == '.')
47 {
48 i++;
49 continue;
50 }
51
52 if(c < '0' || c > '9')
53 return 0;
54
55 Octets[i] *= 10;
56 Octets[i] += (c - '0');
57
58 if(Octets[i] > 255)
59 return 0;
60 }
61
62 inp->S_un.S_addr = (Octets[3] << 24) + (Octets[2] << 16) + (Octets[1] << 8) + Octets[0];
63 return 1;
64 }
65