ReactOS 0.4.16-dev-91-g764881a
adapter.c File Reference
#include <rosdhcp.h>
#include <reactos/debug.h>
Include dependency graph for adapter.c:

Go to the source code of this file.

Macros

#define NDEBUG
 

Functions

PCHARGetSubkeyNames (PCHAR MainKeyName, PCHAR Append)
 
PCHAR RegReadString (HKEY Root, PCHAR Subkey, PCHAR Value)
 
HKEY FindAdapterKey (PDHCP_ADAPTER Adapter)
 
BOOL PrepareAdapterForService (PDHCP_ADAPTER Adapter)
 
void AdapterInit ()
 
int InterfaceConnected (const MIB_IFROW *IfEntry)
 
BOOL IsReconnectHackNeeded (PDHCP_ADAPTER Adapter, const MIB_IFROW *IfEntry)
 
DWORD WINAPI AdapterDiscoveryThread (LPVOID Context)
 
HANDLE StartAdapterDiscovery (HANDLE hStopEvent)
 
void AdapterStop ()
 
PDHCP_ADAPTER AdapterFindIndex (unsigned int indx)
 
PDHCP_ADAPTER AdapterFindName (const WCHAR *name)
 
PDHCP_ADAPTER AdapterFindInfo (struct interface_info *ip)
 
PDHCP_ADAPTER AdapterFindByHardwareAddress (u_int8_t haddr[16], u_int8_t hlen)
 
PDHCP_ADAPTER AdapterGetFirst ()
 
PDHCP_ADAPTER AdapterGetNext (PDHCP_ADAPTER This)
 
void if_register_send (struct interface_info *ip)
 
void if_register_receive (struct interface_info *ip)
 

Variables

HANDLE hAdapterStateChangedEvent
 
SOCKET DhcpSocket = INVALID_SOCKET
 
static LIST_ENTRY AdapterList
 
static WSADATA wsd
 

Macro Definition Documentation

◆ NDEBUG

#define NDEBUG

Definition at line 3 of file adapter.c.

Function Documentation

◆ AdapterDiscoveryThread()

DWORD WINAPI AdapterDiscoveryThread ( LPVOID  Context)

Definition at line 291 of file adapter.c.

