ReactOS 0.4.15-dev-7958-gcd0bb1a
util.c File Reference
#include <rosdhcp.h>
#include <reactos/debug.h>
Include dependency graph for util.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

charpiaddr (struct iaddr addr)
 
int note (char *format,...)
 
int debug (char *format,...)
 
int warn (char *format,...)
 
int warning (char *format,...)
 
void error (char *format,...)
 
int16_t getShort (unsigned char *data)
 
u_int16_t getUShort (unsigned char *data)
 
int32_t getLong (unsigned char *data)
 
u_int32_t getULong (unsigned char *data)
 
int addr_eq (struct iaddr a, struct iaddr b)
 
voiddmalloc (int size, char *name)
 
int read_client_conf (struct interface_info *ifi)
 
struct iaddr broadcast_addr (struct iaddr addr, struct iaddr mask)
 
struct iaddr subnet_number (struct iaddr addr, struct iaddr mask)
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file util.c.

Function Documentation

◆ addr_eq()

int addr_eq ( struct iaddr  a,
struct iaddr  b 
)

Definition at line 100 of file util.c.

100 {
101 return a.len == b.len && !memcmp( a.iabuf, b.iabuf, a.len );
102}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204

Referenced by bootp(), and dhcp().

◆ broadcast_addr()

struct iaddr broadcast_addr ( struct iaddr  addr,
struct iaddr  mask 
)

Definition at line 167 of file util.c.

167 {
168 struct iaddr bcast = { 0 };
169 return bcast;
170}
Definition: dhcpd.h:125

Referenced by priv_script_write_params().

◆ debug()

int debug ( char format,
  ... 
)

Definition at line 27 of file util.c.

27 {
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}
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
#define DPRINT
Definition: sndvol32.h:71
int ret
#define _vsnprintf
Definition: xmlstorage.h:202

◆ dmalloc()

void * dmalloc ( int  size,
char name 
)

Definition at line 104 of file util.c.

104{ return malloc( size ); }
#define malloc
Definition: debug_ros.c:4
GLsizeiptr size
Definition: glext.h:5919

Referenced by cons(), do_host_lookup(), enter_dns_host(), tree_concat(), tree_const(), and tree_evaluate().

◆ error()

void error ( char format,
  ... 
)

Definition at line 72 of file util.c.

72 {
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}
#define DPRINT1
Definition: precomp.h:8

◆ getLong()

int32_t getLong ( unsigned char data)

Definition at line 92 of file util.c.

92 {
93 return (int32_t) ntohl(*(u_int32_t*) data);
94}
INT32 int32_t
Definition: types.h:71
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
#define ntohl(x)
Definition: module.h:205
unsigned int u_int32_t
Definition: rosdhcp.h:35

Referenced by pretty_print_option().

◆ getShort()

int16_t getShort ( unsigned char data)

Definition at line 84 of file util.c.

84 {
85 return (int16_t) ntohs(*(int16_t*) data);
86}
INT16 int16_t
Definition: types.h:70
#define ntohs(x)
Definition: module.h:210

Referenced by pretty_print_option().

◆ getULong()

u_int32_t getULong ( unsigned char data)

Definition at line 96 of file util.c.

96 {
97 return ntohl(*(u_int32_t*)data);
98}

Referenced by dhcpack(), and pretty_print_option().

◆ getUShort()

u_int16_t getUShort ( unsigned char data)

Definition at line 88 of file util.c.

88 {
89 return (u_int16_t) ntohs(*(u_int16_t*) data);
90}
unsigned short u_int16_t
Definition: rosdhcp.h:34

Referenced by cons_options(), and pretty_print_option().

◆ note()

int note ( char format,
  ... 
)

Definition at line 12 of file util.c.

12 {
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}

Referenced by bind_lease(), bootp(), dhcp(), dhcpack(), dhcpnak(), dhcpoffer(), do_packet(), image_check_alternate(), image_locate_build_id_target(), ipv4addrs(), PlayNote(), send_decline(), send_discover(), send_packet(), send_request(), state_panic(), and StopNote().

◆ piaddr()

char * piaddr ( struct iaddr  addr)

Definition at line 6 of file util.c.

6 {
7 struct sockaddr_in sa;
8 memcpy(&sa.sin_addr,addr.iabuf,sizeof(sa.sin_addr));
9 return inet_ntoa( sa.sin_addr );
10}
static struct sockaddr_in sa
Definition: adnsresfilter.c:69
GLenum const GLvoid * addr
Definition: glext.h:9621
#define inet_ntoa(addr)
Definition: inet.h:100
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878

Referenced by bind_lease(), bootp(), dhcp(), dhcpack(), dhcpnak(), dhcpoffer(), priv_script_write_params(), set_name_servers(), setup_adapter(), and write_client_lease().

◆ read_client_conf()

int read_client_conf ( struct interface_info ifi)

Definition at line 106 of file util.c.

106 {
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}
#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
struct config_s config
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
unsigned long DWORD
Definition: ntddk_ex.h:95
#define debug(msg)
Definition: key_call.c:71
#define error(str)
Definition: mkdosfs.c:1605
#define warn(...)
unsigned char u_int8_t
Definition: rosdhcp.h:33
struct client_state * client
Definition: dhcpd.h:238
struct hardware hw_address
Definition: dhcpd.h:229
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:243
#define GetComputerName
Definition: winbase.h:3800
char * LPSTR
Definition: xmlstorage.h:182

Referenced by AdapterDiscoveryThread().

◆ subnet_number()

struct iaddr subnet_number ( struct iaddr  addr,
struct iaddr  mask 
)

Definition at line 172 of file util.c.

172 {
173 struct iaddr bcast = { 0 };
174 return bcast;
175}

Referenced by priv_script_write_params().

◆ warn()

int warn ( char format,
  ... 
)

Definition at line 42 of file util.c.

42 {
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}

◆ warning()

int warning ( char format,
  ... 
)

Definition at line 57 of file util.c.

57 {
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}