5 #include <reactos/debug.h>
7 char *piaddr( struct iaddr addr
) {
9 memcpy(&sa
.sin_addr
,addr
.iabuf
,sizeof(sa
.sin_addr
));
10 return inet_ntoa( sa
.sin_addr
);
13 int note( char *format
, ... ) {
17 va_start( arg_begin
, format
);
19 ret
= _vsnprintf( buf
, sizeof(buf
), format
, arg_begin
);
21 DPRINT("NOTE: %s\n", buf
);
26 int debug( char *format
, ... ) {
30 va_start( arg_begin
, format
);
32 ret
= _vsnprintf( buf
, sizeof(buf
), format
, arg_begin
);
34 DPRINT("DEBUG: %s\n", buf
);
39 int warn( char *format
, ... ) {
43 va_start( arg_begin
, format
);
45 ret
= _vsnprintf( buf
, sizeof(buf
), format
, arg_begin
);
47 DPRINT("WARN: %s\n", buf
);
52 int warning( char *format
, ... ) {
56 va_start( arg_begin
, format
);
58 ret
= _vsnprintf( buf
, sizeof(buf
), format
, arg_begin
);
60 DPRINT("WARNING: %s\n", buf
);
65 void error( char *format
, ... ) {
68 va_start( arg_begin
, format
);
70 _vsnprintf( buf
, sizeof(buf
), format
, arg_begin
);
72 DPRINT1("ERROR: %s\n", buf
);
75 int16_t getShort( unsigned char *data
) {
76 return (int16_t) ntohs(*(int16_t*) data
);
79 u_int16_t
getUShort( unsigned char *data
) {
80 return (u_int16_t
) ntohs(*(u_int16_t
*) data
);
83 int32_t getLong( unsigned char *data
) {
84 return (int32_t) ntohl(*(u_int32_t
*) data
);
87 u_int32_t
getULong( unsigned char *data
) {
88 return ntohl(*(u_int32_t
*)data
);
91 int addr_eq( struct iaddr a
, struct iaddr b
) {
92 return a
.len
== b
.len
&& !memcmp( a
.iabuf
, b
.iabuf
, a
.len
);
95 void *dmalloc( int size
, char *name
) { return malloc( size
); }
97 int read_client_conf(struct interface_info
*ifi
) {
98 /* What a strange dance */
99 struct client_config
*config
;
100 char ComputerName
[MAX_COMPUTERNAME_LENGTH
+ 1];
102 DWORD ComputerNameSize
= sizeof ComputerName
/ sizeof ComputerName
[0];
104 if ((ifi
!= NULL
) && (ifi
->client
->config
!= NULL
))
105 config
= ifi
->client
->config
;
108 warn("util.c read_client_conf poorly implemented!");
113 GetComputerName(ComputerName
, & ComputerNameSize
);
114 debug("Hostname: %s, length: %lu",
115 ComputerName
, ComputerNameSize
);
116 /* This never gets freed since it's only called once */
118 HeapAlloc(GetProcessHeap(), 0, ComputerNameSize
+ 1);
119 if (lpCompName
!=NULL
) {
120 memcpy(lpCompName
, ComputerName
, ComputerNameSize
+ 1);
121 /* Send our hostname, some dhcpds use this to update DNS */
122 config
->send_options
[DHO_HOST_NAME
].data
= (u_int8_t
*)lpCompName
;
123 config
->send_options
[DHO_HOST_NAME
].len
= ComputerNameSize
;
124 debug("Hostname: %s, length: %d",
125 config
->send_options
[DHO_HOST_NAME
].data
,
126 config
->send_options
[DHO_HOST_NAME
].len
);
128 error("Failed to allocate heap for hostname");
130 /* Both Linux and Windows send this */
131 config
->send_options
[DHO_DHCP_CLIENT_IDENTIFIER
].data
=
132 ifi
->hw_address
.haddr
;
133 config
->send_options
[DHO_DHCP_CLIENT_IDENTIFIER
].len
=
134 ifi
->hw_address
.hlen
;
136 /* Setup the requested option list */
137 config
->requested_options
138 [config
->requested_option_count
++] = DHO_SUBNET_MASK
;
139 config
->requested_options
140 [config
->requested_option_count
++] = DHO_BROADCAST_ADDRESS
;
141 config
->requested_options
142 [config
->requested_option_count
++] = DHO_TIME_OFFSET
;
143 config
->requested_options
144 [config
->requested_option_count
++] = DHO_ROUTERS
;
145 config
->requested_options
146 [config
->requested_option_count
++] = DHO_DOMAIN_NAME
;
147 config
->requested_options
148 [config
->requested_option_count
++] = DHO_DOMAIN_NAME_SERVERS
;
149 config
->requested_options
150 [config
->requested_option_count
++] = DHO_HOST_NAME
;
151 config
->requested_options
152 [config
->requested_option_count
++] = DHO_NTP_SERVERS
;
154 warn("util.c read_client_conf poorly implemented!");
158 struct iaddr
broadcast_addr( struct iaddr addr
, struct iaddr mask
) {
159 struct iaddr bcast
= { 0 };
163 struct iaddr
subnet_number( struct iaddr addr
, struct iaddr mask
) {
164 struct iaddr bcast
= { 0 };