291 {
293 DWORD Error, Size = sizeof(MIB_IFTABLE);
294 PDHCP_ADAPTER Adapter = NULL;
296 struct interface_info *ifi = NULL;
297 struct protocol *proto;
298 int i, AdapterCount = 0, Broadcast;
299
300 while (TRUE)
301 {
302 DH_DbgPrint(MID_TRACE,("Getting Adapter List...\n"));
303
304 while( (Error = GetIfTable(Table, &Size, 0 )) ==
306 DH_DbgPrint(MID_TRACE,("Error %d, New Buffer Size: %d\n", Error, Size));
307 free( Table );
309 }
310
311 if( Error != NO_ERROR )
312 {
313 /* HACK: We are waiting until TCP/IP starts */
314 Sleep(2000);
315 continue;
316 }
317
318 DH_DbgPrint(MID_TRACE,("Got Adapter List (%d entries)\n", Table->dwNumEntries));
319
320 for( i = Table->dwNumEntries - 1; i >= 0; i-- ) {
321 DH_DbgPrint(MID_TRACE,("Getting adapter %d attributes\n",
322 Table->table[i].dwIndex));
323
324 ApiLock();
325
326 if ((Adapter = AdapterFindByHardwareAddress(Table->table[i].bPhysAddr, Table->table[i].dwPhysAddrLen)))
327 {
329
330 /* This is an existing adapter */
331 if (InterfaceConnected(&Table->table[i])) {
332 /* We're still active so we stay in the list */
333 ifi = &Adapter->DhclientInfo;
334
335 /* This is a hack because IP helper API sucks */
336 if (IsReconnectHackNeeded(Adapter, &Table->table[i]))
337 {
338 /* This handles a disconnect/reconnect */
339
340 if (proto)
342 Adapter->DhclientInfo.client->state = S_INIT;
343
344 /* These are already invalid since the media state change */
345 Adapter->RouterMib.dwForwardNextHop = 0;
346 Adapter->NteContext = 0;
347
348 add_protocol(Adapter->DhclientInfo.name,
349 Adapter->DhclientInfo.rfdesc,
350 got_one, &Adapter->DhclientInfo);
351 state_init(&Adapter->DhclientInfo);
352
354 }
355
356 } else {
357 if (proto)
359
360 /* We've lost our link so out we go */
361 RemoveEntryList(&Adapter->ListEntry);
362 free(Adapter);
363 }
364
365 ApiUnlock();
366
367 continue;
368 }
369
370 ApiUnlock();
371
372 Adapter = (DHCP_ADAPTER*) calloc( sizeof( DHCP_ADAPTER ) + Table->table[i].dwMtu, 1 );
373
374 if( Adapter && Table->table[i].dwType == MIB_IF_TYPE_ETHERNET && InterfaceConnected(&Table->table[i])) {
375 memcpy( &Adapter->IfMib, &Table->table[i],
376 sizeof(Adapter->IfMib) );
377 Adapter->DhclientInfo.client = &Adapter->DhclientState;
378 Adapter->DhclientInfo.rbuf = Adapter->recv_buf;
379 Adapter->DhclientInfo.rbuf_max = Table->table[i].dwMtu;
380 Adapter->DhclientInfo.rbuf_len =
381 Adapter->DhclientInfo.rbuf_offset = 0;
382 memcpy(Adapter->DhclientInfo.hw_address.haddr,
383 Adapter->IfMib.bPhysAddr,
384 Adapter->IfMib.dwPhysAddrLen);
385 Adapter->DhclientInfo.hw_address.hlen = Adapter->IfMib.dwPhysAddrLen;
386
387 /* I'm not sure where else to set this, but
388 some DHCP servers won't take a zero.
389 We checked the hardware type earlier in
390 the if statement. */
391 Adapter->DhclientInfo.hw_address.htype = HTYPE_ETHER;
392
393 if( DhcpSocket == INVALID_SOCKET ) {
394 DhcpSocket =
395 Adapter->DhclientInfo.rfdesc =
396 Adapter->DhclientInfo.wfdesc =
398
399 if (DhcpSocket != INVALID_SOCKET) {
400
401 /* Allow broadcast on this socket */
402 Broadcast = 1;
406 (const char *)&Broadcast,
407 sizeof(Broadcast));
408
409 Adapter->ListenAddr.sin_family = AF_INET;
410 Adapter->ListenAddr.sin_port = htons(LOCAL_PORT);
411 Adapter->BindStatus =
412 (bind( Adapter->DhclientInfo.rfdesc,
413 (struct sockaddr *)&Adapter->ListenAddr,
414 sizeof(Adapter->ListenAddr) ) == 0) ?
415 0 : WSAGetLastError();
416 } else {
417 error("socket() failed: %d\n", WSAGetLastError());
418 }
419 } else {
420 Adapter->DhclientInfo.rfdesc =
421 Adapter->DhclientInfo.wfdesc = DhcpSocket;
422 }
423
424 Adapter->DhclientConfig.timeout = DHCP_PANIC_TIMEOUT;
425 Adapter->DhclientConfig.initial_interval = DHCP_DISCOVER_INTERVAL;
426 Adapter->DhclientConfig.retry_interval = DHCP_DISCOVER_INTERVAL;
427 Adapter->DhclientConfig.select_interval = 1;
428 Adapter->DhclientConfig.reboot_timeout = DHCP_REBOOT_TIMEOUT;
429 Adapter->DhclientConfig.backoff_cutoff = DHCP_BACKOFF_MAX;
430 Adapter->DhclientState.interval =
431 Adapter->DhclientConfig.retry_interval;
432
433 if( PrepareAdapterForService( Adapter ) ) {
434 Adapter->DhclientInfo.next = ifi;
435 ifi = &Adapter->DhclientInfo;
436
438
439 if (Adapter->DhclientInfo.client->state == S_INIT)
440 {
441 add_protocol(Adapter->DhclientInfo.name,
442 Adapter->DhclientInfo.rfdesc,
443 got_one, &Adapter->DhclientInfo);
444
445 state_init(&Adapter->DhclientInfo);
446 }
447
448 ApiLock();
449 InsertTailList( &AdapterList, &Adapter->ListEntry );
450 AdapterCount++;
452 ApiUnlock();
453 } else { free( Adapter ); Adapter = 0; }
454 } else { free( Adapter ); Adapter = 0; }
455
456 if( !Adapter )
457 DH_DbgPrint(MID_TRACE,("Adapter %d was rejected\n",
458 Table->table[i].dwIndex));
459 }
460#if 0
462 if (Error != NO_ERROR)
463 break;
464#else
466 {
467 DPRINT("Stopping the discovery thread!\n");
468 break;
469 }
470#endif
471 }
472
473 if (Table)
474 free(Table);
475
476 DPRINT("Adapter discovery thread terminated! (Error: %d)\n", Error);
477
478 return Error;
479}
HANDLE hAdapterStateChangedEvent
Definition: dhcpcsvc.c:20
SOCKET DhcpSocket
Definition: adapter.c:8
int InterfaceConnected(const MIB_IFROW *IfEntry)
Definition: adapter.c:199
PDHCP_ADAPTER AdapterFindByHardwareAddress(u_int8_t haddr[16], u_int8_t hlen)
Definition: adapter.c:540
BOOL PrepareAdapterForService(PDHCP_ADAPTER Adapter)
Definition: adapter.c:153
static LIST_ENTRY AdapterList
Definition: adapter.c:9
BOOL IsReconnectHackNeeded(PDHCP_ADAPTER Adapter, const MIB_IFROW *IfEntry)
Definition: adapter.c:210
VOID ApiLock()
Definition: api.c:22
VOID ApiUnlock()
Definition: api.c:26
void add_protocol(char *name, int fd, void(*handler)(struct protocol *), void *local)
Definition: dispatch.c:342
void remove_protocol(struct protocol *proto)
Definition: dispatch.c:359
void got_one(struct protocol *l)
Definition: dispatch.c:194
struct protocol * find_protocol_by_adapter(struct interface_info *info)
Definition: dispatch.c:412
int read_client_conf(struct interface_info *ifi)
Definition: util.c:106
#define MID_TRACE
Definition: debug.h:15
#define DH_DbgPrint(_t_, _x_)
Definition: debug.h:49
#define HTYPE_ETHER
Definition: dhcp.h:85
BOOL Error
Definition: chkdsk.c:66
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define free
Definition: debug_ros.c:5
#define malloc
Definition: debug_ros.c:4
void state_init(void *ipp)
Definition: dhclient.c:210
HANDLE hStopEvent
Definition: dhcpcsvc.c:19
@ S_INIT
Definition: dhcpd.h:172
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define IPPROTO_UDP
Definition: ip.h:197
#define AF_INET
Definition: tcpip.h:117
#define RemoveEntryList(Entry)
Definition: env_spec_w32.h:986
#define InsertTailList(ListHead, Entry)
unsigned long DWORD
Definition: ntddk_ex.h:95
ASMGENDATA Table[]
Definition: genincdata.c:61
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
struct _MIB_IFTABLE * PMIB_IFTABLE
struct _MIB_IFTABLE MIB_IFTABLE
DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped)
DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder)
#define MIB_IF_TYPE_ETHERNET
Definition: ipifcons.h:223
#define error(str)
Definition: mkdosfs.c:1605
#define memcpy(s1, s2, n)
Definition: mkisofs.h:878
#define htons(x)
Definition: module.h:215
#define DHCP_REBOOT_TIMEOUT
Definition: rosdhcp.h:27
#define DHCP_PANIC_TIMEOUT
Definition: rosdhcp.h:28
#define DHCP_DISCOVER_INTERVAL
Definition: rosdhcp.h:26
#define DHCP_BACKOFF_MAX
Definition: rosdhcp.h:29
#define calloc
Definition: rosglue.h:14
#define DPRINT
Definition: sndvol32.h:73
INT WSAAPI setsockopt(IN SOCKET s, IN INT level, IN INT optname, IN CONST CHAR FAR *optval, IN INT optlen)
Definition: sockctrl.c:421
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
ULONG NteContext
Definition: rosdhcp.h:70
MIB_IPFORWARDROW RouterMib
Definition: rosdhcp.h:67
unsigned char recv_buf[1]
Definition: rosdhcp.h:76
struct interface_info DhclientInfo
Definition: rosdhcp.h:71
struct client_state DhclientState
Definition: rosdhcp.h:72
struct client_config DhclientConfig
Definition: rosdhcp.h:73
LIST_ENTRY ListEntry
Definition: rosdhcp.h:65
struct sockaddr_in ListenAddr
Definition: rosdhcp.h:74
unsigned int BindStatus
Definition: rosdhcp.h:75
MIB_IFROW IfMib
Definition: rosdhcp.h:66
UCHAR bPhysAddr[MAXLEN_PHYSADDR]
Definition: ifmib.h:43
DWORD dwPhysAddrLen
Definition: ifmib.h:42
DWORD dwForwardNextHop
Definition: ipmib.h:74
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
PVOID HANDLE
Definition: typedefs.h:73
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define WAIT_OBJECT_0
Definition: winbase.h:406
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define INVALID_SOCKET
Definition: winsock.h:332
#define SOCK_DGRAM
Definition: winsock.h:336
#define SOL_SOCKET
Definition: winsock.h:398
#define SO_BROADCAST
Definition: winsock.h:183

