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
7 * PROGRAMMERS: Art Yerkes
9 * CSH 01/08-2000 Created
14 NTSTATUS
GetInterfaceIPv4Address( PIP_INTERFACE Interface
,
17 switch( TargetType
) {
19 *Address
= Interface
->Unicast
.Address
.IPv4Address
;
23 *Address
= Interface
->Netmask
.Address
.IPv4Address
;
27 *Address
= Interface
->Broadcast
.Address
.IPv4Address
;
31 *Address
= Interface
->PointToPoint
.Address
.IPv4Address
;
35 return STATUS_UNSUCCESSFUL
;
38 return STATUS_SUCCESS
;
41 UINT
CountInterfaces() {
44 IF_LIST_ITER(CurrentIF
);
46 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
48 ForEachInterface(CurrentIF
) {
52 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
57 NTSTATUS
GetInterfaceSpeed( PIP_INTERFACE Interface
, PUINT Speed
) {
58 PLAN_ADAPTER IF
= (PLAN_ADAPTER
)Interface
->Context
;
62 return STATUS_SUCCESS
;
65 NTSTATUS
GetInterfaceName( PIP_INTERFACE Interface
,
70 RtlUnicodeToMultiByteN( NameBuffer
,
73 Interface
->Name
.Buffer
,
74 Interface
->Name
.Length
);
76 if( NT_SUCCESS(Status
) )
77 NameBuffer
[ResultSize
] = 0;
84 PIP_INTERFACE
AddrLocateInterface(
85 PIP_ADDRESS MatchAddress
)
88 PIP_INTERFACE RetIF
= NULL
;
89 IF_LIST_ITER(CurrentIF
);
91 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
93 ForEachInterface(CurrentIF
) {
94 if( AddrIsEqual( &CurrentIF
->Unicast
, MatchAddress
) ||
95 AddrIsEqual( &CurrentIF
->Broadcast
, MatchAddress
) ) {
101 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
111 * FUNCTION: Determines wether an address has an given prefix
113 * Address = Pointer to address to use
114 * Prefix = Pointer to prefix to check for
115 * Length = Length of prefix
117 * TRUE if the address has the prefix, FALSE if not
119 * The two addresses must be of the same type
122 PUCHAR pAddress
= (PUCHAR
)&Address
->Address
;
123 PUCHAR pPrefix
= (PUCHAR
)&Prefix
->Address
;
125 TI_DbgPrint(DEBUG_ROUTER
, ("Called. Address (0x%X) Prefix (0x%X) Length (%d).\n", Address
, Prefix
, Length
));
128 TI_DbgPrint(DEBUG_ROUTER
, ("Address (%s) Prefix (%s).\n",
129 A2S(Address
), A2S(Prefix
)));
132 /* Check that initial integral bytes match */
134 if (*pAddress
++ != *pPrefix
++)
139 /* Check any remaining bits */
140 if ((Length
> 0) && ((*pAddress
>> (8 - Length
)) != (*pPrefix
>> (8 - Length
))))
146 static PIP_INTERFACE
GetDefaultInterface(VOID
)
149 IF_LIST_ITER(CurrentIF
);
151 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
152 ForEachInterface(CurrentIF
) {
153 if (CurrentIF
->Context
) {
154 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
158 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
160 /* There are no physical interfaces on the system
161 * so we must pick the loopback interface */
166 PIP_INTERFACE
FindOnLinkInterface(PIP_ADDRESS Address
)
168 * FUNCTION: Checks all on-link prefixes to find out if an address is on-link
170 * Address = Pointer to address to check
172 * Pointer to interface if address is on-link, NULL if not
176 IF_LIST_ITER(CurrentIF
);
178 TI_DbgPrint(DEBUG_ROUTER
, ("Called. Address (0x%X)\n", Address
));
179 TI_DbgPrint(DEBUG_ROUTER
, ("Address (%s)\n", A2S(Address
)));
181 if (AddrIsUnspecified(Address
))
182 return GetDefaultInterface();
184 TcpipAcquireSpinLock(&InterfaceListLock
, &OldIrql
);
186 ForEachInterface(CurrentIF
) {
187 if (HasPrefix(Address
, &CurrentIF
->Unicast
,
188 AddrCountPrefixBits(&CurrentIF
->Netmask
))) {
189 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
194 TcpipReleaseSpinLock(&InterfaceListLock
, OldIrql
);
199 NTSTATUS GetInterfaceConnectionStatus
200 ( PIP_INTERFACE Interface
, PULONG Result
) {
201 NTSTATUS Status
= TcpipLanGetDwordOid
202 ( Interface
, OID_GEN_HARDWARE_STATUS
, Result
);
203 if( NT_SUCCESS(Status
) ) switch( *Result
) {
204 case NdisHardwareStatusReady
:
205 *Result
= MIB_IF_OPER_STATUS_OPERATIONAL
;
207 case NdisHardwareStatusInitializing
:
208 *Result
= MIB_IF_OPER_STATUS_CONNECTING
;
210 case NdisHardwareStatusReset
:
211 *Result
= MIB_IF_OPER_STATUS_DISCONNECTED
;
213 case NdisHardwareStatusNotReady
:
214 *Result
= MIB_IF_OPER_STATUS_DISCONNECTED
;
216 case NdisHardwareStatusClosing
:
218 *Result
= MIB_IF_OPER_STATUS_NON_OPERATIONAL
;