ReactOS  0.4.12-dev-57-g7050ac4
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.

Referenced by bootp(), and dhcp().

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
unsigned char iabuf[16]
Definition: dhcpd.h:127
int len
Definition: dhcpd.h:126

◆ broadcast_addr()

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

Definition at line 167 of file util.c.

Referenced by priv_script_write_params().

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

◆ debug()

int debug ( char format,
  ... 
)

Definition at line 27 of file util.c.

Referenced by read_client_conf().

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

◆ dmalloc()

void* dmalloc ( int  size,
char name 
)

Definition at line 104 of file util.c.

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

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

◆ error()

void error ( char format,
  ... 
)

Definition at line 72 of file util.c.

Referenced by map_view_of_file(), and read_client_conf().

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

◆ getLong()

int32_t getLong ( unsigned char data)

Definition at line 92 of file util.c.

Referenced by pretty_print_option().

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

◆ getShort()

int16_t getShort ( unsigned char data)

Definition at line 84 of file util.c.

Referenced by pretty_print_option().

84  {
85  return (int16_t) ntohs(*(int16_t*) data);
86 }
#define ntohs(x)
Definition: module.h:208
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
INT16 int16_t
Definition: types.h:70

◆ getULong()

u_int32_t getULong ( unsigned char data)

Definition at line 96 of file util.c.

Referenced by dhcpack(), and pretty_print_option().

96  {
97  return ntohl(*(u_int32_t*)data);
98 }
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned int u_int32_t
Definition: rosdhcp.h:35
#define ntohl(x)
Definition: module.h:203

◆ getUShort()

u_int16_t getUShort ( unsigned char data)

Definition at line 88 of file util.c.

Referenced by cons_options(), and pretty_print_option().

88  {
89  return (u_int16_t) ntohs(*(u_int16_t*) data);
90 }
#define ntohs(x)
Definition: module.h:208
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned short u_int16_t
Definition: rosdhcp.h:34

◆ note()

int note ( char format,
  ... 
)

Definition at line 12 of file util.c.

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

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

◆ piaddr()

char* piaddr ( struct iaddr  addr)

Definition at line 6 of file util.c.

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

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 }
unsigned char iabuf[16]
Definition: dhcpd.h:127
#define inet_ntoa(addr)
Definition: inet.h:100
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
static struct sockaddr_in sa
Definition: adnsresfilter.c:69

◆ read_client_conf()

int read_client_conf ( struct interface_info ifi)

Definition at line 106 of file util.c.

Referenced by AdapterDiscoveryThread().

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 */
141  ifi->hw_address.haddr;
143  ifi->hw_address.hlen;
144 
145  /* Setup the requested option list */
146  config->requested_options
148  config->requested_options
150  config->requested_options
152  config->requested_options
153  [config->requested_option_count++] = DHO_ROUTERS;
154  config->requested_options
156  config->requested_options
158  config->requested_options
160  config->requested_options
162 
163  warn("util.c read_client_conf poorly implemented!");
164  return 0;
165 }
struct config_s config
#define GetComputerName
Definition: winbase.h:3614
struct client_state * client
Definition: dhcpd.h:238
char * LPSTR
Definition: xmlstorage.h:182
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_ROUTERS
Definition: dhcp.h:99
#define DHO_DHCP_CLIENT_IDENTIFIER
Definition: dhcp.h:157
unsigned char u_int8_t
Definition: rosdhcp.h:33
#define DHO_TIME_OFFSET
Definition: dhcp.h:98
int warn(char *format,...)
Definition: util.c:42
smooth NULL
Definition: ftsmooth.c:416
int debug(char *format,...)
Definition: util.c:27
int requested_option_count
Definition: dhcpd.h:193
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
void error(char *format,...)
Definition: util.c:72
struct hardware hw_address
Definition: dhcpd.h:229
#define DHO_SUBNET_MASK
Definition: dhcp.h:97
unsigned long DWORD
Definition: ntddk_ex.h:95
u_int8_t requested_options[256]
Definition: dhcpd.h:192
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
struct option_data send_options[256]
Definition: dhcpd.h:190

◆ subnet_number()

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

Definition at line 172 of file util.c.

Referenced by priv_script_write_params().

172  {
173  struct iaddr bcast = { 0 };
174  return bcast;
175 }
Definition: dhcpd.h:125

◆ warn()

int warn ( char format,
  ... 
)

Definition at line 42 of file util.c.

Referenced by read_client_conf().

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

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