Referenced by StartAdapterDiscovery().

◆ AdapterFindByHardwareAddress()

PDHCP_ADAPTER AdapterFindByHardwareAddress ( u_int8_t  haddr[16],
u_int8_t  hlen 
)

Definition at line 540 of file adapter.c.

540 {
541 PDHCP_ADAPTER Adapter;
542 PLIST_ENTRY ListEntry;
543
544 for(ListEntry = AdapterList.Flink;
545 ListEntry != &AdapterList;
546 ListEntry = ListEntry->Flink) {
547 Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
548 if (Adapter->DhclientInfo.hw_address.hlen == hlen &&
549 !memcmp(Adapter->DhclientInfo.hw_address.haddr,
550 haddr,
551 hlen)) return Adapter;
552 }
553
554 return NULL;
555}
int memcmp(void *Buffer1, void *Buffer2, ACPI_SIZE Count)
Definition: utclib.c:112
Definition: typedefs.h:120
struct _LIST_ENTRY * Flink
Definition: typedefs.h:121
#define CONTAINING_RECORD(address, type, field)
Definition: typedefs.h:260

Referenced by AdapterDiscoveryThread(), and got_one().

◆ AdapterFindIndex()

PDHCP_ADAPTER AdapterFindIndex ( unsigned int  indx)

