ReactOS 0.4.15-dev-8245-gd24675b
util.c
Go to the documentation of this file.
1#include <rosdhcp.h>
2
3#define NDEBUG
4#include <reactos/debug.h>
5
6char *piaddr( struct iaddr addr ) {
7 struct sockaddr_in sa;
8 memcpy(&sa.sin_addr,addr.iabuf,sizeof(sa.sin_addr));
9 return inet_ntoa( sa.sin_addr );
10}
11
12int note( char *format, ... ) {
13 char buf[0x100];
14 int ret;
15 va_list arg_begin;
16 va_start( arg_begin, format );
17
18 ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
19
20 va_end( arg_begin );
21
22 DPRINT("NOTE: %s\n", buf);
23
24 return ret;
25}
26
27int debug( char *format, ... ) {
28 char buf[0x100];
29 int ret;
30 va_list arg_begin;
31 va_start( arg_begin, format );
32
33 ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
34
35 va_end( arg_begin );
36
37 DPRINT("DEBUG: %s\n", buf);
38
39 return ret;
40}
41
42int warn( char *format, ... ) {
43 char buf[0x100];
44 int ret;
45 va_list arg_begin;
46 va_start( arg_begin, format );
47
48 ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
49
50 va_end( arg_begin );
51
52 DPRINT("WARN: %s\n", buf);
53
54 return ret;
55}
56
57int warning( char *format, ... ) {
58 char buf[0x100];
59 int ret;
60 va_list arg_begin;
61 va_start( arg_begin, format );
62
63 ret = _vsnprintf( buf, sizeof(buf), format, arg_begin );
64
65 va_end( arg_begin );
66
67 DPRINT("WARNING: %s\n", buf);
68
69 return ret;
70}
71
72void error( char *format, ... ) {
73 char buf[0x100];
74 va_list arg_begin;
75 va_start( arg_begin, format );
76
77 _vsnprintf( buf, sizeof(buf), format, arg_begin );
78
79 va_end( arg_begin );
80
81 DPRINT1("ERROR: %s\n", buf);
82}
83
84int16_t getShort( unsigned char *data ) {
85 return (int16_t) ntohs(*(int16_t*) data);
86}
87
88u_int16_t getUShort( unsigned char *data ) {
89 return (u_int16_t) ntohs(*(u_int16_t*) data);
90}
91
92int32_t getLong( unsigned char *data ) {
93 return (int32_t) ntohl(*(u_int32_t*) data);
94}
95
96u_int32_t getULong( unsigned char *data ) {
97 return ntohl(*(u_int32_t*)data);
98}
99
100int addr_eq( struct iaddr a, struct iaddr b ) {
101 return a.len == b.len && !memcmp( a.iabuf, b.iabuf, a.len );
102}
103
104void *dmalloc( int size, char *name ) { return malloc( size ); }
105
107 /* What a strange dance */
108 struct client_config *config;
109 char ComputerName [MAX_COMPUTERNAME_LENGTH + 1];
110 LPSTR lpCompName;
111 DWORD ComputerNameSize = sizeof ComputerName / sizeof ComputerName[0];
112
113 if ((ifi!= NULL) && (ifi->client->config != NULL))
114 config = ifi->client->config;
115 else
116 {
117 warn("util.c read_client_conf poorly implemented!");
118 return 0;
119 }
120
121
122 GetComputerName(ComputerName, & ComputerNameSize);
123 debug("Hostname: %s, length: %lu",
124 ComputerName, ComputerNameSize);
125 /* This never gets freed since it's only called once */
126 lpCompName =
127 HeapAlloc(GetProcessHeap(), 0, ComputerNameSize + 1);
128 if (lpCompName !=NULL) {
129 memcpy(lpCompName, ComputerName, ComputerNameSize + 1);
130 /* Send our hostname, some dhcpds use this to update DNS */
131 config->send_options[DHO_HOST_NAME].data = (u_int8_t*)lpCompName;
132 config->send_options[DHO_HOST_NAME].len = ComputerNameSize;
133 debug("Hostname: %s, length: %d",
134 config->send_options[DHO_HOST_NAME].data,
135 config->send_options[DHO_HOST_NAME].len);
136 } else {
137 error("Failed to allocate heap for hostname");
138 }
139 /* Both Linux and Windows send this */
140 config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].data =
141 ifi->hw_address.haddr;
142 config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].len =
143 ifi->hw_address.hlen;
144
145 /* Setup the requested option list */
146 config->requested_options
147 [config->requested_option_count++] = DHO_SUBNET_MASK;
148 config->requested_options
149 [config->requested_option_count++] = DHO_BROADCAST_ADDRESS;
150 config->requested_options
151 [config->requested_option_count++] = DHO_TIME_OFFSET;
152 config->requested_options
153 [config->requested_option_count++] = DHO_ROUTERS;
154 config->requested_options
155 [config->requested_option_count++] = DHO_DOMAIN_NAME;
156 config->requested_options
157 [config->requested_option_count++] = DHO_DOMAIN_NAME_SERVERS;
158 config->requested_options
159 [config->requested_option_count++] = DHO_HOST_NAME;
160 config->requested_options
161 [config->requested_option_count++] = DHO_NTP_SERVERS;
162
163 warn("util.c read_client_conf poorly implemented!");
164 return 0;
165}
166
168 struct iaddr bcast = { 0 };
169 return bcast;
170}
171
173 struct iaddr bcast = { 0 };
174 return bcast;
175}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
#define DPRINT1
Definition: precomp.h:8
int note(char *format,...)
Definition: util.c:12
int addr_eq(struct iaddr a, struct iaddr b)
Definition: util.c:100
struct iaddr broadcast_addr(struct iaddr addr, struct iaddr mask)
Definition: util.c:167
int32_t getLong(unsigned char *data)
Definition: util.c:92
u_int16_t getUShort(unsigned char *data)
Definition: util.c:88
char * piaddr(struct iaddr addr)
Definition: util.c:6
u_int32_t getULong(unsigned char *data)
Definition: util.c:96
void * dmalloc(int size, char *name)
Definition: util.c:104
int16_t getShort(unsigned char *data)
Definition: util.c:84
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
Definition: util.c:172
int read_client_conf(struct interface_info *ifi)
Definition: util.c:106
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
#define DHO_DHCP_CLIENT_IDENTIFIER
Definition: dhcp.h:157
#define DHO_TIME_OFFSET
Definition: dhcp.h:98
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
#define DHO_ROUTERS
Definition: dhcp.h:99
#define DHO_SUBNET_MASK
Definition: dhcp.h:97
#define malloc
Definition: debug_ros.c:4
struct config_s config
#define NULL
Definition: types.h:112
INT32 int32_t
Definition: types.h:71
INT16 int16_t
Definition: types.h:70
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLsizeiptr size
Definition: glext.h:5919
GLenum GLint GLuint mask
Definition: glext.h:6028
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
GLenum const GLvoid * addr
Definition: glext.h:9621
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
#define inet_ntoa(addr)
Definition: inet.h:100
#define debug(msg)
Definition: key_call.c:71
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define ntohl(x)
Definition: module.h:205
#define ntohs(x)
Definition: module.h:210
#define warn(...)
unsigned int u_int32_t
Definition: rosdhcp.h:35
unsigned short u_int16_t
Definition: rosdhcp.h:34
unsigned char u_int8_t
Definition: rosdhcp.h:33
#define warning(s)
Definition: debug.h:83
#define DPRINT
Definition: sndvol32.h:73
Definition: dhcpd.h:125
struct client_state * client
Definition: dhcpd.h:238
struct hardware hw_address
Definition: dhcpd.h:229
Definition: name.c:39
int ret
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
#define GetComputerName
Definition: winbase.h:3800
#define _vsnprintf
Definition: xmlstorage.h:202
char * LPSTR
Definition: xmlstorage.h:182