Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygenifenum_reactos.c
Go to the documentation of this file.
00001 /* Copyright (C) 2003 Art Yerkes 00002 * A reimplementation of ifenum.c by Juan Lang 00003 * 00004 * This library is free software; you can redistribute it and/or 00005 * modify it under the terms of the GNU Lesser General Public 00006 * License as published by the Free Software Foundation; either 00007 * version 2.1 of the License, or (at your option) any later version. 00008 * 00009 * This library is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 * Lesser General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU Lesser General Public 00015 * License along with this library; if not, write to the Free Software 00016 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00017 * 00018 * Implementation notes 00019 * - Our bretheren use IOCTL_TCP_QUERY_INFORMATION_EX to get information 00020 * from tcpip.sys and IOCTL_TCP_SET_INFORMATION_EX to set info (such as 00021 * the route table). These ioctls mirror WsControl exactly in usage. 00022 * - This iphlpapi does not rely on any reactos-only features. 00023 * - This implementation is meant to be largely correct. I am not, however, 00024 * paying any attention to performance. It can be done faster, and 00025 * someone should definately optimize this code when speed is more of a 00026 * priority than it is now. 00027 * 00028 * Edited implementation notes from the original -- Basically edited to add 00029 * information and prune things which are not accurate about this file. 00030 * Interface index fun: 00031 * - Windows may rely on an index being cleared in the topmost 8 bits in some 00032 * APIs; see GetFriendlyIfIndex and the mention of "backward compatible" 00033 * indexes. It isn't clear which APIs might fail with non-backward-compatible 00034 * indexes, but I'll keep them bits clear just in case. 00035 * FIXME: 00036 * - We don't support IPv6 addresses here yet -- I moved the upper edge 00037 * functions into iphlpv6.c (arty) 00038 */ 00039 #include "iphlpapi_private.h" 00040 00041 WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi); 00042 00043 /* Functions */ 00044 00045 /* I'm a bit skittish about maintaining this info in memory, as I'd rather 00046 * not add any mutex or critical section blockers to these functions. I've 00047 * encountered far too many windows functions that contribute to deadlock 00048 * by not announcing themselves. */ 00049 void interfaceMapInit(void) 00050 { 00051 /* For now, nothing */ 00052 } 00053 00054 void interfaceMapFree(void) 00055 { 00056 /* Ditto. */ 00057 } 00058 00059 NTSTATUS tdiGetMibForIfEntity 00060 ( HANDLE tcpFile, TDIEntityID *ent, IFEntrySafelySized *entry ) { 00061 TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT; 00062 NTSTATUS status = STATUS_SUCCESS; 00063 DWORD returnSize; 00064 00065 WARN("TdiGetMibForIfEntity(tcpFile %x,entityId %x)\n", 00066 (int)tcpFile, (int)ent->tei_instance); 00067 00068 req.ID.toi_class = INFO_CLASS_PROTOCOL; 00069 req.ID.toi_type = INFO_TYPE_PROVIDER; 00070 req.ID.toi_id = IF_MIB_STATS_ID; 00071 req.ID.toi_entity = *ent; 00072 00073 status = DeviceIoControl( tcpFile, 00074 IOCTL_TCP_QUERY_INFORMATION_EX, 00075 &req, 00076 sizeof(req), 00077 entry, 00078 sizeof(*entry), 00079 &returnSize, 00080 NULL ); 00081 00082 if(!status) 00083 { 00084 WARN("IOCTL Failed\n"); 00085 return STATUS_UNSUCCESSFUL; 00086 } 00087 00088 TRACE("TdiGetMibForIfEntity() => {\n" 00089 " if_index ....................... %x\n" 00090 " if_type ........................ %x\n" 00091 " if_mtu ......................... %d\n" 00092 " if_speed ....................... %x\n" 00093 " if_physaddrlen ................. %d\n", 00094 entry->ent.if_index, 00095 entry->ent.if_type, 00096 entry->ent.if_mtu, 00097 entry->ent.if_speed, 00098 entry->ent.if_physaddrlen); 00099 TRACE(" if_physaddr .................... %02x:%02x:%02x:%02x:%02x:%02x\n" 00100 " if_descr ....................... %s\n", 00101 entry->ent.if_physaddr[0] & 0xff, 00102 entry->ent.if_physaddr[1] & 0xff, 00103 entry->ent.if_physaddr[2] & 0xff, 00104 entry->ent.if_physaddr[3] & 0xff, 00105 entry->ent.if_physaddr[4] & 0xff, 00106 entry->ent.if_physaddr[5] & 0xff, 00107 entry->ent.if_descr); 00108 TRACE("} status %08x\n",status); 00109 00110 return STATUS_SUCCESS; 00111 } 00112 00113 BOOL isInterface( TDIEntityID *if_maybe ) { 00114 return 00115 if_maybe->tei_entity == IF_ENTITY; 00116 } 00117 00118 BOOL isLoopback( HANDLE tcpFile, TDIEntityID *loop_maybe ) { 00119 IFEntrySafelySized entryInfo; 00120 NTSTATUS status; 00121 00122 status = tdiGetMibForIfEntity( tcpFile, 00123 loop_maybe, 00124 &entryInfo ); 00125 00126 return NT_SUCCESS(status) && 00127 (entryInfo.ent.if_type == IFENT_SOFTWARE_LOOPBACK); 00128 } 00129 00130 BOOL hasArp( HANDLE tcpFile, TDIEntityID *arp_maybe ) { 00131 TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT; 00132 NTSTATUS status = STATUS_SUCCESS; 00133 DWORD returnSize, type; 00134 00135 req.ID.toi_class = INFO_CLASS_GENERIC; 00136 req.ID.toi_type = INFO_TYPE_PROVIDER; 00137 req.ID.toi_id = ENTITY_TYPE_ID; 00138 req.ID.toi_entity.tei_entity = AT_ENTITY; 00139 req.ID.toi_entity.tei_instance = arp_maybe->tei_instance; 00140 00141 status = DeviceIoControl( tcpFile, 00142 IOCTL_TCP_QUERY_INFORMATION_EX, 00143 &req, 00144 sizeof(req), 00145 &type, 00146 sizeof(type), 00147 &returnSize, 00148 NULL ); 00149 if( !NT_SUCCESS(status) ) return FALSE; 00150 00151 return (type & AT_ARP); 00152 } 00153 00154 static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile, 00155 IFInfo **infoSet, 00156 PDWORD numInterfaces ) { 00157 DWORD numEntities; 00158 TDIEntityID *entIDSet = 0; 00159 NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entIDSet, &numEntities ); 00160 IFInfo *infoSetInt = 0; 00161 int curInterf = 0, i; 00162 00163 if (!NT_SUCCESS(status)) { 00164 ERR("getInterfaceInfoSet: tdiGetEntityIDSet() failed: 0x%lx\n", status); 00165 return status; 00166 } 00167 00168 infoSetInt = HeapAlloc( GetProcessHeap(), 0, 00169 sizeof(IFInfo) * numEntities ); 00170 00171 if( infoSetInt ) { 00172 for( i = 0; i < numEntities; i++ ) { 00173 if( isInterface( &entIDSet[i] ) ) { 00174 infoSetInt[curInterf].entity_id = entIDSet[i]; 00175 status = tdiGetMibForIfEntity 00176 ( tcpFile, 00177 &entIDSet[i], 00178 &infoSetInt[curInterf].if_info ); 00179 TRACE("tdiGetMibForIfEntity: %08x\n", status); 00180 if( NT_SUCCESS(status) ) { 00181 DWORD numAddrs; 00182 IPAddrEntry *addrs; 00183 TDIEntityID ip_ent; 00184 int j; 00185 00186 status = getNthIpEntity( tcpFile, curInterf, &ip_ent ); 00187 if( NT_SUCCESS(status) ) 00188 status = tdiGetIpAddrsForIpEntity 00189 ( tcpFile, &ip_ent, &addrs, &numAddrs ); 00190 for( j = 0; j < numAddrs && NT_SUCCESS(status); j++ ) { 00191 TRACE("ADDR %d: index %d (target %d)\n", j, addrs[j].iae_index, infoSetInt[curInterf].if_info.ent.if_index); 00192 if( addrs[j].iae_index == 00193 infoSetInt[curInterf].if_info.ent.if_index ) { 00194 memcpy( &infoSetInt[curInterf].ip_addr, 00195 &addrs[j], 00196 sizeof( addrs[j] ) ); 00197 curInterf++; 00198 break; 00199 } 00200 } 00201 } 00202 } 00203 } 00204 00205 tdiFreeThingSet(entIDSet); 00206 00207 if (NT_SUCCESS(status)) { 00208 *infoSet = infoSetInt; 00209 *numInterfaces = curInterf; 00210 } else { 00211 HeapFree(GetProcessHeap(), 0, infoSetInt); 00212 } 00213 00214 return status; 00215 } else { 00216 return STATUS_INSUFFICIENT_RESOURCES; 00217 } 00218 } 00219 00220 static DWORD getNumInterfacesInt(BOOL onlyNonLoopback) 00221 { 00222 DWORD numEntities, numInterfaces = 0; 00223 TDIEntityID *entitySet; 00224 HANDLE tcpFile; 00225 NTSTATUS status; 00226 int i; 00227 00228 status = openTcpFile( &tcpFile ); 00229 00230 if( !NT_SUCCESS(status) ) { 00231 WARN("getNumInterfaces: failed %08x\n", status ); 00232 return 0; 00233 } 00234 00235 status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); 00236 00237 if( !NT_SUCCESS(status) ) { 00238 WARN("getNumInterfaces: failed %08x\n", status ); 00239 closeTcpFile( tcpFile ); 00240 return 0; 00241 } 00242 00243 for( i = 0; i < numEntities; i++ ) { 00244 if( isInterface( &entitySet[i] ) && 00245 (!onlyNonLoopback || 00246 (onlyNonLoopback && !isLoopback( tcpFile, &entitySet[i] ))) ) 00247 numInterfaces++; 00248 } 00249 00250 TRACE("getNumInterfaces: success: %d %d %08x\n", 00251 onlyNonLoopback, numInterfaces, status ); 00252 00253 closeTcpFile( tcpFile ); 00254 00255 tdiFreeThingSet( entitySet ); 00256 00257 return numInterfaces; 00258 } 00259 00260 DWORD getNumInterfaces(void) 00261 { 00262 return getNumInterfacesInt( FALSE ); 00263 } 00264 00265 DWORD getNumNonLoopbackInterfaces(void) 00266 { 00267 return getNumInterfacesInt( TRUE ); 00268 } 00269 00270 DWORD getNthInterfaceEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) { 00271 DWORD numEntities = 0; 00272 DWORD numInterfaces = 0; 00273 TDIEntityID *entitySet = 0; 00274 NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); 00275 int i; 00276 00277 if( !NT_SUCCESS(status) ) 00278 return status; 00279 00280 for( i = 0; i < numEntities; i++ ) { 00281 if( isInterface( &entitySet[i] ) ) { 00282 if( numInterfaces == index ) break; 00283 else numInterfaces++; 00284 } 00285 } 00286 00287 TRACE("Index %d is entity #%d - %04x:%08x\n", index, i, 00288 entitySet[i].tei_entity, entitySet[i].tei_instance ); 00289 00290 tdiFreeThingSet( entitySet ); 00291 00292 if( numInterfaces == index && i < numEntities ) { 00293 memcpy( ent, &entitySet[i], sizeof(*ent) ); 00294 return STATUS_SUCCESS; 00295 } else { 00296 return STATUS_UNSUCCESSFUL; 00297 } 00298 } 00299 00300 NTSTATUS getInterfaceInfoByIndex( HANDLE tcpFile, DWORD index, IFInfo *info ) { 00301 IFInfo *ifInfo; 00302 DWORD numInterfaces; 00303 NTSTATUS status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces ); 00304 int i; 00305 00306 if( NT_SUCCESS(status) ) 00307 { 00308 for( i = 0; i < numInterfaces; i++ ) { 00309 if( ifInfo[i].if_info.ent.if_index == index ) { 00310 memcpy( info, &ifInfo[i], sizeof(*info) ); 00311 break; 00312 } 00313 } 00314 00315 HeapFree(GetProcessHeap(), 0, ifInfo); 00316 00317 return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; 00318 } 00319 00320 return status; 00321 } 00322 00323 NTSTATUS getInterfaceInfoByName( HANDLE tcpFile, char *name, IFInfo *info ) { 00324 IFInfo *ifInfo; 00325 DWORD numInterfaces; 00326 int i; 00327 NTSTATUS status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces ); 00328 00329 if( NT_SUCCESS(status) ) 00330 { 00331 for( i = 0; i < numInterfaces; i++ ) { 00332 if( !strcmp((PCHAR)ifInfo[i].if_info.ent.if_descr, name) ) { 00333 memcpy( info, &ifInfo[i], sizeof(*info) ); 00334 break; 00335 } 00336 } 00337 00338 HeapFree(GetProcessHeap(), 0,ifInfo); 00339 00340 return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL; 00341 } 00342 00343 return status; 00344 } 00345 00346 /* Note that the result of this operation must be freed later */ 00347 00348 const char *getInterfaceNameByIndex(DWORD index) 00349 { 00350 IFInfo ifInfo; 00351 HANDLE tcpFile; 00352 char *interfaceName = 0, *adapter_name = 0; 00353 NTSTATUS status = openTcpFile( &tcpFile ); 00354 00355 if( NT_SUCCESS(status) ) { 00356 status = getInterfaceInfoByIndex( tcpFile, index, &ifInfo ); 00357 00358 if( NT_SUCCESS(status) ) { 00359 adapter_name = (char *)ifInfo.if_info.ent.if_descr; 00360 00361 interfaceName = HeapAlloc( GetProcessHeap(), 0, 00362 strlen(adapter_name) + 1 ); 00363 if (!interfaceName) return NULL; 00364 00365 strcpy( interfaceName, adapter_name ); 00366 } 00367 00368 closeTcpFile( tcpFile ); 00369 } 00370 00371 return interfaceName; 00372 } 00373 00374 void consumeInterfaceName(const char *name) { 00375 HeapFree( GetProcessHeap(), 0, (char *)name ); 00376 } 00377 00378 DWORD getInterfaceIndexByName(const char *name, PDWORD index) 00379 { 00380 IFInfo ifInfo; 00381 HANDLE tcpFile; 00382 NTSTATUS status = openTcpFile( &tcpFile ); 00383 00384 if( NT_SUCCESS(status) ) { 00385 status = getInterfaceInfoByName( tcpFile, (char *)name, &ifInfo ); 00386 00387 if( NT_SUCCESS(status) ) { 00388 *index = ifInfo.if_info.ent.if_index; 00389 } 00390 00391 closeTcpFile( tcpFile ); 00392 } 00393 00394 return status; 00395 } 00396 00397 InterfaceIndexTable *getInterfaceIndexTableInt( BOOL nonLoopbackOnly ) { 00398 DWORD numInterfaces, curInterface = 0; 00399 int i; 00400 IFInfo *ifInfo; 00401 InterfaceIndexTable *ret = 0; 00402 HANDLE tcpFile; 00403 NTSTATUS status = openTcpFile( &tcpFile ); 00404 00405 if( NT_SUCCESS(status) ) { 00406 status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces ); 00407 00408 TRACE("InterfaceInfoSet: %08x, %04x:%08x\n", 00409 status, 00410 ifInfo->entity_id.tei_entity, 00411 ifInfo->entity_id.tei_instance); 00412 00413 if( NT_SUCCESS(status) ) { 00414 ret = (InterfaceIndexTable *) 00415 calloc(1, 00416 sizeof(InterfaceIndexTable) + 00417 (numInterfaces - 1) * sizeof(DWORD)); 00418 00419 if (ret) { 00420 ret->numAllocated = numInterfaces; 00421 TRACE("NumInterfaces = %d\n", numInterfaces); 00422 00423 for( i = 0; i < numInterfaces; i++ ) { 00424 TRACE("Examining interface %d\n", i); 00425 if( !nonLoopbackOnly || 00426 !isLoopback( tcpFile, &ifInfo[i].entity_id ) ) { 00427 TRACE("Interface %d matches (%d)\n", i, curInterface); 00428 ret->indexes[curInterface++] = 00429 ifInfo[i].if_info.ent.if_index; 00430 } 00431 } 00432 00433 ret->numIndexes = curInterface; 00434 } 00435 00436 tdiFreeThingSet( ifInfo ); 00437 } 00438 closeTcpFile( tcpFile ); 00439 } 00440 00441 return ret; 00442 } 00443 00444 InterfaceIndexTable *getInterfaceIndexTable(void) { 00445 return getInterfaceIndexTableInt( FALSE ); 00446 } 00447 00448 InterfaceIndexTable *getNonLoopbackInterfaceIndexTable(void) { 00449 return getInterfaceIndexTableInt( TRUE ); 00450 } 00451 00452 DWORD getInterfaceIPAddrByName(const char *name) 00453 { 00454 return INADDR_ANY; 00455 } 00456 00457 NTSTATUS getIPAddrEntryForIf(HANDLE tcpFile, 00458 char *name, 00459 DWORD index, 00460 IFInfo *ifInfo) { 00461 NTSTATUS status = 00462 name ? 00463 getInterfaceInfoByName( tcpFile, name, ifInfo ) : 00464 getInterfaceInfoByIndex( tcpFile, index, ifInfo ); 00465 00466 if (!NT_SUCCESS(status)) { 00467 ERR("getIPAddrEntryForIf returning %lx\n", status); 00468 } 00469 00470 return status; 00471 } 00472 00473 DWORD getAddrByIndexOrName( char *name, DWORD index, IPHLPAddrType addrType ) { 00474 IFInfo ifInfo; 00475 HANDLE tcpFile; 00476 NTSTATUS status = STATUS_SUCCESS; 00477 DWORD addrOut = INADDR_ANY; 00478 00479 status = openTcpFile( &tcpFile ); 00480 00481 if( NT_SUCCESS(status) ) { 00482 status = getIPAddrEntryForIf( tcpFile, name, index, &ifInfo ); 00483 if( NT_SUCCESS(status) ) { 00484 switch( addrType ) { 00485 case IPAAddr: addrOut = ifInfo.ip_addr.iae_addr; break; 00486 case IPABcast: addrOut = ifInfo.ip_addr.iae_bcastaddr; break; 00487 case IPAMask: addrOut = ifInfo.ip_addr.iae_mask; break; 00488 case IFMtu: addrOut = ifInfo.if_info.ent.if_mtu; break; 00489 case IFStatus: addrOut = ifInfo.if_info.ent.if_operstatus; break; 00490 } 00491 } 00492 closeTcpFile( tcpFile ); 00493 } 00494 00495 return addrOut; 00496 } 00497 00498 DWORD getInterfaceIPAddrByIndex(DWORD index) { 00499 return getAddrByIndexOrName( 0, index, IPAAddr ); 00500 } 00501 00502 DWORD getInterfaceBCastAddrByName(const char *name) { 00503 return getAddrByIndexOrName( (char *)name, 0, IPABcast ); 00504 } 00505 00506 DWORD getInterfaceBCastAddrByIndex(DWORD index) { 00507 return getAddrByIndexOrName( 0, index, IPABcast ); 00508 } 00509 00510 DWORD getInterfaceMaskByName(const char *name) { 00511 return getAddrByIndexOrName( (char *)name, 0, IPAMask ); 00512 } 00513 00514 DWORD getInterfaceMaskByIndex(DWORD index) { 00515 return getAddrByIndexOrName( 0, index, IPAMask ); 00516 } 00517 00518 void getInterfacePhysicalFromInfo( IFInfo *info, 00519 PDWORD len, PBYTE addr, PDWORD type ) { 00520 *len = info->if_info.ent.if_physaddrlen; 00521 memcpy( addr, info->if_info.ent.if_physaddr, *len ); 00522 *type = info->if_info.ent.if_type; 00523 } 00524 00525 DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr, 00526 PDWORD type) 00527 { 00528 HANDLE tcpFile; 00529 IFInfo info; 00530 NTSTATUS status = openTcpFile( &tcpFile ); 00531 00532 if( NT_SUCCESS(status) ) { 00533 status = getInterfaceInfoByName( tcpFile, (char *)name, &info ); 00534 if( NT_SUCCESS(status) ) 00535 getInterfacePhysicalFromInfo( &info, len, addr, type ); 00536 closeTcpFile( tcpFile ); 00537 } 00538 00539 return status; 00540 } 00541 00542 DWORD getInterfacePhysicalByIndex(DWORD index, PDWORD len, PBYTE addr, 00543 PDWORD type) 00544 { 00545 HANDLE tcpFile; 00546 IFInfo info; 00547 NTSTATUS status = openTcpFile( &tcpFile ); 00548 00549 if( NT_SUCCESS(status) ) { 00550 status = getInterfaceInfoByIndex( tcpFile, index, &info ); 00551 if( NT_SUCCESS(status) ) 00552 getInterfacePhysicalFromInfo( &info, len, addr, type ); 00553 closeTcpFile( tcpFile ); 00554 } 00555 00556 return status; 00557 } 00558 00559 DWORD getInterfaceMtuByName(const char *name, PDWORD mtu) { 00560 *mtu = getAddrByIndexOrName( (char *)name, 0, IFMtu ); 00561 return STATUS_SUCCESS; 00562 } 00563 00564 DWORD getInterfaceMtuByIndex(DWORD index, PDWORD mtu) { 00565 *mtu = getAddrByIndexOrName( 0, index, IFMtu ); 00566 return STATUS_SUCCESS; 00567 } 00568 00569 DWORD getInterfaceStatusByName(const char *name, PDWORD status) { 00570 *status = getAddrByIndexOrName( (char *)name, 0, IFStatus ); 00571 return STATUS_SUCCESS; 00572 } 00573 00574 DWORD getInterfaceStatusByIndex(DWORD index, PDWORD status) 00575 { 00576 *status = getAddrByIndexOrName( 0, index, IFStatus ); 00577 return STATUS_SUCCESS; 00578 } 00579 00580 DWORD getInterfaceEntryByName(const char *name, PMIB_IFROW entry) 00581 { 00582 HANDLE tcpFile; 00583 IFInfo info; 00584 NTSTATUS status = openTcpFile( &tcpFile ); 00585 00586 TRACE("Called.\n"); 00587 00588 if( NT_SUCCESS(status) ) { 00589 status = getInterfaceInfoByName( tcpFile, (char *)name, &info ); 00590 00591 if( NT_SUCCESS(status) ) { 00592 memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN], 00593 &info.if_info, 00594 sizeof(info.if_info) ); 00595 } 00596 00597 TRACE("entry->bDescr = %s\n", entry->bDescr); 00598 00599 closeTcpFile( tcpFile ); 00600 } 00601 00602 return status; 00603 } 00604 00605 DWORD getInterfaceEntryByIndex(DWORD index, PMIB_IFROW entry) 00606 { 00607 HANDLE tcpFile; 00608 IFInfo info; 00609 NTSTATUS status = openTcpFile( &tcpFile ); 00610 00611 TRACE("Called.\n"); 00612 00613 if( NT_SUCCESS(status) ) { 00614 status = getInterfaceInfoByIndex( tcpFile, index, &info ); 00615 00616 if( NT_SUCCESS(status) ) { 00617 memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN], 00618 &info.if_info, 00619 sizeof(info.if_info) ); 00620 } 00621 00622 closeTcpFile( tcpFile ); 00623 } 00624 00625 return status; 00626 } 00627 00628 char *toIPAddressString(unsigned int addr, char string[16]) 00629 { 00630 struct in_addr iAddr; 00631 00632 iAddr.s_addr = addr; 00633 00634 if (string) 00635 strncpy(string, inet_ntoa(iAddr), 16); 00636 00637 return inet_ntoa(iAddr); 00638 } 00639 00640 NTSTATUS addIPAddress( IPAddr Address, IPMask Mask, DWORD IfIndex, 00641 PULONG NteContext, PULONG NteInstance ) 00642 { 00643 HANDLE tcpFile; 00644 NTSTATUS status = openTcpFile( &tcpFile ); 00645 IP_SET_DATA Data; 00646 IO_STATUS_BLOCK Iosb; 00647 00648 TRACE("Called.\n"); 00649 00650 if( !NT_SUCCESS(status) ) return status; 00651 00652 Data.NteContext = IfIndex; 00653 Data.NewAddress = Address; 00654 Data.NewNetmask = Mask; 00655 00656 status = NtDeviceIoControlFile( tcpFile, 00657 NULL, 00658 NULL, 00659 NULL, 00660 &Iosb, 00661 IOCTL_SET_IP_ADDRESS, 00662 &Data, 00663 sizeof(Data), 00664 &Data, 00665 sizeof(Data) ); 00666 00667 closeTcpFile( tcpFile ); 00668 00669 if( NT_SUCCESS(status) ) { 00670 *NteContext = Iosb.Information; 00671 *NteInstance = Data.NewAddress; 00672 } 00673 00674 if (!NT_SUCCESS(status)) { 00675 ERR("addIPAddress for if %d returning 0x%lx\n", IfIndex, status); 00676 } 00677 00678 return status; 00679 00680 } 00681 00682 NTSTATUS deleteIpAddress( ULONG NteContext ) 00683 { 00684 HANDLE tcpFile; 00685 NTSTATUS status = openTcpFile( &tcpFile ); 00686 IO_STATUS_BLOCK Iosb; 00687 00688 TRACE("Called.\n"); 00689 00690 if( !NT_SUCCESS(status) ) return status; 00691 00692 status = NtDeviceIoControlFile( tcpFile, 00693 NULL, 00694 NULL, 00695 NULL, 00696 &Iosb, 00697 IOCTL_DELETE_IP_ADDRESS, 00698 &NteContext, 00699 sizeof(USHORT), 00700 NULL, 00701 0 ); 00702 00703 closeTcpFile( tcpFile ); 00704 00705 if (!NT_SUCCESS(status)) { 00706 ERR("deleteIpAddress(%lu) returning 0x%lx\n", NteContext, status); 00707 } 00708 00709 return status; 00710 } Generated on Sun May 27 2012 04:24:09 for ReactOS by
1.7.6.1
|