Definition at line 498 of file adapter.c.

498 {
499 PDHCP_ADAPTER Adapter;
500 PLIST_ENTRY ListEntry;
501
502 for( ListEntry = AdapterList.Flink;
503 ListEntry != &AdapterList;
504 ListEntry = ListEntry->Flink ) {
505 Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
506 if( Adapter->IfMib.dwIndex == indx ) return Adapter;
507 }
508
509 return NULL;
510}
DWORD dwIndex
Definition: ifmib.h:38

Referenced by DSGetAdapterInfo(), DSLeaseIpAddress(), DSQueryHWInfo(), DSReleaseIpAddressLease(), DSRenewIpAddressLease(), and DSStaticRefreshParams().

◆ AdapterFindInfo()

PDHCP_ADAPTER AdapterFindInfo ( struct interface_info ip)

Definition at line 526 of file adapter.c.

526 {
527 PDHCP_ADAPTER Adapter;
528 PLIST_ENTRY ListEntry;
529
530 for( ListEntry = AdapterList.Flink;
531 ListEntry != &AdapterList;
532 ListEntry = ListEntry->Flink ) {
533 Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
534 if( ip == &Adapter->DhclientInfo ) return Adapter;
535 }
536
537 return NULL;
538}
Definition: dhcpd.h:62

Referenced by bind_lease(), got_one(), send_request(), and state_panic().

◆ AdapterFindName()

PDHCP_ADAPTER AdapterFindName ( const WCHAR name)

Definition at line 512 of file adapter.c.

512 {
513 PDHCP_ADAPTER Adapter;
514 PLIST_ENTRY ListEntry;
515
516 for( ListEntry = AdapterList.Flink;
517 ListEntry != &AdapterList;
518 ListEntry = ListEntry->Flink ) {
519 Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
520 if( !wcsicmp( Adapter->IfMib.wszName, name ) ) return Adapter;
521 }
522
523 return NULL;
524}
#define wcsicmp
Definition: compat.h:15
WCHAR wszName[MAX_INTERFACE_NAME_LEN]
Definition: ifmib.h:37
Definition: name.c:39

◆ AdapterGetFirst()

PDHCP_ADAPTER AdapterGetFirst ( )

Definition at line 557 of file adapter.c.

557 {
558 if( IsListEmpty( &AdapterList ) ) return NULL; else {
559 return CONTAINING_RECORD
560 ( AdapterList.Flink, DHCP_ADAPTER, ListEntry );
561 }
562}
#define IsListEmpty(ListHead)
Definition: env_spec_w32.h:954

