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