-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIPHelper.c
792 lines (707 loc) · 19 KB
/
IPHelper.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
////////////////////////////////////////////////////////////////////////////////
//
// General including files
//
// Including the files for the system.
//
// These including files are generally used in different operation system.
//
////////////////////////////////////////////////////////////////////////////////
#include "Global.h"
//For windows.
#ifdef _MICROSOFT_WINDOWS
#include <windows.h>
#include <Iphlpapi.h>
#endif
////////////////////////////////////////////////////////////////////////////////
//
// Genernal definations.
//
////////////////////////////////////////////////////////////////////////////////
//Adapters Information List
IP_ADAPTER_INFO* theAdaptersInformationList = NULL;
//Interface Information List
IP_INTERFACE_INFO* theInterfaceInformationList = NULL;
////////////////////////////////////////////////////////////////////////////////
//
// Load adapters information list.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL LoadAdaptersInformationList()
{
//Size.
_UINT32 nSize;
//Status
_UINT32 nStatus;
#ifdef _DEBUG
assert(theAdaptersInformationList == NULL);
#endif
//Set size.
nSize = 0;
//Get size of adapters information.
nStatus = GetAdaptersInfo(NULL,&nSize);
//Check result.
if(nStatus != ERROR_BUFFER_OVERFLOW)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::LoadAdaptersInformationList : fail to get size !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
#ifdef _DEBUG
PrintLine(stdout,"IPHelper::LoadAdaptersInformationList : IP_ADAPTER_INFO(%d)/%d !",sizeof(IP_ADAPTER_INFO),nSize);
#endif
//Create adapters information list.
theAdaptersInformationList = (IP_ADAPTER_INFO *)malloc(nSize);
#ifdef _DEBUG
assert(theAdaptersInformationList != NULL);
#endif
//Clear adapters information list.
memset(theAdaptersInformationList,0,nSize);
//Get adapters information list.
nStatus = GetAdaptersInfo(theAdaptersInformationList,&nSize);
//Check result.
if(nStatus != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::LoadAdaptersInformationList : fail to get list !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Show adapters information list
//
////////////////////////////////////////////////////////////////////////////////
void ShowAdaptersInformationList()
{
//Count
_UINT32 nCount = 0;
//Index.
_INT32 nIndex = 0;
//Current member.
IP_ADAPTER_INFO* pCurrent;
#ifdef _DEBUG
assert(theAdaptersInformationList != NULL);
#endif
//Print.
PrintLine(stdout,"IPHelper::ShowAdaptersInformationList : show adapters information !");
//Get current memeber.
pCurrent = theAdaptersInformationList;
//Check index.
do
{
//Print.
PrintLine(stdout,"Adapter[%d]",nIndex);
//Print.
PrintLine(stdout,"\tAdapter Index: %d",pCurrent->Index);
//Print.
PrintLine(stdout,"\tAdapter Name: %s",pCurrent->AdapterName);
//Print.
PrintLine(stdout,"\tMAC Address : %02x-%02x-%02x-%02x-%02x-%02x",
pCurrent->Address[0],pCurrent->Address[1],pCurrent->Address[2],
pCurrent->Address[3],pCurrent->Address[4],pCurrent->Address[5]);
//Print.
PrintLine(stdout,"\tDescription: %s",pCurrent->Description);
//Print.
PrintLine(stdout,"\tIP Address : %s",pCurrent->IpAddressList.IpAddress.String);
//Print
PrintLine(stdout,"\tIP Mask : %s",pCurrent->IpAddressList.IpMask.String);
//Print.
PrintLine(stdout,"\tGateway IP : %s",pCurrent->GatewayList.IpAddress.String);
//Add index.
nIndex ++;
//Set next.
pCurrent = pCurrent->Next;
}while(pCurrent != NULL);
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter information by index.
//
////////////////////////////////////////////////////////////////////////////////
IP_ADAPTER_INFO* GetAdapterInformationByIndex(_UINT32 nAdapterIndex)
{
//Current member.
IP_ADAPTER_INFO* pCurrent;
#ifdef _DEBUG
assert(theAdaptersInformationList != NULL);
#endif
//Get current memeber.
pCurrent = theAdaptersInformationList;
//Check index.
do
{
//Check result.
if(pCurrent->Index == nAdapterIndex)
{
//Return result.
return pCurrent;
}
//Set next.
pCurrent = pCurrent->Next;
}while(pCurrent != NULL);
//Return null.
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter ip count.
//
////////////////////////////////////////////////////////////////////////////////
_INT32 GetAdapterIPCount(IP_ADAPTER_INFO* lpAdapterInformation)
{
//Count
_INT32 nCount = 0;
//IP Address
IP_ADDR_STRING* lpAddress;
#ifdef _DEBUG
assert(lpAdapterInformation != NULL);
#endif
//Get header.
lpAddress = &lpAdapterInformation->IpAddressList;
//Check result.
while(lpAddress != NULL)
{
//Add count.
nCount ++;
//Set next.
lpAddress = lpAddress->Next;
}
//Return count.
return nCount;
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter MAC address.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL GetAdapterMACAddress(_UINT32 nAdapterIndex,_MAC6 macAddress)
{
//Index.
_INT32 nIndex;
//Adapter.
IP_ADAPTER_INFO* pAdapter;
//Get adapter.
pAdapter = GetAdapterInformationByIndex(nAdapterIndex);
//Check result.
if(pAdapter != NULL)
{
//Copy address.
for(nIndex = 0;nIndex < sizeof(_MAC6);nIndex ++)
{
//Set mac address.
macAddress[nIndex] = pAdapter->Address[nIndex];
}
//Return true.
return _TRUE;
}
//Return false.
return _FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter DHCP status.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL GetAdapterDHCPStatus(_UINT32 nAdapterIndex,_BOOL* lpStatus)
{
//Current member.
IP_ADAPTER_INFO* pCurrent;
#ifdef _DEBUG
assert(theAdaptersInformationList != NULL);
#endif
//Get current memeber.
pCurrent = theAdaptersInformationList;
//Check index.
do
{
//Check result.
if(pCurrent->Index == nAdapterIndex)
{
//Set status.
*lpStatus = pCurrent->DhcpEnabled;
//Return true.
return _TRUE;
}
//Set next.
pCurrent = pCurrent->Next;
}while(pCurrent != NULL);
//Return false.
return _FALSE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Delete adapter addresses.
//
////////////////////////////////////////////////////////////////////////////////
void DeleteAdapterAddresses(_UINT32 nAdapterIndex)
{
//Result.
_UINT32 nResult;
//Adapter.
IP_ADAPTER_INFO* pAdapter;
//Address.
IP_ADDR_STRING* lpAddress;
//Get adapter.
pAdapter = GetAdapterInformationByIndex(nAdapterIndex);
//Check result.
if(pAdapter != NULL)
{
//Get address.
lpAddress = &pAdapter->IpAddressList;
//Do while.
while(lpAddress != NULL)
{
//Delete ip address.
nResult = DeleteIPAddress(lpAddress->Context);
//Check result.
if(nResult == NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::DeleteAdapterAddresses : ip was deleted !",
LOG_TUNNEL | LOG_EXCEPTION);
//Print.
PrintLine(stdout,"\tIP = %s",lpAddress->IpAddress.String);
PrintLine(stdout,"\tNetmask = %s",lpAddress->IpMask.String);
#endif
}
else
{
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_EXCEPTION,
"IPHelper::DeleteAdapterAddresses : fail(%d) to delete ip !",
nResult);
#endif
}
//Get next.
lpAddress = lpAddress->Next;
}
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Unload adapters information list.
//
////////////////////////////////////////////////////////////////////////////////
void UnloadAdaptersInformationList()
{
//Check result.
if(theAdaptersInformationList != NULL)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::UnloadAdaptersInformationList : list was freed !",
LOG_TUNNEL | LOG_INFORMATION);
#endif
//Free it.
free(theAdaptersInformationList);
//Clear it.
theAdaptersInformationList = NULL;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Load interface information list.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL LoadInterfaceInformationList()
{
//Size.
_UINT32 nSize;
//Status
_UINT32 nStatus;
#ifdef _DEBUG
assert(theInterfaceInformationList == NULL);
#endif
//Set size.
nSize = 0;
//Get size of interface information.
nStatus = GetInterfaceInfo(NULL,&nSize);
//Check result.
if(nStatus != ERROR_INSUFFICIENT_BUFFER)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::LoadInterfaceInformationList : fail to get size !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
#ifdef _DEBUG
PrintLine(stdout,"IPHelper::LoadInterfaceInformationList : IP_INTERFACE_INFO(%d)/%d !",sizeof(IP_INTERFACE_INFO),nSize);
#endif
//Create interface information list.
theInterfaceInformationList = (IP_INTERFACE_INFO *)malloc(nSize);
#ifdef _DEBUG
assert(theInterfaceInformationList != NULL);
#endif
//Clear interface information list.
memset(theInterfaceInformationList,0,nSize);
//Get interface information list.
nStatus = GetInterfaceInfo(theInterfaceInformationList,&nSize);
//Check result.
if(nStatus != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::LoadInterfaceInformationList : fail to get list !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Show interface information list
//
////////////////////////////////////////////////////////////////////////////////
void ShowInterfaceInformationList()
{
//Index.
_INT32 nIndex = 0;
#ifdef _DEBUG
assert(theInterfaceInformationList != NULL);
#endif
//Print.
PrintLine(stdout,"IPHelper::ShowInterfaceInformationList : show interfaces information !");
//Check index.
while(nIndex < theInterfaceInformationList->NumAdapters)
{
//Print.
PrintLine(stdout,"\tInterface[%d]",nIndex);
//Print.
PrintLine(stdout,"\tAdapter Index = %ld",theInterfaceInformationList->Adapter[nIndex].Index);
//Print.
PrintLine(stdout,"\tAdapter Name = \"%ws\"",theInterfaceInformationList->Adapter[nIndex].Name);
//Add index.
nIndex ++;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter index map.
//
////////////////////////////////////////////////////////////////////////////////
IP_ADAPTER_INDEX_MAP* GetAdapterIndexMap(_UINT32 nAdapterIndex)
{
//Count.
_INT32 nCount = 0;
#ifdef _DEBUG
assert(theInterfaceInformationList != NULL);
#endif
//Check index.
while(nCount < (_INT32)theInterfaceInformationList->NumAdapters)
{
//Check result.
if(theInterfaceInformationList->Adapter[nCount].Index = nAdapterIndex)
{
//Return result.
return &theInterfaceInformationList->Adapter[nCount];
}
//Add index.
nCount ++;
}
//Return null.
return NULL;
}
////////////////////////////////////////////////////////////////////////////////
//
// Get adapter index by guid.
//
////////////////////////////////////////////////////////////////////////////////
_UINT32 GetAdapterIndexByGuid(_STRING lpstrGuid)
{
//Index.
_INT32 nIndex = 0;
//Name.
_PASCALSTRING strName;
#ifdef _DEBUG
assert(theInterfaceInformationList != NULL);
#endif
//Clear string.
memset(strName,0,PASCAL_STRING_LENGTH);
//Format.
wsprintf((_STRING)strName,"\\DEVICE\\TCPIP_%s",lpstrGuid);
//Check index.
while(nIndex < theInterfaceInformationList->NumAdapters)
{
//Check result.
if(wcscmp((_UINT16 *)strName,theInterfaceInformationList->Adapter[nIndex].Name))
{
//Return result.
return theInterfaceInformationList->Adapter[nIndex].Index;
}
//Add index.
nIndex ++;
}
//Return result.
return -1;
}
////////////////////////////////////////////////////////////////////////////////
//
// Flush adapter ARP cache information.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL FlushAdapterARPCacheInformation(_UINT32 nAdapterIndex)
{
//Check result.
if(FlushIpNetTable(nAdapterIndex) != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::FlushAdapterARPCacheInformation : fail to flush ARP table !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Release adapter DHCP.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL ReleaseAdapterDHCPInformation(_UINT32 nAdapterIndex)
{
//Index Map
IP_ADAPTER_INDEX_MAP* pIndexMap;
//Flush ip tables.
pIndexMap = GetAdapterIndexMap(nAdapterIndex);
//Check result.
if(pIndexMap == NULL)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::ReleaseAdapterDHCPInformation : fail to get index map !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Release address.
if(IpReleaseAddress(pIndexMap) != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::ReleaseAdapterDHCPInformation : fail to release address !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Renew adapter DHCP information.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL RenewAdapterDHCPInformation(_UINT32 nAdapterIndex)
{
//Index Map
IP_ADAPTER_INDEX_MAP* pIndexMap;
//Flush ip tables.
pIndexMap = GetAdapterIndexMap(nAdapterIndex);
//Check result.
if(pIndexMap == NULL)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::RenewAdapterDHCPInformation : fail to get index map !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Release ip address.
if(IpRenewAddress(pIndexMap) != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::RenewAdapterDHCPInformation : fail to renew address !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Add adapter IP address.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL AddAdapterIPAddress(_UINT32 nAdapterIndex,_IPV4 ipLocal,_IPV4 ipNetmask,_UINT32* lpContext,_UINT32* lpInstance)
{
//Result.
_UINT32 nResult;
#ifdef _DEBUG
assert(lpContext != NULL && lpInstance != NULL);
#endif
//Get result.
nResult = AddIPAddress(*((_UINT32 *)ipLocal),*((_UINT32 *)ipNetmask),
nAdapterIndex,lpContext,lpInstance);
//Check result.
if(nResult != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_EXCEPTION,
"IPHelper::AddAdapterIPAddress : fail(%d) to add ip address !",
nResult);
#endif
return _FALSE;
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Unload interface information list.
//
////////////////////////////////////////////////////////////////////////////////
void UnloadInterfaceInformationList()
{
//Check result.
if(theInterfaceInformationList != NULL)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::UnloadInterfaceInformationList : list was freed !",
LOG_TUNNEL | LOG_INFORMATION);
#endif
//Free it.
free(theInterfaceInformationList);
//Clear it.
theInterfaceInformationList = NULL;
}
}
////////////////////////////////////////////////////////////////////////////////
//
// Set nework tunnel local address.
//
////////////////////////////////////////////////////////////////////////////////
_BOOL SetNetworkTunnelLocalAddress(NetworkTunnel* pTunnel)
{
#ifdef _DEBUG
assert(pTunnel != NULL && strlen(pTunnel->strGuid) > 0);
#endif
//Get adapter index.
pTunnel->nAdapterIndex = GetAdapterIndexByGuid(pTunnel->strGuid);
//Check result.
if(pTunnel->nAdapterIndex == -1)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : fail to get index of adapter !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_INFORMATION,
"IPHelper::SetNetworkTunnelLocalAddress : index(%d) of adapter !",
pTunnel->nAdapterIndex);
#endif
//Get mac address.
if(!GetAdapterMACAddress(pTunnel->nAdapterIndex,pTunnel->macLocal))
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : fail to get index of adapter !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_INFORMATION,
"IPHelper::SetNetworkTunnelLocalAddress : local(%02x-%02x-%02x-%02x-%02x-%02x) !",
pTunnel->macLocal[0],pTunnel->macLocal[1],pTunnel->macLocal[2],
pTunnel->macLocal[3],pTunnel->macLocal[4],pTunnel->macLocal[5]);
#endif
//Copy MAC address.
memcpy(pTunnel->macRemote,pTunnel->macLocal,sizeof(_MAC6));
//Adjust the last.
pTunnel->macRemote[5] = 0x01;
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_INFORMATION,
"IPHelper::SetNetworkTunnelLocalAddress : remote(%02x-%02x-%02x-%02x-%02x-%02x) !",
pTunnel->macRemote[0],pTunnel->macRemote[1],pTunnel->macRemote[2],
pTunnel->macRemote[3],pTunnel->macRemote[4],pTunnel->macRemote[5]);
#endif
//Flush ARP cache.
if(!FlushAdapterARPCacheInformation(pTunnel->nAdapterIndex))
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : fail to flush ARP cache !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
}
else
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : ARP cache was flushed !",
LOG_TUNNEL | LOG_INFORMATION);
#endif
}
//Get DHCP status.
if(!GetAdapterDHCPStatus(pTunnel->nAdapterIndex,&pTunnel->bDHCPEnabled))
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : fail to get DHCP status !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
}
#ifdef _DEBUG
LogRequestedFormat(LOG_TUNNEL | LOG_EXCEPTION,
"IPHelper::SetNetworkTunnelLocalAddress : DHCP(%s) !",
pTunnel->bDHCPEnabled ? "TRUE" : "FALSE");
#endif
//Delete adapter addresses.
DeleteAdapterAddresses(pTunnel->nAdapterIndex);
//Add IP address.
if(!AddAdapterIPAddress(pTunnel->nAdapterIndex,
pTunnel->ipLocal,pTunnel->ipNetmask,
&pTunnel->nConext,&pTunnel->nInstance))
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : fail to add ip addresses !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
return _FALSE;
}
else
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::SetNetworkTunnelLocalAddress : ip address was added !",
LOG_TUNNEL | LOG_INFORMATION);
#endif
}
//Return true.
return _TRUE;
}
////////////////////////////////////////////////////////////////////////////////
//
// Clear nework tunnel local address.
//
////////////////////////////////////////////////////////////////////////////////
void ClearNetworkTunnelLocalAddress(NetworkTunnel* pTunnel)
{
#ifdef _DEBUG
assert(pTunnel != NULL);
#endif
//Check adapter index.
if(pTunnel->nAdapterIndex != -1 && pTunnel->nConext)
{
//Delete IP address.
if(DeleteIPAddress(pTunnel->nConext) != NO_ERROR)
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::ClearNetworkTunnelLocalAddress : fail to delete ip addresses !",
LOG_TUNNEL | LOG_EXCEPTION);
#endif
}
else
{
#ifdef _DEBUG
LogRequestedEvent("IPHelper::ClearNetworkTunnelLocalAddress : ip address was delete !",
LOG_TUNNEL | LOG_INFORMATION);
#endif
}
}
}