◆ AdapterGetNext()

PDHCP_ADAPTER AdapterGetNext ( PDHCP_ADAPTER  This)

Definition at line 564 of file adapter.c.

565{
566 if( This->ListEntry.Flink == &AdapterList ) return NULL;
567 return CONTAINING_RECORD
568 ( This->ListEntry.Flink, DHCP_ADAPTER, ListEntry );
569}

◆ AdapterInit()

void AdapterInit ( )

Definition at line 192 of file adapter.c.

192 {
193 WSAStartup(0x0101,&wsd);
194
196}
static WSADATA wsd
Definition: adapter.c:10
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define InitializeListHead(ListHead)
Definition: env_spec_w32.h:944

Referenced by init_client().

◆ AdapterStop()

void AdapterStop ( )

Definition at line 485 of file adapter.c.

485 {
486 PLIST_ENTRY ListEntry;
487 PDHCP_ADAPTER Adapter;
488 ApiLock();
489 while( !IsListEmpty( &AdapterList ) ) {
490 ListEntry = (PLIST_ENTRY)RemoveHeadList( &AdapterList );
491 Adapter = CONTAINING_RECORD( ListEntry, DHCP_ADAPTER, ListEntry );
492 free( Adapter );
493 }
494 ApiUnlock();
495 WSACleanup();
496}
#define RemoveHeadList(ListHead)
Definition: env_spec_w32.h:964
struct _LIST_ENTRY * PLIST_ENTRY
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

◆ FindAdapterKey()

HKEY FindAdapterKey ( PDHCP_ADAPTER  Adapter)

Definition at line 105 of file adapter.c.

105 {
106 int i = 0;
107 PCHAR EnumKeyName =
108 "SYSTEM\\CurrentControlSet\\Control\\Class\\"
109 "{4D36E972-E325-11CE-BFC1-08002BE10318}";
110 PCHAR TargetKeyNameStart =
111 "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
112 PCHAR TargetKeyName = NULL;
113 PCHAR *EnumKeysLinkage = GetSubkeyNames( EnumKeyName, "\\Linkage" );
114 PCHAR *EnumKeysTop = GetSubkeyNames( EnumKeyName, "" );
115 PCHAR RootDevice = NULL;
116 HKEY EnumKey, OutKey = NULL;
118
119 if( !EnumKeysLinkage || !EnumKeysTop ) goto cleanup;
120
121 Error = RegOpenKey( HKEY_LOCAL_MACHINE, EnumKeyName, &EnumKey );
122
123 if( Error ) goto cleanup;
124
125 for( i = 0; EnumKeysLinkage[i]; i++ ) {
126 RootDevice = RegReadString
127 ( EnumKey, EnumKeysLinkage[i], "RootDevice" );
128
129 if( RootDevice &&
130 !strcmp( RootDevice, Adapter->DhclientInfo.name ) ) {
131 TargetKeyName =
132 (CHAR*) malloc( strlen( TargetKeyNameStart ) +
133 strlen( RootDevice ) + 1);
134 if( !TargetKeyName ) goto cleanup;
135 sprintf( TargetKeyName, "%s%s",
136 TargetKeyNameStart, RootDevice );
137 Error = RegCreateKeyExA( HKEY_LOCAL_MACHINE, TargetKeyName, 0, NULL, 0, KEY_READ, NULL, &OutKey, NULL );
138 break;
139 } else {
140 free( RootDevice ); RootDevice = 0;
141 }
142 }
143
144cleanup:
145 if( RootDevice ) free( RootDevice );
146 if( EnumKeysLinkage ) free( EnumKeysLinkage );
147 if( EnumKeysTop ) free( EnumKeysTop );
148 if( TargetKeyName ) free( TargetKeyName );
149
150 return OutKey;
151}
int strcmp(const char *String1, const char *String2)
Definition: utclib.c:469
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
PCHAR * GetSubkeyNames(PCHAR MainKeyName, PCHAR Append)
Definition: adapter.c:12
PCHAR RegReadString(HKEY Root, PCHAR Subkey, PCHAR Value)
Definition: adapter.c:61
#define ERROR_SUCCESS
Definition: deptool.c:10
LONG WINAPI RegCreateKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD Reserved, _In_ LPSTR lpClass, _In_ DWORD dwOptions, _In_ REGSAM samDesired, _In_ LPSECURITY_ATTRIBUTES lpSecurityAttributes, _Out_ PHKEY phkResult, _Out_ LPDWORD lpdwDisposition)
Definition: reg.c:1034
static void cleanup(void)
Definition: main.c:1335
static LONG WINAPI EnumKey(HANDLE hcKey, DWORD dwIndex, LPWSTR pszName, PDWORD pcchName, PFILETIME pftLastWriteTime, HANDLE hSpooler)
Definition: localmon.c:169
#define sprintf(buf, format,...)
Definition: sprintf.c:55
#define KEY_READ
Definition: nt_native.h:1023
char * PCHAR
Definition: typedefs.h:51
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12
#define RegOpenKey
Definition: winreg.h:519
char CHAR
Definition: xmlstorage.h:175

