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 106 int read_client_conf(struct interface_info *ifi) { 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 167 struct iaddr broadcast_addr( struct iaddr addr, struct iaddr mask ) { 168 struct iaddr bcast = { 0 }; 169 return bcast; 170 } 171 172 struct iaddr subnet_number( struct iaddr addr, struct iaddr mask ) { 173 struct iaddr bcast = { 0 }; 174 return bcast; 175 } 176