Changeset 432
- Timestamp:
- 02/06/05 18:18:17 (6 years ago)
- Files:
-
- 1 modified
Legend:
- Unmodified
- Added
- Removed
-
branches/CaptiveDNS/wifidog/src/dnsserver_thread.c
r431 r432 43 43 #include "dnsserver_thread.h" 44 44 45 /** Accepts DNS requests , replies to all IN A requests with the internalIP address45 /** Accepts DNS requests: For certain hostnames replies with their real IP, for all others replies with the gateway's IP address 46 46 @param arg NULL 47 47 @todo This thread loops infinitely, need a watchdog to verify that it is still running? … … 218 218 outputanswerheader.length = htons(sizeof(answerip)); 219 219 220 /* Now we populate answerip with what we tell them220 /* Now we populate answerip with what the answer should be 221 221 */ 222 222 authhostname = config_get_config()->auth_servers->authserv_hostname; … … 227 227 authip = wd_gethostbyname(authhostname); 228 228 if (authip) { 229 debug(LOG_DEBUG, "Requested IP is for the hostname of the active auth server"); 229 230 memcpy(&answerip, authip, sizeof(answerip)); 230 231 free(authip); 231 232 } 232 233 else { 234 debug(LOG_NOTICE, "Requested IP is for the hostname of the active auth server but I failed to resolve it"); 233 235 /* XXX: Failed to resolve auth server hostname - Loop back to us ?*/ 234 236 inet_aton(config_get_config()->gw_address, &answerip); … … 239 241 * They're asking for something else - point them to us 240 242 */ 243 debug(LOG_DEBUG, "Requested IP is for an arbitrary hostname"); 241 244 inet_aton(config_get_config()->gw_address, &answerip); 242 245 } 243 246 244 247 /* Calculate size of output pieces together */ 245 outputlength = sizeof(outputheader) + strlen(hostname) + 1 + sizeof(outputqueryfooter) + sizeof(outputanswerheader) + sizeof(answerip); 248 outputlength = 249 sizeof(outputheader) 250 + strlen(hostname) 251 + 1 252 + sizeof(outputqueryfooter) 253 + sizeof(outputanswerheader) 254 + sizeof(answerip) 255 ; 256 246 257 outputbuffer = malloc(outputlength); 247 258 if (!outputbuffer) { … … 251 262 else { 252 263 /* 253 * XXX: dirty - must match above malloc size pieces for outputbuffer 264 * Fill outputbuffer with the concatenated pieces 265 * Be careful - anything added here must be accounted for in the above outputlength calculation 254 266 */ 255 memcpy(outputbuffer, &outputheader, sizeof(outputheader)); 256 memcpy(outputbuffer + sizeof(outputheader), hostname, strlen(hostname)); 257 memcpy(outputbuffer + sizeof(outputheader) + strlen(hostname), "", 1); 258 memcpy(outputbuffer + sizeof(outputheader) + strlen(hostname) + 1, &outputqueryfooter, sizeof(outputqueryfooter)); 259 memcpy(outputbuffer + sizeof(outputheader) + strlen(hostname) + 1 + sizeof(outputqueryfooter), &outputanswerheader, sizeof(outputanswerheader)); 260 memcpy(outputbuffer + sizeof(outputheader) + strlen(hostname) + 1 + sizeof(outputqueryfooter) + sizeof(outputanswerheader), &answerip, sizeof(answerip)); 267 temp = outputbuffer; 268 269 memcpy(temp, &outputheader, sizeof(outputheader)); 270 temp += sizeof(outputheader); 271 272 memcpy(temp, hostname, strlen(hostname)); 273 temp += strlen(hostname); 274 275 memcpy(temp, "", 1); 276 temp += 1; 277 278 memcpy(temp, &outputqueryfooter, sizeof(outputqueryfooter)); 279 temp += sizeof(outputqueryfooter); 280 281 memcpy(temp, &outputanswerheader, sizeof(outputanswerheader)); 282 temp += sizeof(outputanswerheader); 283 284 memcpy(temp, &answerip, sizeof(answerip)); 285 temp += sizeof(answerip); 261 286 262 287 /*