Referenced by PrepareAdapterForService().

◆ GetSubkeyNames()

PCHAR * GetSubkeyNames ( PCHAR  MainKeyName,
PCHAR  Append 
)

Definition at line 12 of file adapter.c.

12 {
13 int i = 0;
15 HKEY MainKey;
16 PCHAR *Out, OutKeyName;
17 SIZE_T CharTotal = 0, AppendLen = 1 + strlen(Append);
18 DWORD MaxSubKeyLen = 0, MaxSubKeys = 0;
19
20 Error = RegOpenKey( HKEY_LOCAL_MACHINE, MainKeyName, &MainKey );
21
22 if( Error ) return NULL;
23
25 ( MainKey,
26 NULL, NULL, NULL,
27 &MaxSubKeys, &MaxSubKeyLen,
28 NULL, NULL, NULL, NULL, NULL, NULL );
29
30 MaxSubKeyLen++;
31 DH_DbgPrint(MID_TRACE,("MaxSubKeys: %d, MaxSubKeyLen %d\n",
32 MaxSubKeys, MaxSubKeyLen));
33
34 CharTotal = (sizeof(PCHAR) + MaxSubKeyLen + AppendLen) * (MaxSubKeys + 1);
35
36 DH_DbgPrint(MID_TRACE,("AppendLen: %d, CharTotal: %d\n",
37 AppendLen, CharTotal));
38
39 Out = (CHAR**) malloc( CharTotal );
40 OutKeyName = ((PCHAR)&Out[MaxSubKeys+1]);
41
42 if( !Out ) { RegCloseKey( MainKey ); return NULL; }
43
44 i = 0;
45 do {
46 Out[i] = OutKeyName;
47 Error = RegEnumKey( MainKey, i, OutKeyName, MaxSubKeyLen );
48 if( !Error ) {
49 strcat( OutKeyName, Append );
50 DH_DbgPrint(MID_TRACE,("[%d]: %s\n", i, OutKeyName));
51 OutKeyName += strlen(OutKeyName) + 1;
52 i++;
53 } else Out[i] = 0;
54 } while( Error == ERROR_SUCCESS );
55
56 RegCloseKey( MainKey );
57
58 return Out;
59}
char * strcat(char *DstString, const char *SrcString)
Definition: utclib.c:568
#define RegCloseKey(hKey)
Definition: registry.h:49
@ Out
#define PCHAR
Definition: match.c:90
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define RegEnumKey
Definition: winreg.h:509
#define RegQueryInfoKey
Definition: winreg.h:521

Referenced by FindAdapterKey().

◆ if_register_receive()

void if_register_receive ( struct interface_info ip)

Definition at line 575 of file adapter.c.

575 {
576}

◆ if_register_send()

void if_register_send ( struct interface_info ip)

Definition at line 571 of file adapter.c.

571 {
572
573}

◆ InterfaceConnected()

int InterfaceConnected ( const MIB_IFROW IfEntry)

Definition at line 199 of file adapter.c.

