Author: amunger
Date: Wed Apr 5 20:38:03 2006
New Revision: 21474
URL:
http://svn.reactos.ru/svn/reactos?rev=21474&view=rev
Log:
DHCP Client fixes and enhancements
Set the correct hardware type flag. Fixes bug 651.
Send option 12 on discovery, allows some DHCP servers to dynamically update DNS.
Send option 61 for good measure. We use the MAC address as some other OSes do.
Modified:
trunk/reactos/base/services/dhcp/adapter.c
trunk/reactos/base/services/dhcp/dhclient.c
trunk/reactos/base/services/dhcp/util.c
Modified: trunk/reactos/base/services/dhcp/adapter.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/base/services/dhcp/adapter.…
==============================================================================
--- trunk/reactos/base/services/dhcp/adapter.c (original)
+++ trunk/reactos/base/services/dhcp/adapter.c Wed Apr 5 20:38:03 2006
@@ -258,6 +258,12 @@
Adapter->IfMib.dwPhysAddrLen);
Adapter->DhclientInfo.hw_address.hlen =
Adapter->IfMib.dwPhysAddrLen;
+ /* I'm not sure where else to set this, but
+ some DHCP servers won't take a zero.
+ We checked the hardware type earlier in
+ the if statement. */
+ Adapter->DhclientInfo.hw_address.htype =
+ HTYPE_ETHER;
if( DhcpSocket == INVALID_SOCKET ) {
DhcpSocket =
Modified: trunk/reactos/base/services/dhcp/dhclient.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/base/services/dhcp/dhclient…
==============================================================================
--- trunk/reactos/base/services/dhcp/dhclient.c (original)
+++ trunk/reactos/base/services/dhcp/dhclient.c Wed Apr 5 20:38:03 2006
@@ -114,6 +114,13 @@
time_t scripttime;
+/* XXX Added this since it's not in the NDK ;0/ */
+ULONG
+NTAPI
+RtlRandom(
+ IN OUT PULONG Seed
+ );
+
/* XXX Implement me */
int check_arp( struct interface_info *ip, struct client_lease *lp ) {
return 1;
@@ -221,6 +228,7 @@
state_reboot(void *ipp)
{
struct interface_info *ip = ipp;
+ ULONG foo = (ULONG) GetTickCount();
/* If we don't remember an active lease, go straight to INIT. */
if (!ip->client->active || ip->client->active->is_bootp) {
@@ -234,7 +242,7 @@
/* make_request doesn't initialize xid because it normally comes
from the DHCPDISCOVER, but we haven't sent a DHCPDISCOVER,
so pick an xid now. */
- ip->client->xid = rand();
+ ip->client->xid = RtlRandom(&foo);
/* Make a DHCPREQUEST packet, and set appropriate per-interface
flags. */
@@ -1229,6 +1237,7 @@
struct tree_cache *options[256];
struct tree_cache option_elements[256];
int i;
+ ULONG foo = (ULONG) GetTickCount();
memset(option_elements, 0, sizeof(option_elements));
memset(options, 0, sizeof(options));
@@ -1287,7 +1296,7 @@
ip->client->packet.htype = ip->hw_address.htype;
ip->client->packet.hlen = ip->hw_address.hlen;
ip->client->packet.hops = 0;
- ip->client->packet.xid = rand();
+ ip->client->packet.xid = RtlRandom(&foo);
ip->client->packet.secs = 0; /* filled in by send_discover. */
ip->client->packet.flags = 0;
@@ -1996,11 +2005,11 @@
struct in_addr jnk;
int i = 0;
- note("Input: %s\n", buf);
+ note("Input: %s", buf);
do {
tmp = strtok(buf, " ");
- note("got %s\n", tmp);
+ note("got %s", tmp);
if( tmp && inet_aton(tmp, &jnk) ) i++;
buf = NULL;
} while( tmp );
Modified: trunk/reactos/base/services/dhcp/util.c
URL:
http://svn.reactos.ru/svn/reactos/trunk/reactos/base/services/dhcp/util.c?r…
==============================================================================
--- trunk/reactos/base/services/dhcp/util.c (original)
+++ trunk/reactos/base/services/dhcp/util.c Wed Apr 5 20:38:03 2006
@@ -3,6 +3,8 @@
#define NDEBUG
#include <reactos/debug.h>
+
+extern struct interface_info *ifi;
char *piaddr( struct iaddr addr ) {
struct sockaddr_in sa;
@@ -95,7 +97,33 @@
void *dmalloc( int size, char *name ) { return malloc( size ); }
int read_client_conf(void) {
- error("util.c read_client_conf not implemented!");
+ /* What a strage dance */
+ struct client_config *config = ifi->client->config;
+ char ComputerName [MAX_COMPUTERNAME_LENGTH + 1];
+ DWORD ComputerNameSize = sizeof ComputerName / sizeof ComputerName[0];
+
+ GetComputerName(ComputerName, & ComputerNameSize);
+ /* This never gets freed since it's only called once */
+ LPSTR lpCompName =
+ HeapAlloc(GetProcessHeap(), 0, strlen(ComputerName) + 1);
+ if (lpCompName !=NULL) {
+ GetComputerName(lpCompName, & ComputerNameSize);
+ /* Send our hostname, some dhcpds use this to update DNS */
+ config->send_options[DHO_HOST_NAME].data = strlwr(lpCompName);
+ config->send_options[DHO_HOST_NAME].len = strlen(ComputerName);
+ debug("Hostname: %s, length: %d",
+ config->send_options[DHO_HOST_NAME].data,
+ config->send_options[DHO_HOST_NAME].len);
+ } else {
+ error("Failed to allocate heap for hostname");
+ }
+ /* Both Linux and Windows send this */
+ config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].data =
+ ifi->hw_address.haddr;
+ config->send_options[DHO_DHCP_CLIENT_IDENTIFIER].len =
+ ifi->hw_address.hlen;
+
+ warn("util.c read_client_conf poorly implemented!");
return 0;
}