Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygeninterface.c
Go to the documentation of this file.
00001 /* 00002 * COPYRIGHT: See COPYING in the top level directory 00003 * PROJECT: ReactOS TCP/IP protocol driver 00004 * FILE: tcpip/interface.c 00005 * PURPOSE: Convenient abstraction for getting and setting information 00006 * in IP_INTERFACE. 00007 * PROGRAMMERS: Art Yerkes 00008 * REVISIONS: 00009 * CSH 01/08-2000 Created 00010 */ 00011 00012 #include "precomp.h" 00013 00014 NTSTATUS GetInterfaceIPv4Address( PIP_INTERFACE Interface, 00015 ULONG TargetType, 00016 PULONG Address ) { 00017 switch( TargetType ) { 00018 case ADE_UNICAST: 00019 *Address = Interface->Unicast.Address.IPv4Address; 00020 break; 00021 00022 case ADE_ADDRMASK: 00023 *Address = Interface->Netmask.Address.IPv4Address; 00024 break; 00025 00026 case ADE_BROADCAST: 00027 *Address = Interface->Broadcast.Address.IPv4Address; 00028 break; 00029 00030 case ADE_POINTOPOINT: 00031 *Address = Interface->PointToPoint.Address.IPv4Address; 00032 break; 00033 00034 default: 00035 return STATUS_UNSUCCESSFUL; 00036 } 00037 00038 return STATUS_SUCCESS; 00039 } 00040 00041 UINT CountInterfaces() { 00042 ULONG Count = 0; 00043 KIRQL OldIrql; 00044 IF_LIST_ITER(CurrentIF); 00045 00046 TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql); 00047 00048 ForEachInterface(CurrentIF) { 00049 Count++; 00050 } EndFor(CurrentIF); 00051 00052 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00053 00054 return Count; 00055 } 00056 00057 NTSTATUS GetInterfaceSpeed( PIP_INTERFACE Interface, PUINT Speed ) { 00058 PLAN_ADAPTER IF = (PLAN_ADAPTER)Interface->Context; 00059 00060 *Speed = IF->Speed; 00061 00062 return STATUS_SUCCESS; 00063 } 00064 00065 NTSTATUS GetInterfaceName( PIP_INTERFACE Interface, 00066 PCHAR NameBuffer, 00067 UINT Len ) { 00068 ULONG ResultSize = 0; 00069 NTSTATUS Status = 00070 RtlUnicodeToMultiByteN( NameBuffer, 00071 Len, 00072 &ResultSize, 00073 Interface->Name.Buffer, 00074 Interface->Name.Length ); 00075 00076 if( NT_SUCCESS(Status) ) 00077 NameBuffer[ResultSize] = 0; 00078 else 00079 NameBuffer[0] = 0; 00080 00081 return Status; 00082 } 00083 00084 PIP_INTERFACE AddrLocateInterface( 00085 PIP_ADDRESS MatchAddress) 00086 { 00087 KIRQL OldIrql; 00088 PIP_INTERFACE RetIF = NULL; 00089 IF_LIST_ITER(CurrentIF); 00090 00091 TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql); 00092 00093 ForEachInterface(CurrentIF) { 00094 if( AddrIsEqual( &CurrentIF->Unicast, MatchAddress ) || 00095 AddrIsEqual( &CurrentIF->Broadcast, MatchAddress ) ) { 00096 RetIF = CurrentIF; 00097 break; 00098 } 00099 } EndFor(CurrentIF); 00100 00101 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00102 00103 return RetIF; 00104 } 00105 00106 BOOLEAN HasPrefix( 00107 PIP_ADDRESS Address, 00108 PIP_ADDRESS Prefix, 00109 UINT Length) 00110 /* 00111 * FUNCTION: Determines wether an address has an given prefix 00112 * ARGUMENTS: 00113 * Address = Pointer to address to use 00114 * Prefix = Pointer to prefix to check for 00115 * Length = Length of prefix 00116 * RETURNS: 00117 * TRUE if the address has the prefix, FALSE if not 00118 * NOTES: 00119 * The two addresses must be of the same type 00120 */ 00121 { 00122 PUCHAR pAddress = (PUCHAR)&Address->Address; 00123 PUCHAR pPrefix = (PUCHAR)&Prefix->Address; 00124 00125 TI_DbgPrint(DEBUG_ROUTER, ("Called. Address (0x%X) Prefix (0x%X) Length (%d).\n", Address, Prefix, Length)); 00126 00127 #if 0 00128 TI_DbgPrint(DEBUG_ROUTER, ("Address (%s) Prefix (%s).\n", 00129 A2S(Address), A2S(Prefix))); 00130 #endif 00131 00132 /* Check that initial integral bytes match */ 00133 while (Length > 8) { 00134 if (*pAddress++ != *pPrefix++) 00135 return FALSE; 00136 Length -= 8; 00137 } 00138 00139 /* Check any remaining bits */ 00140 if ((Length > 0) && ((*pAddress >> (8 - Length)) != (*pPrefix >> (8 - Length)))) 00141 return FALSE; 00142 00143 return TRUE; 00144 } 00145 00146 static PIP_INTERFACE GetDefaultInterface(VOID) 00147 { 00148 KIRQL OldIrql; 00149 IF_LIST_ITER(CurrentIF); 00150 00151 TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql); 00152 ForEachInterface(CurrentIF) { 00153 if (CurrentIF->Context) { 00154 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00155 return CurrentIF; 00156 } 00157 } EndFor(CurrentIF); 00158 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00159 00160 /* There are no physical interfaces on the system 00161 * so we must pick the loopback interface */ 00162 00163 return Loopback; 00164 } 00165 00166 PIP_INTERFACE FindOnLinkInterface(PIP_ADDRESS Address) 00167 /* 00168 * FUNCTION: Checks all on-link prefixes to find out if an address is on-link 00169 * ARGUMENTS: 00170 * Address = Pointer to address to check 00171 * RETURNS: 00172 * Pointer to interface if address is on-link, NULL if not 00173 */ 00174 { 00175 KIRQL OldIrql; 00176 IF_LIST_ITER(CurrentIF); 00177 00178 TI_DbgPrint(DEBUG_ROUTER, ("Called. Address (0x%X)\n", Address)); 00179 TI_DbgPrint(DEBUG_ROUTER, ("Address (%s)\n", A2S(Address))); 00180 00181 if (AddrIsUnspecified(Address)) 00182 return GetDefaultInterface(); 00183 00184 TcpipAcquireSpinLock(&InterfaceListLock, &OldIrql); 00185 00186 ForEachInterface(CurrentIF) { 00187 if (HasPrefix(Address, &CurrentIF->Unicast, 00188 AddrCountPrefixBits(&CurrentIF->Netmask))) { 00189 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00190 return CurrentIF; 00191 } 00192 } EndFor(CurrentIF); 00193 00194 TcpipReleaseSpinLock(&InterfaceListLock, OldIrql); 00195 00196 return NULL; 00197 } 00198 00199 NTSTATUS GetInterfaceConnectionStatus(PIP_INTERFACE Interface, PULONG Result) 00200 { 00201 NTSTATUS Status; 00202 00203 /* Query OID_GEN_MEDIA_CONNECT_STATUS for connection status information */ 00204 Status = TcpipLanGetDwordOid(Interface, OID_GEN_MEDIA_CONNECT_STATUS, Result); 00205 if (!NT_SUCCESS(Status)) 00206 return Status; 00207 00208 /* Translate the result into MIB_IF_OPER_STATUS_XXX */ 00209 if (*Result == NdisMediaStateConnected) 00210 { 00211 /* Up and running */ 00212 *Result = MIB_IF_OPER_STATUS_OPERATIONAL; 00213 } 00214 else 00215 { 00216 /* Down */ 00217 *Result = MIB_IF_OPER_STATUS_DISCONNECTED; 00218 } 00219 00220 return STATUS_SUCCESS; 00221 } Generated on Mon May 28 2012 04:25:51 for ReactOS by
1.7.6.1
|