ReactOS  0.4.12-dev-51-ge94618b
util.c
Go to the documentation of this file.
1 #include <rosdhcp.h>
2 
3 #define NDEBUG
4 #include <reactos/debug.h>
5 
6 char *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 
12 int 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 
27 int 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 
42 int 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 
57 int 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 
72 void 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 
84 int16_t getShort( unsigned char *data ) {
85  return (int16_t) ntohs(*(int16_t*) data);
86 }
87 
88 u_int16_t getUShort( unsigned char *data ) {
89  return (u_int16_t) ntohs(*(u_int16_t*) data);
90 }
91 
92 int32_t getLong( unsigned char *data ) {
93  return (int32_t) ntohl(*(u_int32_t*) data);
94 }
95 
96 u_int32_t getULong( unsigned char *data ) {
97  return ntohl(*(u_int32_t*)data);
98 }
99 
100 int addr_eq( struct iaddr a, struct iaddr b ) {
101  return a.len == b.len && !memcmp( a.iabuf, b.iabuf, a.len );
102 }
103 
104 void *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 */
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 }
166 
168  struct iaddr bcast = { 0 };
169  return bcast;
170 }
171 
173  struct iaddr bcast = { 0 };
174  return bcast;
175 }
int addr_eq(struct iaddr a, struct iaddr b)
Definition: util.c:100
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
int16_t getShort(unsigned char *data)
Definition: util.c:84
struct config_s config
int read_client_conf(struct interface_info *ifi)
Definition: util.c:106
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
unsigned char iabuf[16]
Definition: dhcpd.h:127
#define GetComputerName
Definition: winbase.h:3614
struct client_state * client
Definition: dhcpd.h:238
u_int16_t getUShort(unsigned char *data)
Definition: util.c:88
char * LPSTR
Definition: xmlstorage.h:182
#define ntohs(x)
Definition: module.h:208
GLint GLint GLsizei GLsizei GLsizei GLint GLenum format
Definition: gl.h:1546
#define DHO_NTP_SERVERS
Definition: dhcp.h:138
#define DHO_ROUTERS
Definition: dhcp.h:99
int len
Definition: dhcpd.h:126
GLenum GLint GLuint mask
Definition: glext.h:6028
#define va_end(ap)
Definition: acmsvcex.h:90
#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
int note(char *format,...)
Definition: util.c:12
smooth NULL
Definition: ftsmooth.c:416
char * va_list
Definition: acmsvcex.h:78
void DPRINT(...)
Definition: polytest.cpp:61
#define inet_ntoa(addr)
Definition: inet.h:100
struct iaddr subnet_number(struct iaddr addr, struct iaddr mask)
Definition: util.c:172
int debug(char *format,...)
Definition: util.c:27
int requested_option_count
Definition: dhcpd.h:193
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
int32_t getLong(unsigned char *data)
Definition: util.c:92
GLsizeiptr size
Definition: glext.h:5919
#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
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
unsigned short u_int16_t
Definition: rosdhcp.h:34
int ret
u_int8_t requested_options[256]
Definition: dhcpd.h:192
GLenum const GLvoid * addr
Definition: glext.h:9621
Definition: dhcpd.h:125
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
unsigned int u_int32_t
Definition: rosdhcp.h:35
INT32 int32_t
Definition: types.h:71
struct in_addr sin_addr
Definition: winsock.h:512
#define MAX_COMPUTERNAME_LENGTH
Definition: winbase.h:240
#define DHO_BROADCAST_ADDRESS
Definition: dhcp.h:124
struct iaddr broadcast_addr(struct iaddr addr, struct iaddr mask)
Definition: util.c:167
#define DHO_HOST_NAME
Definition: dhcp.h:108
#define va_start(ap, A)
Definition: acmsvcex.h:91
char * piaddr(struct iaddr addr)
Definition: util.c:6
u_int32_t getULong(unsigned char *data)
Definition: util.c:96
#define _vsnprintf
Definition: xmlstorage.h:202
#define DPRINT1
Definition: precomp.h:8
Definition: name.c:36
#define DHO_DOMAIN_NAME
Definition: dhcp.h:111
int warning(char *format,...)
Definition: util.c:57
#define malloc
Definition: debug_ros.c:4
INT16 int16_t
Definition: types.h:70
#define DHO_DOMAIN_NAME_SERVERS
Definition: dhcp.h:102
GLboolean GLboolean GLboolean GLboolean a
Definition: glext.h:6204
void * dmalloc(int size, char *name)
Definition: util.c:104
struct option_data send_options[256]
Definition: dhcpd.h:190
#define ntohl(x)
Definition: module.h:203