200{
201 if (IfEntry->dwOperStatus == IF_OPER_STATUS_CONNECTED ||
203 return 1;
204
205 DH_DbgPrint(MID_TRACE,("Interface %d is down\n", IfEntry->dwIndex));
206 return 0;
207}
@ IF_OPER_STATUS_CONNECTED
Definition: ipifcons.h:242
@ IF_OPER_STATUS_OPERATIONAL
Definition: ipifcons.h:243
INTERNAL_IF_OPER_STATUS dwOperStatus
Definition: ifmib.h:45

Referenced by AdapterDiscoveryThread().

◆ IsReconnectHackNeeded()

BOOL IsReconnectHackNeeded ( PDHCP_ADAPTER  Adapter,
const MIB_IFROW IfEntry 
)

Definition at line 210 of file adapter.c.

211{
212 struct protocol *proto;
213 PIP_ADAPTER_INFO AdapterInfo, Orig;
214 DWORD Size, Ret;
215 char *ZeroAddress = "0.0.0.0";
216
218
219 if (Adapter->DhclientInfo.client->state == S_BOUND && !proto)
220 return FALSE;
221
222 if (Adapter->DhclientInfo.client->state != S_BOUND &&
223 Adapter->DhclientInfo.client->state != S_STATIC)
224 return FALSE;
225
226 ApiUnlock();
227
228 Orig = AdapterInfo = HeapAlloc(GetProcessHeap(), 0, sizeof(IP_ADAPTER_INFO));
229 Size = sizeof(IP_ADAPTER_INFO);
230 if (!AdapterInfo)
231 {
232 ApiLock();
233 return FALSE;
234 }
235
236 Ret = GetAdaptersInfo(AdapterInfo, &Size);
237 if (Ret == ERROR_BUFFER_OVERFLOW)
238 {
239 HeapFree(GetProcessHeap(), 0, AdapterInfo);
240 AdapterInfo = HeapAlloc(GetProcessHeap(), 0, Size);
241 if (!AdapterInfo)
242 {
243 ApiLock();
244 return FALSE;
245 }
246
247 if (GetAdaptersInfo(AdapterInfo, &Size) != NO_ERROR)
248 {
249 ApiLock();
250 return FALSE;
251 }
252
253 Orig = AdapterInfo;
254 for (; AdapterInfo != NULL; AdapterInfo = AdapterInfo->Next)
255 {
256 if (AdapterInfo->Index == IfEntry->dwIndex)
257 break;
258 }
259
260 if (AdapterInfo == NULL)
261 {
262 HeapFree(GetProcessHeap(), 0, Orig);
263 ApiLock();
264 return FALSE;
265 }
266 }
267 else if (Ret != NO_ERROR)
268 {
269 HeapFree(GetProcessHeap(), 0, Orig);
270 ApiLock();
271 return FALSE;
272 }
273
274 if (!strcmp(AdapterInfo->IpAddressList.IpAddress.String, ZeroAddress))
275 {
276 HeapFree(GetProcessHeap(), 0, Orig);
277 ApiLock();
278 return TRUE;
279 }
280 else
281 {
282 HeapFree(GetProcessHeap(), 0, Orig);
283 ApiLock();
284 return FALSE;
285 }
286}
@ S_BOUND
Definition: dhcpd.h:175
@ S_STATIC
Definition: dhcpd.h:178
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
struct _IP_ADAPTER_INFO IP_ADAPTER_INFO
char String[4 *4]
Definition: iptypes.h:42
IP_ADDR_STRING IpAddressList
Definition: iptypes.h:63
struct _IP_ADAPTER_INFO * Next
Definition: iptypes.h:53
IP_ADDRESS_STRING IpAddress
Definition: iptypes.h:47
#define ERROR_BUFFER_OVERFLOW
Definition: winerror.h:185

Referenced by AdapterDiscoveryThread().

◆ PrepareAdapterForService()

BOOL PrepareAdapterForService ( PDHCP_ADAPTER  Adapter)

Definition at line 153 of file adapter.c.

153 {
154 HKEY AdapterKey;
155 DWORD Error = ERROR_SUCCESS, DhcpEnabled, Length = sizeof(DWORD);
156
157 Adapter->DhclientState.config = &Adapter->DhclientConfig;
158 strncpy(Adapter->DhclientInfo.name, (char*)Adapter->IfMib.bDescr,
159 sizeof(Adapter->DhclientInfo.name));
160
161 AdapterKey = FindAdapterKey( Adapter );
162 if( AdapterKey )
163 {
164 Error = RegQueryValueEx(AdapterKey, "EnableDHCP", NULL, NULL, (LPBYTE)&DhcpEnabled, &Length);
165
166 if (Error != ERROR_SUCCESS || Length != sizeof(DWORD))
167 DhcpEnabled = 1;
168
169 CloseHandle(AdapterKey);
170 }
171 else
172 {
173 /* DHCP enabled by default */
174 DhcpEnabled = 1;
175 }
176
177 if( !DhcpEnabled ) {
178 /* Non-automatic case */
179 DbgPrint("DHCPCSVC: Adapter Name: [%s] (static)\n", Adapter->DhclientInfo.name);
180
181 Adapter->DhclientState.state = S_STATIC;
182 } else {
183 /* Automatic case */
184 DbgPrint("DHCPCSVC: Adapter Name: [%s] (dynamic)\n", Adapter->DhclientInfo.name);
185
186 Adapter->DhclientInfo.client->state = S_INIT;
187 }
188
189 return TRUE;
190}
char * strncpy(char *DstString, const char *SrcString, ACPI_SIZE Count)
Definition: utclib.c:427
HKEY FindAdapterKey(PDHCP_ADAPTER Adapter)
Definition: adapter.c:105
#define CloseHandle
Definition: compat.h:739
#define DbgPrint
Definition: hal.h:12
#define DWORD
Definition: nt_native.h:44
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
BYTE bDescr[MAXLEN_IFDESCR]
Definition: ifmib.h:60
unsigned char * LPBYTE
Definition: typedefs.h:53
#define RegQueryValueEx
Definition: winreg.h:524

Referenced by AdapterDiscoveryThread().

◆ RegReadString()

PCHAR RegReadString ( HKEY  Root,
PCHAR  Subkey,
PCHAR  Value 
)

Definition at line 61 of file adapter.c.

61 {
62 PCHAR SubOut = NULL;
63 DWORD SubOutLen = 0, Error = 0;
64 HKEY ValueKey = NULL;
65
66 DH_DbgPrint(MID_TRACE,("Looking in %x:%s:%s\n", Root, Subkey, Value ));
67
68 if( Subkey && strlen(Subkey) ) {
69 if( RegOpenKey( Root, Subkey, &ValueKey ) != ERROR_SUCCESS )
70 goto regerror;
71 } else ValueKey = Root;
72
73 DH_DbgPrint(MID_TRACE,("Got Key %x\n", ValueKey));
74
75 if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
76 (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS )
77 goto regerror;
78
79 DH_DbgPrint(MID_TRACE,("Value %s has size %d\n", Value, SubOutLen));
80
81 if( !(SubOut = (CHAR*) malloc(SubOutLen)) )
82 goto regerror;
83
84 if( (Error = RegQueryValueEx( ValueKey, Value, NULL, NULL,
85 (LPBYTE)SubOut, &SubOutLen )) != ERROR_SUCCESS )
86 goto regerror;
87
88 DH_DbgPrint(MID_TRACE,("Value %s is %s\n", Value, SubOut));
89
90 goto cleanup;
91
92regerror:
93 if( SubOut ) { free( SubOut ); SubOut = NULL; }
95 if( ValueKey && ValueKey != Root ) {
96 DH_DbgPrint(MID_TRACE,("Closing key %x\n", ValueKey));
97 RegCloseKey( ValueKey );
98 }
99
100 DH_DbgPrint(MID_TRACE,("Returning %x with error %d\n", SubOut, Error));
101
102 return SubOut;
103}
root entry for file system trees
Definition: entries.h:148
_Must_inspect_result_ _In_ WDFKEY _In_ PCUNICODE_STRING _Out_opt_ PUSHORT _Inout_opt_ PUNICODE_STRING Value
Definition: wdfregistry.h:413

Referenced by FindAdapterKey().

◆ StartAdapterDiscovery()

HANDLE StartAdapterDiscovery ( HANDLE  hStopEvent)

Definition at line 481 of file adapter.c.

481 {
483}
DWORD WINAPI AdapterDiscoveryThread(LPVOID Context)
Definition: adapter.c:291
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137

Referenced by ServiceMain().

Variable Documentation

◆ AdapterList

◆ DhcpSocket

SOCKET DhcpSocket = INVALID_SOCKET

Definition at line 8 of file adapter.c.

Referenced by AdapterDiscoveryThread(), dispatch(), and ServiceMain().

◆ hAdapterStateChangedEvent

HANDLE hAdapterStateChangedEvent
extern

Definition at line 20 of file dhcpcsvc.c.

Referenced by AdapterDiscoveryThread().

◆ wsd

WSADATA wsd
static

Definition at line 10 of file adapter.c.

Referenced by AdapterInit(), openlog(), and wmain().