2c3388691063bf60db9543ae0df239d32dab2752
[reactos.git] / reactos / drivers / lib / ip / network / interface.c
1 /*
2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TCP/IP protocol driver
4 * FILE: tcpip/interface.c
5 * PURPOSE: Convenient abstraction for getting and setting information
6 * in IP_INTERFACE.
7 * PROGRAMMERS: Art Yerkes
8 * REVISIONS:
9 * CSH 01/08-2000 Created
10 */
11
12 #include "precomp.h"
13
14
15 NTSTATUS GetInterfaceIPv4Address( PIP_INTERFACE Interface,
16 ULONG TargetType,
17 PULONG Address ) {
18 ADE_LIST_ITER(CurrentADE);
19
20 ForEachADE(Interface->ADEListHead,CurrentADE) {
21 if (CurrentADE->Type == TargetType) {
22 *Address = CurrentADE->Address.Address.IPv4Address;
23 return STATUS_SUCCESS;
24 }
25 } EndFor(CurrentADE);
26
27 return STATUS_UNSUCCESSFUL;
28 }
29
30 UINT CountInterfaces() {
31 DWORD Count = 0;
32 KIRQL OldIrql;
33 IF_LIST_ITER(CurrentIF);
34
35 TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql);
36
37 ForEachInterface(CurrentIF) {
38 Count++;
39 } EndFor(CurrentIF);
40
41 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql);
42
43 return Count;
44 }
45
46 UINT CountInterfaceAddresses( PIP_INTERFACE Interface ) {
47 UINT AddrCount = 0;
48 ADE_LIST_ITER(CurrentADE);
49
50 ForEachADE(Interface->ADEListHead,CurrentADE) {
51 if( CurrentADE->Type == ADE_UNICAST )
52 AddrCount++;
53 } EndFor(CurrentADE);
54
55 return AddrCount;
56 }
57
58 NTSTATUS GetInterfaceSpeed( PIP_INTERFACE Interface, PUINT Speed ) {
59 NDIS_STATUS NdisStatus;
60 PLAN_ADAPTER IF = (PLAN_ADAPTER)Interface->Context;
61
62 #ifdef __NTDRIVER__
63 /* Get maximum link speed */
64 NdisStatus = NDISCall(IF,
65 NdisRequestQueryInformation,
66 OID_GEN_LINK_SPEED,
67 Speed,
68 sizeof(UINT));
69 #else
70 (void)IF;
71 NdisStatus = NDIS_STATUS_SUCCESS;
72 *Speed = 10000;
73 #endif
74
75 return
76 NdisStatus != NDIS_STATUS_SUCCESS ?
77 STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
78 }
79
80 NTSTATUS GetInterfaceName( PIP_INTERFACE Interface,
81 PCHAR NameBuffer,
82 UINT Len ) {
83 NDIS_STATUS NdisStatus;
84 PLAN_ADAPTER IF = (PLAN_ADAPTER)Interface->Context;
85
86 #ifdef __NTDRIVER__
87 /* Get maximum link speed */
88 NdisStatus = NDISCall(IF,
89 NdisRequestQueryInformation,
90 OID_GEN_FRIENDLY_NAME,
91 NameBuffer,
92 Len);
93 #else
94 (void)IF;
95 NdisStatus = NDIS_STATUS_SUCCESS;
96 strncpy( NameBuffer, "eth", Len );
97 #endif
98
99 return
100 NdisStatus != NDIS_STATUS_SUCCESS ?
101 STATUS_UNSUCCESSFUL : STATUS_SUCCESS;
102 }