Something went wrong. Try again.
Reactos
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345/* * iphlpapi dll implementation * * Copyright (C) 2003 Juan Lang * 2018 Pierre Schweitzer * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */
#define DEBUG
#include <config.h>#include "iphlpapi_private.h"#include <strsafe.h>#include <psapi.h>
WINE_DEFAULT_DEBUG_CHANNEL(iphlpapi);
typedef struct _NAME_SERVER_LIST_CONTEXT { ULONG uSizeAvailable; ULONG uSizeRequired; PIP_PER_ADAPTER_INFO pData; UINT NumServers; IP_ADDR_STRING *pLastAddr;} NAME_SERVER_LIST_CONTEXT, *PNAME_SERVER_LIST_CONTEXT;
BOOL WINAPI DllMain (HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved){ switch (fdwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls( hinstDLL ); interfaceMapInit(); break;
case DLL_PROCESS_DETACH: interfaceMapFree(); break; } return TRUE;}
/****************************************************************** * AddIPAddress (IPHLPAPI.@) * * PARAMS * Address [In] * IpMask [In] * IfIndex [In] * NTEContext [In/Out] * NTEInstance [In/Out] * * RETURNS * DWORD */DWORD WINAPI AddIPAddress(IPAddr Address, IPMask Netmask, DWORD IfIndex, PULONG NteContext, PULONG NteInstance){ return RtlNtStatusToDosError(addIPAddress(Address, Netmask, IfIndex, NteContext, NteInstance));}
DWORD getInterfaceGatewayByIndex(DWORD index){ DWORD ndx, retVal = 0, numRoutes = getNumRoutes(); RouteTable *table = getRouteTable(); if (!table) return 0;
for (ndx = 0; ndx < numRoutes; ndx++) { if ((table->routes[ndx].ifIndex == (index)) && (table->routes[ndx].dest == 0)) retVal = table->routes[ndx].gateway; } HeapFree(GetProcessHeap(), 0, table); return retVal;}
/****************************************************************** * AllocateAndGetIfTableFromStack (IPHLPAPI.@) * * PARAMS * ppIfTable [Out] -- pointer into which the MIB_IFTABLE is * allocated and returned. * bOrder [In] -- passed to GetIfTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever * GetIfTable returns otherwise */DWORD WINAPI AllocateAndGetIfTableFromStack(PMIB_IFTABLE *ppIfTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppIfTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppIfTable, (DWORD)bOrder, heap, flags); if (!ppIfTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppIfTable = NULL; ret = GetIfTable(*ppIfTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppIfTable = (PMIB_IFTABLE)HeapAlloc(heap, flags, dwSize); ret = GetIfTable(*ppIfTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppIfTable); *ppIfTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetIpAddrTableFromStack (IPHLPAPI.@) * * PARAMS * ppIpAddrTable [Out] * bOrder [In] -- passed to GetIpAddrTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetIpAddrTableFromStack(PMIB_IPADDRTABLE *ppIpAddrTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppIpAddrTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppIpAddrTable, (DWORD)bOrder, heap, flags); if (!ppIpAddrTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppIpAddrTable = NULL; ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppIpAddrTable = (PMIB_IPADDRTABLE)HeapAlloc(heap, flags, dwSize); ret = GetIpAddrTable(*ppIpAddrTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppIpAddrTable); *ppIpAddrTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetIpForwardTableFromStack (IPHLPAPI.@) * * ppIpForwardTable [Out] -- pointer into which the MIB_IPFORWARDTABLE is * allocated and returned. * bOrder [In] -- passed to GetIfTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS -- ERROR_INVALID_PARAMETER if ppIfTable is NULL, whatever * GetIpForwardTable returns otherwise */DWORD WINAPI AllocateAndGetIpForwardTableFromStack(PMIB_IPFORWARDTABLE * ppIpForwardTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppIpForwardTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppIpForwardTable, (DWORD)bOrder, heap, flags); if (!ppIpForwardTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppIpForwardTable = NULL; ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppIpForwardTable = (PMIB_IPFORWARDTABLE)HeapAlloc(heap, flags, dwSize); ret = GetIpForwardTable(*ppIpForwardTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppIpForwardTable); *ppIpForwardTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetIpNetTableFromStack (IPHLPAPI.@) * * PARAMS * ppIpNetTable [Out] * bOrder [In] -- passed to GetIpNetTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetIpNetTableFromStack(PMIB_IPNETTABLE *ppIpNetTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppIpNetTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppIpNetTable, (DWORD)bOrder, heap, flags); if (!ppIpNetTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppIpNetTable = NULL; ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppIpNetTable = (PMIB_IPNETTABLE)HeapAlloc(heap, flags, dwSize); ret = GetIpNetTable(*ppIpNetTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppIpNetTable); *ppIpNetTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetTcpTableFromStack (IPHLPAPI.@) * * PARAMS * ppTcpTable [Out] * bOrder [In] -- passed to GetTcpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetTcpTableFromStack(PMIB_TCPTABLE *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppTcpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppTcpTable, (DWORD)bOrder, heap, flags); if (!ppTcpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppTcpTable = NULL; ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppTcpTable = (PMIB_TCPTABLE)HeapAlloc(heap, flags, dwSize); ret = GetTcpTable(*ppTcpTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppTcpTable); *ppTcpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetTcpExTableFromStack (IPHLPAPI.@) * * PARAMS * ppTcpTable [Out] * bOrder [In] -- passed to GetExtendedTcpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * family [In] -- passed to GetExtendedTcpTable to select INET family * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetTcpExTableFromStack(PVOID *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags, DWORD family){ DWORD ret;
TRACE("ppTcpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx, family 0x%08lx\n", ppTcpTable, (DWORD)bOrder, heap, flags, family); if (!ppTcpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppTcpTable = NULL; ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, TCP_TABLE_OWNER_PID_ALL, 0); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppTcpTable = (PMIB_TCPTABLE_OWNER_PID)HeapAlloc(heap, flags, dwSize); ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, TCP_TABLE_OWNER_PID_ALL, 0); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppTcpTable); *ppTcpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetTcpExTable2FromStack (IPHLPAPI.@) * * PARAMS * ppTcpTable [Out] * bOrder [In] -- passed to GetExtendedTcpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * family [In] -- passed to GetExtendedTcpTable to select INET family * class [In] -- passed to GetExtendedTcpTable to select information * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetTcpExTable2FromStack(PVOID *ppTcpTable, BOOL bOrder, HANDLE heap, DWORD flags, DWORD family, TCP_TABLE_CLASS class){ DWORD ret;
TRACE("ppTcpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx, family %ld, class %ld\n", ppTcpTable, (DWORD)bOrder, heap, flags, family, class); if (!ppTcpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppTcpTable = NULL; ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, class, 0); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppTcpTable = HeapAlloc(heap, flags, dwSize); ret = GetExtendedTcpTable(*ppTcpTable, &dwSize, bOrder, family, class, 0); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppTcpTable); *ppTcpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetUdpTableFromStack (IPHLPAPI.@) * * PARAMS * ppUdpTable [Out] * bOrder [In] -- passed to GetUdpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetUdpTableFromStack(PMIB_UDPTABLE *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags){ DWORD ret;
TRACE("ppUdpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx\n", ppUdpTable, (DWORD)bOrder, heap, flags); if (!ppUdpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppUdpTable = NULL; ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppUdpTable = (PMIB_UDPTABLE)HeapAlloc(heap, flags, dwSize); ret = GetUdpTable(*ppUdpTable, &dwSize, bOrder); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppUdpTable); *ppUdpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetUdpExTableFromStack (IPHLPAPI.@) * * PARAMS * ppUdpTable [Out] * bOrder [In] -- passed to GetExtendedUdpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * family [In] -- passed to GetExtendedUdpTable to select INET family * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetUdpExTableFromStack(PVOID *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags, DWORD family){ DWORD ret;
TRACE("ppUdpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx, family 0x%08lx\n", ppUdpTable, (DWORD)bOrder, heap, flags, family); if (!ppUdpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppUdpTable = NULL; ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, UDP_TABLE_OWNER_PID, 0); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppUdpTable = (PMIB_UDPTABLE_OWNER_PID)HeapAlloc(heap, flags, dwSize); ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, UDP_TABLE_OWNER_PID, 0); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppUdpTable); *ppUdpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * AllocateAndGetUdpExTable2FromStack (IPHLPAPI.@) * * PARAMS * ppUdpTable [Out] * bOrder [In] -- passed to GetExtendedUdpTable to order the table * heap [In] -- heap from which the table is allocated * flags [In] -- flags to HeapAlloc * family [In] -- passed to GetExtendedUdpTable to select INET family * class [In] -- passed to GetExtendedUdpTable to select information * * RETURNS * DWORD */DWORD WINAPI AllocateAndGetUdpExTable2FromStack(PVOID *ppUdpTable, BOOL bOrder, HANDLE heap, DWORD flags, DWORD family, UDP_TABLE_CLASS class){ DWORD ret;
TRACE("ppUdpTable %p, bOrder %ld, heap 0x%p, flags 0x%08lx, family %ld, class %ld\n", ppUdpTable, (DWORD)bOrder, heap, flags, family, class); if (!ppUdpTable) ret = ERROR_INVALID_PARAMETER; else { DWORD dwSize = 0;
*ppUdpTable = NULL; ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, class, 0); if (ret == ERROR_INSUFFICIENT_BUFFER) { *ppUdpTable = HeapAlloc(heap, flags, dwSize); ret = GetExtendedUdpTable(*ppUdpTable, &dwSize, bOrder, family, class, 0); if (ret != NO_ERROR) { HeapFree(heap, flags, *ppUdpTable); *ppUdpTable = NULL; } } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * CreateIpForwardEntry (IPHLPAPI.@) * * PARAMS * pRoute [In/Out] * * RETURNS * DWORD */DWORD WINAPI CreateIpForwardEntry(PMIB_IPFORWARDROW pRoute){ return createIpForwardEntry( pRoute );}
/****************************************************************** * CreateIpNetEntry (IPHLPAPI.@) * * PARAMS * pArpEntry [In/Out] * * RETURNS * DWORD */DWORD WINAPI CreateIpNetEntry(PMIB_IPNETROW pArpEntry){ TRACE("pArpEntry %p\n", pArpEntry); /* could use SIOCSARP on systems that support it, not sure I want to */ FIXME(":stub\n"); return (DWORD) 0;}
/****************************************************************** * CreateProxyArpEntry (IPHLPAPI.@) * * PARAMS * dwAddress [In] * dwMask [In] * dwIfIndex [In] * * RETURNS * DWORD */DWORD WINAPI CreateProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex){ TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress, dwMask, dwIfIndex); FIXME(":stub\n"); /* marking Win2K+ functions not supported */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * DeleteIPAddress (IPHLPAPI.@) * * PARAMS * NTEContext [In] * * RETURNS * DWORD */DWORD WINAPI DeleteIPAddress(ULONG NTEContext){ TRACE("NTEContext %ld\n", NTEContext); return RtlNtStatusToDosError(deleteIpAddress(NTEContext));}
/****************************************************************** * DeleteIpForwardEntry (IPHLPAPI.@) * * PARAMS * pRoute [In/Out] * * RETURNS * DWORD */DWORD WINAPI DeleteIpForwardEntry(PMIB_IPFORWARDROW pRoute){ return deleteIpForwardEntry( pRoute );}
/****************************************************************** * DeleteIpNetEntry (IPHLPAPI.@) * * PARAMS * pArpEntry [In/Out] * * RETURNS * DWORD */DWORD WINAPI DeleteIpNetEntry(PMIB_IPNETROW pArpEntry){ TRACE("pArpEntry %p\n", pArpEntry); /* could use SIOCDARP on systems that support it, not sure I want to */ FIXME(":stub\n"); return (DWORD) 0;}
/****************************************************************** * DeleteProxyArpEntry (IPHLPAPI.@) * * PARAMS * dwAddress [In] * dwMask [In] * dwIfIndex [In] * * RETURNS * DWORD */DWORD WINAPI DeleteProxyArpEntry(DWORD dwAddress, DWORD dwMask, DWORD dwIfIndex){ TRACE("dwAddress 0x%08lx, dwMask 0x%08lx, dwIfIndex 0x%08lx\n", dwAddress, dwMask, dwIfIndex); FIXME(":stub\n"); /* marking Win2K+ functions not supported */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * EnableRouter (IPHLPAPI.@) * * PARAMS * pHandle [In/Out] * pOverlapped [In/Out] * * RETURNS * DWORD */DWORD WINAPI EnableRouter(HANDLE * pHandle, OVERLAPPED * pOverlapped){ TRACE("pHandle %p, pOverlapped %p\n", pHandle, pOverlapped); FIXME(":stub\n"); /* could echo "1" > /proc/net/sys/net/ipv4/ip_forward, not sure I want to could map EACCESS to ERROR_ACCESS_DENIED, I suppose marking Win2K+ functions not supported */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * FlushIpNetTable (IPHLPAPI.@) * * PARAMS * dwIfIndex [In] * * RETURNS * DWORD */DWORD WINAPI FlushIpNetTable(DWORD dwIfIndex){ TRACE("dwIfIndex 0x%08lx\n", dwIfIndex); FIXME(":stub\n"); /* this flushes the arp cache of the given index marking Win2K+ functions not supported */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * GetAdapterIndex (IPHLPAPI.@) * * PARAMS * AdapterName [In/Out] * IfIndex [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex){ TRACE("AdapterName %p, IfIndex %p\n", AdapterName, IfIndex); FIXME(":stub\n"); /* marking Win2K+ functions not supported */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * GetAdaptersInfo (IPHLPAPI.@) * * PARAMS * pAdapterInfo [In/Out] * pOutBufLen [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen){ DWORD ret;
TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen); if (!pOutBufLen) ret = ERROR_INVALID_PARAMETER; else { DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces();
if (numNonLoopbackInterfaces > 0) { /* this calculation assumes only one address in the IP_ADDR_STRING lists. that's okay, because: - we don't get multiple addresses per adapter anyway - we don't know about per-adapter gateways - DHCP and WINS servers can have max one entry per list */ ULONG size = sizeof(IP_ADAPTER_INFO) * numNonLoopbackInterfaces;
if (!pAdapterInfo || *pOutBufLen < size) { *pOutBufLen = size; ret = ERROR_BUFFER_OVERFLOW; } else { InterfaceIndexTable *table = getNonLoopbackInterfaceIndexTable();
if (table) { size = sizeof(IP_ADAPTER_INFO) * table->numIndexes; if (*pOutBufLen < size) { *pOutBufLen = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { DWORD ndx; HKEY hKey; BOOL winsEnabled = FALSE; IP_ADDRESS_STRING primaryWINS, secondaryWINS;
memset(pAdapterInfo, 0, size); /* @@ Wine registry key: HKCU\Software\Wine\Network */ if (RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Network", &hKey) == ERROR_SUCCESS) { DWORD size = sizeof(primaryWINS.String); unsigned long addr;
RegQueryValueExA(hKey, "WinsServer", NULL, NULL, (PBYTE)primaryWINS.String, &size); addr = inet_addr(primaryWINS.String); if (addr != INADDR_NONE && addr != INADDR_ANY) winsEnabled = TRUE; size = sizeof(secondaryWINS.String); RegQueryValueExA(hKey, "BackupWinsServer", NULL, NULL, (PBYTE)secondaryWINS.String, &size); addr = inet_addr(secondaryWINS.String); if (addr != INADDR_NONE && addr != INADDR_ANY) winsEnabled = TRUE; RegCloseKey(hKey); } TRACE("num of index is %lu\n", table->numIndexes); for (ndx = 0; ndx < table->numIndexes; ndx++) { PIP_ADAPTER_INFO ptr = &pAdapterInfo[ndx]; DWORD addrLen = sizeof(ptr->Address), type; const char *ifname = getInterfaceNameByIndex(table->indexes[ndx]); if (!ifname) { ret = ERROR_OUTOFMEMORY; break; }
/* on Win98 this is left empty, but whatever */ strncpy(ptr->AdapterName,ifname,sizeof(ptr->AdapterName)); consumeInterfaceName(ifname); ptr->AdapterName[MAX_ADAPTER_NAME_LENGTH] = '\0'; getInterfacePhysicalByIndex(table->indexes[ndx], &addrLen, ptr->Address, &type); /* MS defines address length and type as UINT in some places and DWORD in others, **sigh**. Don't want to assume that PUINT and PDWORD are equiv (64-bit?) */ ptr->AddressLength = addrLen; ptr->Type = type; ptr->Index = table->indexes[ndx]; toIPAddressString(getInterfaceIPAddrByIndex(table->indexes[ndx]), ptr->IpAddressList.IpAddress.String); toIPAddressString(getInterfaceMaskByIndex(table->indexes[ndx]), ptr->IpAddressList.IpMask.String); ptr->IpAddressList.Context = ptr->Index; toIPAddressString(getInterfaceGatewayByIndex(table->indexes[ndx]), ptr->GatewayList.IpAddress.String); getDhcpInfoForAdapter(table->indexes[ndx], ptr); if (winsEnabled) { ptr->HaveWins = TRUE; memcpy(ptr->PrimaryWinsServer.IpAddress.String, primaryWINS.String, sizeof(primaryWINS.String)); memcpy(ptr->SecondaryWinsServer.IpAddress.String, secondaryWINS.String, sizeof(secondaryWINS.String)); } if (ndx < table->numIndexes - 1) ptr->Next = &pAdapterInfo[ndx + 1]; else ptr->Next = NULL; } ret = NO_ERROR; } free(table); } else ret = ERROR_OUTOFMEMORY; } } else ret = ERROR_NO_DATA; } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetBestInterface (IPHLPAPI.@) * * PARAMS * dwDestAddr [In] * pdwBestIfIndex [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetBestInterface(IPAddr dwDestAddr, PDWORD pdwBestIfIndex){ DWORD ret;
TRACE("dwDestAddr 0x%08lx, pdwBestIfIndex %p\n", dwDestAddr, pdwBestIfIndex); if (!pdwBestIfIndex) ret = ERROR_INVALID_PARAMETER; else { MIB_IPFORWARDROW ipRow;
ret = GetBestRoute(dwDestAddr, 0, &ipRow); if (ret == ERROR_SUCCESS) *pdwBestIfIndex = ipRow.dwForwardIfIndex; } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetBestRoute (IPHLPAPI.@) * * PARAMS * dwDestAddr [In] * dwSourceAddr [In] * OUT [In] * * RETURNS * DWORD */DWORD WINAPI GetBestRoute(DWORD dwDestAddr, DWORD dwSourceAddr, PMIB_IPFORWARDROW pBestRoute){ PMIB_IPFORWARDTABLE table; DWORD ret;
TRACE("dwDestAddr 0x%08lx, dwSourceAddr 0x%08lx, pBestRoute %p\n", dwDestAddr, dwSourceAddr, pBestRoute); if (!pBestRoute) return ERROR_INVALID_PARAMETER;
AllocateAndGetIpForwardTableFromStack(&table, FALSE, GetProcessHeap(), 0); if (table) { DWORD ndx, minMaskSize, matchedNdx = 0;
for (ndx = 0, minMaskSize = 255; ndx < table->dwNumEntries; ndx++) { if ((dwDestAddr & table->table[ndx].dwForwardMask) == (table->table[ndx].dwForwardDest & table->table[ndx].dwForwardMask)) { DWORD hostMaskSize;
if (!_BitScanForward(&hostMaskSize, ntohl(table->table[ndx].dwForwardMask))) { hostMaskSize = 32; } if (hostMaskSize < minMaskSize) { minMaskSize = hostMaskSize; matchedNdx = ndx; } } } memcpy(pBestRoute, &table->table[matchedNdx], sizeof(MIB_IPFORWARDROW)); HeapFree(GetProcessHeap(), 0, table); ret = ERROR_SUCCESS; } else ret = ERROR_OUTOFMEMORY; TRACE("returning %ld\n", ret); return ret;}
static int TcpTableSorter(const void *a, const void *b){ int ret;
if (a && b) { PMIB_TCPROW rowA = (PMIB_TCPROW)a, rowB = (PMIB_TCPROW)b;
ret = rowA->dwLocalAddr - rowB->dwLocalAddr; if (ret == 0) { ret = rowA->dwLocalPort - rowB->dwLocalPort; if (ret == 0) { ret = rowA->dwRemoteAddr - rowB->dwRemoteAddr; if (ret == 0) ret = rowA->dwRemotePort - rowB->dwRemotePort; } } } else ret = 0; return ret;}
/****************************************************************** * GetExtendedTcpTable (IPHLPAPI.@) * * Get the table of TCP endpoints available to the application. * * PARAMS * pTcpTable [Out] table struct with the filtered TCP endpoints available to application * pdwSize [In/Out] estimated size of the structure returned in pTcpTable, in bytes * bOrder [In] whether to order the table * ulAf [in] version of IP used by the TCP endpoints * TableClass [in] type of the TCP table structure from TCP_TABLE_CLASS * Reserved [in] reserved - this value must be zero * * RETURNS * Success: NO_ERROR * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER */DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved){ DWORD i, count, size; DWORD ret = NO_ERROR;
if (!pdwSize) { return ERROR_INVALID_PARAMETER; }
if (ulAf != AF_INET) { UNIMPLEMENTED; return ERROR_INVALID_PARAMETER; }
switch (TableClass) { case TCP_TABLE_BASIC_ALL: { PMIB_TCPTABLE pOurTcpTable = getTcpTable(ClassBasic); PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { size = FIELD_OFFSET(MIB_TCPTABLE, table) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirTcpTable, pOurTcpTable, size);
if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW), TcpTableSorter); }
HeapFree(GetProcessHeap(),0, pOurTcpTable); } } break;
case TCP_TABLE_BASIC_CONNECTIONS: { PMIB_TCPTABLE pOurTcpTable = getTcpTable(ClassBasic); PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].State != MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE, table) + count * sizeof(MIB_TCPROW); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].State != MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_BASIC_LISTENER: { PMIB_TCPTABLE pOurTcpTable = getTcpTable(ClassBasic); PMIB_TCPTABLE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].State == MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE, table) + count * sizeof(MIB_TCPROW); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].State == MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_PID_ALL: { PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getTcpTable(ClassModulePid); PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID, table) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW_OWNER_PID); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirTcpTable, pOurTcpTable, size);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_PID_CONNECTIONS: { PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getTcpTable(ClassModulePid); PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID, table) + count * sizeof(MIB_TCPROW_OWNER_PID); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_PID)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_PID_LISTENER: { PMIB_TCPTABLE_OWNER_PID pOurTcpTable = getTcpTable(ClassModulePid); PMIB_TCPTABLE_OWNER_PID pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_PID, table) + count * sizeof(MIB_TCPROW_OWNER_PID); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_PID)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_PID), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_MODULE_ALL: { PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable = getTcpTable(ClassModule); PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE, table) + pOurTcpTable->dwNumEntries * sizeof(MIB_TCPROW_OWNER_MODULE); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirTcpTable, pOurTcpTable, size);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_MODULE), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_MODULE_CONNECTIONS: { PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable = getTcpTable(ClassModule); PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE, table) + count * sizeof(MIB_TCPROW_OWNER_MODULE); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState != MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_MODULE)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_MODULE), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
case TCP_TABLE_OWNER_MODULE_LISTENER: { PMIB_TCPTABLE_OWNER_MODULE pOurTcpTable = getTcpTable(ClassModule); PMIB_TCPTABLE_OWNER_MODULE pTheirTcpTable = pTcpTable;
if (pOurTcpTable) { for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN) { ++count; } }
size = FIELD_OFFSET(MIB_TCPTABLE_OWNER_MODULE, table) + count * sizeof(MIB_TCPROW_OWNER_MODULE); if (size > *pdwSize || !pTheirTcpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { pTheirTcpTable->dwNumEntries = count;
for (i = 0, count = 0; i < pOurTcpTable->dwNumEntries; ++i) { if (pOurTcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN) { memcpy(&pTheirTcpTable->table[count], &pOurTcpTable->table[i], sizeof(MIB_TCPROW_OWNER_MODULE)); ++count; } } ASSERT(count == pTheirTcpTable->dwNumEntries);
/* Don't sort on PID, so use basic helper */ if (bOrder) qsort(pTheirTcpTable->table, pTheirTcpTable->dwNumEntries, sizeof(MIB_TCPROW_OWNER_MODULE), TcpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurTcpTable); } } break;
default: ret = ERROR_INVALID_PARAMETER; break; }
return ret;}
static int UdpTableSorter(const void *a, const void *b){ int ret;
if (a && b) { PMIB_UDPROW rowA = (PMIB_UDPROW)a, rowB = (PMIB_UDPROW)b;
ret = rowA->dwLocalAddr - rowB->dwLocalAddr; if (ret == 0) ret = rowA->dwLocalPort - rowB->dwLocalPort; } else ret = 0; return ret;}
/****************************************************************** * GetExtendedUdpTable (IPHLPAPI.@) * * Get the table of UDP endpoints available to the application. * * PARAMS * pUdpTable [Out] table struct with the filtered UDP endpoints available to application * pdwSize [In/Out] estimated size of the structure returned in pUdpTable, in bytes * bOrder [In] whether to order the table * ulAf [in] version of IP used by the UDP endpoints * TableClass [in] type of the UDP table structure from UDP_TABLE_CLASS * Reserved [in] reserved - this value must be zero * * RETURNS * Success: NO_ERROR * Failure: either ERROR_INSUFFICIENT_BUFFER or ERROR_INVALID_PARAMETER */DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved){ DWORD size; DWORD ret = NO_ERROR;
if (!pdwSize) { return ERROR_INVALID_PARAMETER; }
if (ulAf != AF_INET) { UNIMPLEMENTED; return ERROR_INVALID_PARAMETER; }
switch (TableClass) { case UDP_TABLE_BASIC: { PMIB_UDPTABLE pOurUdpTable = getUdpTable(ClassBasic); PMIB_UDPTABLE pTheirUdpTable = pUdpTable;
if (pOurUdpTable) { size = FIELD_OFFSET(MIB_UDPTABLE, table) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW); if (size > *pdwSize || !pTheirUdpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirUdpTable, pOurUdpTable, size);
if (bOrder) qsort(pTheirUdpTable->table, pTheirUdpTable->dwNumEntries, sizeof(MIB_UDPROW), UdpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurUdpTable); } } break;
case UDP_TABLE_OWNER_PID: { PMIB_UDPTABLE_OWNER_PID pOurUdpTable = getUdpTable(ClassModulePid); PMIB_UDPTABLE_OWNER_PID pTheirUdpTable = pUdpTable;
if (pOurUdpTable) { size = FIELD_OFFSET(MIB_UDPTABLE_OWNER_PID, table) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_PID); if (size > *pdwSize || !pTheirUdpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirUdpTable, pOurUdpTable, size);
if (bOrder) qsort(pTheirUdpTable->table, pTheirUdpTable->dwNumEntries, sizeof(MIB_UDPROW_OWNER_PID), UdpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurUdpTable); } } break;
case UDP_TABLE_OWNER_MODULE: { PMIB_UDPTABLE_OWNER_MODULE pOurUdpTable = getUdpTable(ClassModule); PMIB_UDPTABLE_OWNER_MODULE pTheirUdpTable = pUdpTable;
if (pOurUdpTable) { size = FIELD_OFFSET(MIB_UDPTABLE_OWNER_MODULE, table) + pOurUdpTable->dwNumEntries * sizeof(MIB_UDPROW_OWNER_MODULE); if (size > *pdwSize || !pTheirUdpTable) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { memcpy(pTheirUdpTable, pOurUdpTable, size);
if (bOrder) qsort(pTheirUdpTable->table, pTheirUdpTable->dwNumEntries, sizeof(MIB_UDPROW_OWNER_MODULE), UdpTableSorter); }
HeapFree(GetProcessHeap(), 0, pOurUdpTable); } } break;
default: ret = ERROR_INVALID_PARAMETER; break; }
return ret;}
/****************************************************************** * GetFriendlyIfIndex (IPHLPAPI.@) * * PARAMS * IfIndex [In] * * RETURNS * DWORD */DWORD WINAPI GetFriendlyIfIndex(DWORD IfIndex){ /* windows doesn't validate these, either, just makes sure the top byte is cleared. I assume my ifenum module never gives an index with the top byte set. */ TRACE("returning %ld\n", IfIndex); return IfIndex;}
/****************************************************************** * GetIcmpStatistics (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetIcmpStatistics(PMIB_ICMP pStats){ DWORD ret;
TRACE("pStats %p\n", pStats); ret = getICMPStats(pStats); TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetIfEntry (IPHLPAPI.@) * * PARAMS * pIfRow [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetIfEntry(PMIB_IFROW pIfRow){ DWORD ret; const char *name;
TRACE("pIfRow %p\n", pIfRow); if (!pIfRow) return ERROR_INVALID_PARAMETER;
name = getInterfaceNameByIndex(pIfRow->dwIndex); if (name) { ret = getInterfaceEntryByIndex(pIfRow->dwIndex, pIfRow); if (ret == NO_ERROR) ret = getInterfaceStatsByName(name, pIfRow); consumeInterfaceName(name); } else ret = ERROR_INVALID_DATA; TRACE("returning %ld\n", ret); return ret;}
static int IfTableSorter(const void *a, const void *b){ int ret;
if (a && b) ret = ((PMIB_IFROW)a)->dwIndex - ((PMIB_IFROW)b)->dwIndex; else ret = 0; return ret;}
/****************************************************************** * GetIfTable (IPHLPAPI.@) * * PARAMS * pIfTable [In/Out] * pdwSize [In/Out] * bOrder [In] * * RETURNS * DWORD */DWORD WINAPI GetIfTable(PMIB_IFTABLE pIfTable, PULONG pdwSize, BOOL bOrder){ DWORD ret;
TRACE("pIfTable %p, pdwSize %p, bOrder %ld\n", pdwSize, pdwSize, (DWORD)bOrder); if (!pdwSize) ret = ERROR_INVALID_PARAMETER; else { DWORD numInterfaces = getNumInterfaces(); ULONG size; TRACE("GetIfTable: numInterfaces = %d\n", (int)numInterfaces); size = sizeof(MIB_IFTABLE) + (numInterfaces - 1) * sizeof(MIB_IFROW);
if (!pIfTable || *pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { InterfaceIndexTable *table = getInterfaceIndexTable();
if (table) { size = sizeof(MIB_IFTABLE) + (table->numIndexes - 1) * sizeof(MIB_IFROW); if (*pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { DWORD ndx;
pIfTable->dwNumEntries = 0; for (ndx = 0; ndx < table->numIndexes; ndx++) { pIfTable->table[ndx].dwIndex = table->indexes[ndx]; GetIfEntry(&pIfTable->table[ndx]); pIfTable->dwNumEntries++; } if (bOrder) qsort(pIfTable->table, pIfTable->dwNumEntries, sizeof(MIB_IFROW), IfTableSorter); ret = NO_ERROR; } free(table); } else ret = ERROR_OUTOFMEMORY; } } TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetInterfaceInfo (IPHLPAPI.@) * * PARAMS * pIfTable [In/Out] * dwOutBufLen [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen){ DWORD ret;
TRACE("pIfTable %p, dwOutBufLen %p\n", pIfTable, dwOutBufLen); if (!dwOutBufLen) ret = ERROR_INVALID_PARAMETER; else { DWORD numNonLoopbackInterfaces = getNumNonLoopbackInterfaces(); ULONG size; TRACE("numNonLoopbackInterfaces == 0x%x\n", numNonLoopbackInterfaces); size = sizeof(IP_INTERFACE_INFO) + (numNonLoopbackInterfaces) * sizeof(IP_ADAPTER_INDEX_MAP);
if (!pIfTable || *dwOutBufLen < size) { *dwOutBufLen = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { InterfaceIndexTable *table = getNonLoopbackInterfaceIndexTable();
if (table) { TRACE("table->numIndexes == 0x%x\n", table->numIndexes); size = sizeof(IP_INTERFACE_INFO) + (table->numIndexes) * sizeof(IP_ADAPTER_INDEX_MAP); if (*dwOutBufLen < size) { *dwOutBufLen = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { DWORD ndx;
pIfTable->NumAdapters = 0; for (ndx = 0; ndx < table->numIndexes; ndx++) { const char *walker, *name; WCHAR *assigner;
pIfTable->Adapter[ndx].Index = table->indexes[ndx]; name = getInterfaceNameByIndex(table->indexes[ndx]); wcscpy(pIfTable->Adapter[ndx].Name, L"\\DEVICE\\TCPIP_"); for (walker = name, assigner = &pIfTable->Adapter[ndx].Name[14]; walker && *walker && assigner - pIfTable->Adapter[ndx].Name < MAX_ADAPTER_NAME - 1 - 14; walker++, assigner++) *assigner = *walker; *assigner = 0; consumeInterfaceName(name); pIfTable->NumAdapters++; } ret = NO_ERROR; } free(table); } else ret = ERROR_OUTOFMEMORY; } } TRACE("returning %ld\n", ret); return ret;}
static int IpAddrTableSorter(const void *a, const void *b){ int ret;
if (a && b) ret = ((PMIB_IPADDRROW)a)->dwAddr - ((PMIB_IPADDRROW)b)->dwAddr; else ret = 0; return ret;}
/****************************************************************** * GetIpAddrTable (IPHLPAPI.@) * * PARAMS * pIpAddrTable [In/Out] * pdwSize [In/Out] * bOrder [In] * * RETURNS * DWORD */DWORD WINAPI GetIpAddrTable(PMIB_IPADDRTABLE pIpAddrTable, PULONG pdwSize, BOOL bOrder){ DWORD ret;
TRACE("pIpAddrTable %p, pdwSize %p, bOrder %ld\n", pIpAddrTable, pdwSize, (DWORD)bOrder); if (!pdwSize) ret = ERROR_INVALID_PARAMETER; else { DWORD numInterfaces = getNumInterfaces(); ULONG size = sizeof(MIB_IPADDRTABLE) + (numInterfaces - 1) * sizeof(MIB_IPADDRROW);
if (!pIpAddrTable || *pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { InterfaceIndexTable *table = getInterfaceIndexTable();
if (table) { size = sizeof(MIB_IPADDRTABLE) + (table->numIndexes - 1) * sizeof(MIB_IPADDRROW); if (*pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { DWORD ndx, bcast;
pIpAddrTable->dwNumEntries = 0; for (ndx = 0; ndx < table->numIndexes; ndx++) { pIpAddrTable->table[ndx].dwIndex = table->indexes[ndx]; pIpAddrTable->table[ndx].dwAddr = getInterfaceIPAddrByIndex(table->indexes[ndx]); pIpAddrTable->table[ndx].dwMask = getInterfaceMaskByIndex(table->indexes[ndx]); /* the dwBCastAddr member isn't the broadcast address, it indicates * whether the interface uses the 1's broadcast address (1) or the * 0's broadcast address (0). */ bcast = getInterfaceBCastAddrByIndex(table->indexes[ndx]); pIpAddrTable->table[ndx].dwBCastAddr = (bcast & pIpAddrTable->table[ndx].dwMask) ? 1 : 0; /* FIXME: hardcoded reasm size, not sure where to get it */ pIpAddrTable->table[ndx].dwReasmSize = 65535; pIpAddrTable->table[ndx].unused1 = 0; pIpAddrTable->table[ndx].wType = 0; /* aka unused2 */ pIpAddrTable->dwNumEntries++; } if (bOrder) qsort(pIpAddrTable->table, pIpAddrTable->dwNumEntries, sizeof(MIB_IPADDRROW), IpAddrTableSorter); ret = NO_ERROR; } free(table); } else ret = ERROR_OUTOFMEMORY; } } TRACE("returning %ld\n", ret); return ret;}
static int IpForwardTableSorter(const void *a, const void *b){ int ret;
if (a && b) { PMIB_IPFORWARDROW rowA = (PMIB_IPFORWARDROW)a, rowB = (PMIB_IPFORWARDROW)b;
ret = rowA->dwForwardDest - rowB->dwForwardDest; if (ret == 0) { ret = rowA->dwForwardProto - rowB->dwForwardProto; if (ret == 0) { ret = rowA->dwForwardPolicy - rowB->dwForwardPolicy; if (ret == 0) ret = rowA->dwForwardNextHop - rowB->dwForwardNextHop; } } } else ret = 0; return ret;}
/****************************************************************** * GetIpForwardTable (IPHLPAPI.@) * * PARAMS * pIpForwardTable [In/Out] * pdwSize [In/Out] * bOrder [In] * * RETURNS * DWORD */DWORD WINAPI GetIpForwardTable(PMIB_IPFORWARDTABLE pIpForwardTable, PULONG pdwSize, BOOL bOrder){ DWORD ret;
TRACE("pIpForwardTable %p, pdwSize %p, bOrder %ld\n", pIpForwardTable, pdwSize, (DWORD)bOrder); if (!pdwSize) ret = ERROR_INVALID_PARAMETER; else { DWORD numRoutes = getNumRoutes(); ULONG sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (numRoutes - 1) * sizeof(MIB_IPFORWARDROW);
if (!pIpForwardTable || *pdwSize < sizeNeeded) { *pdwSize = sizeNeeded; ret = ERROR_INSUFFICIENT_BUFFER; } else { RouteTable *table = getRouteTable(); if (table) { sizeNeeded = sizeof(MIB_IPFORWARDTABLE) + (table->numRoutes - 1) * sizeof(MIB_IPFORWARDROW); if (*pdwSize < sizeNeeded) { *pdwSize = sizeNeeded; ret = ERROR_INSUFFICIENT_BUFFER; } else { DWORD ndx;
pIpForwardTable->dwNumEntries = table->numRoutes; for (ndx = 0; ndx < numRoutes; ndx++) { pIpForwardTable->table[ndx].dwForwardIfIndex = table->routes[ndx].ifIndex; pIpForwardTable->table[ndx].dwForwardDest = table->routes[ndx].dest; pIpForwardTable->table[ndx].dwForwardMask = table->routes[ndx].mask; pIpForwardTable->table[ndx].dwForwardPolicy = 0; pIpForwardTable->table[ndx].dwForwardNextHop = table->routes[ndx].gateway; /* FIXME: this type is appropriate for local interfaces; may not always be appropriate */ pIpForwardTable->table[ndx].dwForwardType = MIB_IPROUTE_TYPE_DIRECT; /* FIXME: other protos might be appropriate, e.g. the default route is typically set with MIB_IPPROTO_NETMGMT instead */ pIpForwardTable->table[ndx].dwForwardProto = MIB_IPPROTO_LOCAL; /* punt on age and AS */ pIpForwardTable->table[ndx].dwForwardAge = 0; pIpForwardTable->table[ndx].dwForwardNextHopAS = 0; pIpForwardTable->table[ndx].dwForwardMetric1 = table->routes[ndx].metric; /* rest of the metrics are 0.. */ pIpForwardTable->table[ndx].dwForwardMetric2 = 0; pIpForwardTable->table[ndx].dwForwardMetric3 = 0; pIpForwardTable->table[ndx].dwForwardMetric4 = 0; pIpForwardTable->table[ndx].dwForwardMetric5 = 0; } if (bOrder) qsort(pIpForwardTable->table, pIpForwardTable->dwNumEntries, sizeof(MIB_IPFORWARDROW), IpForwardTableSorter); ret = NO_ERROR; } HeapFree(GetProcessHeap(), 0, table); } else ret = ERROR_OUTOFMEMORY; } } TRACE("returning %ld\n", ret); return ret;}
static int IpNetTableSorter(const void *a, const void *b){ int ret;
if (a && b) ret = ((PMIB_IPNETROW)a)->dwAddr - ((PMIB_IPNETROW)b)->dwAddr; else ret = 0; return ret;}
/****************************************************************** * GetIpNetTable (IPHLPAPI.@) * * PARAMS * pIpNetTable [In/Out] * pdwSize [In/Out] * bOrder [In] * * RETURNS * DWORD */DWORD WINAPI GetIpNetTable(PMIB_IPNETTABLE pIpNetTable, PULONG pdwSize, BOOL bOrder){ DWORD ret = NO_ERROR;
TRACE("pIpNetTable %p, pdwSize %p, bOrder %d\n", pIpNetTable, pdwSize, (DWORD)bOrder); if (!pdwSize) ret = ERROR_INVALID_PARAMETER; else { DWORD numEntries = getNumArpEntries(); ULONG size = sizeof(MIB_IPNETTABLE);
if (numEntries > 1) size += (numEntries - 1) * sizeof(MIB_IPNETROW); if (!pIpNetTable || *pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { PMIB_IPNETTABLE table = getArpTable(); if (table) { size = sizeof(MIB_IPNETTABLE); if (table->dwNumEntries > 1) size += (table->dwNumEntries - 1) * sizeof(MIB_IPNETROW); if (*pdwSize < size) { *pdwSize = size; ret = ERROR_INSUFFICIENT_BUFFER; } else { *pdwSize = size; memcpy(pIpNetTable, table, size); if (bOrder) qsort(pIpNetTable->table, pIpNetTable->dwNumEntries, sizeof(MIB_IPNETROW), IpNetTableSorter); ret = NO_ERROR; } HeapFree(GetProcessHeap(), 0, table); } } } TRACE("returning %d\n", ret); return ret;}
/****************************************************************** * GetIpStatistics (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetIpStatistics(PMIB_IPSTATS pStats){ return GetIpStatisticsEx(pStats, PF_INET);}
/****************************************************************** * GetIpStatisticsEx (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * dwFamily [In] * * RETURNS * DWORD */DWORD WINAPI GetIpStatisticsEx(PMIB_IPSTATS pStats, DWORD dwFamily){ HANDLE tcpFile; DWORD ret;
if (!pStats) return ERROR_INVALID_PARAMETER;
if (dwFamily != AF_INET && dwFamily != AF_INET6) return ERROR_INVALID_PARAMETER;
if (!NT_SUCCESS(openTcpFile(&tcpFile, FILE_READ_DATA))) return ERROR_NOT_SUPPORTED;
TRACE("pStats %p\n", pStats); ret = getIPStats(tcpFile, pStats); closeTcpFile(tcpFile); TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetNetworkParams (IPHLPAPI.@) * * PARAMS * pFixedInfo [In/Out] * pOutBufLen [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetNetworkParams(PFIXED_INFO pFixedInfo, PULONG pOutBufLen){ DWORD ret, size, type; LONG regReturn; HKEY hKey; PIPHLP_RES_INFO resInfo;
TRACE("pFixedInfo %p, pOutBufLen %p\n", pFixedInfo, pOutBufLen); if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
resInfo = getResInfo(); if (!resInfo) return ERROR_OUTOFMEMORY;
size = sizeof(FIXED_INFO) + (resInfo->riCount > 1 ? (resInfo->riCount-1) * sizeof(IP_ADDR_STRING) : 0); if (!pFixedInfo || *pOutBufLen < size) { *pOutBufLen = size; disposeResInfo( resInfo ); return ERROR_BUFFER_OVERFLOW; }
memset(pFixedInfo, 0, size); /* Check for DhcpHostname and DhcpDomain first */ regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters", 0, KEY_READ, &hKey); if (regReturn == ERROR_SUCCESS) { /* Windows doesn't honor DHCP option 12 even if RFC requires it if it is returned by DHCP server! */#if 0 type = REG_SZ; size = sizeof(pFixedInfo->HostName); regReturn = RegQueryValueExA(hKey, "DhcpHostname", NULL, &type, (LPBYTE)pFixedInfo->HostName, &size); if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1)) {#endif type = REG_SZ; size = sizeof(pFixedInfo->HostName); regReturn = RegQueryValueExA(hKey, "Hostname", NULL, &type, (LPBYTE)pFixedInfo->HostName, &size);#if 0 }#endif
type = REG_SZ; size = sizeof(pFixedInfo->DomainName); regReturn = RegQueryValueExA(hKey, "DhcpDomain", NULL, &type, (LPBYTE)pFixedInfo->DomainName, &size); if (regReturn == ERROR_FILE_NOT_FOUND || (regReturn == ERROR_SUCCESS && size < 1)) { type = REG_SZ; size = sizeof(pFixedInfo->DomainName); regReturn = RegQueryValueExA(hKey, "Domain", NULL, &type, (LPBYTE)pFixedInfo->DomainName, &size); } RegCloseKey(hKey); }
TRACE("GetComputerNameExA: %s\n", pFixedInfo->DomainName);
if (resInfo->riCount > 0) { CopyMemory(&pFixedInfo->DnsServerList, resInfo->DnsList, sizeof(IP_ADDR_STRING)); if (resInfo->riCount > 1) { IP_ADDR_STRING *pSrc = resInfo->DnsList->Next; IP_ADDR_STRING *pTarget = (struct _IP_ADDR_STRING*)((char*)pFixedInfo + sizeof(FIXED_INFO));
pFixedInfo->DnsServerList.Next = pTarget;
do { CopyMemory(pTarget, pSrc, sizeof(IP_ADDR_STRING)); resInfo->riCount--; if (resInfo->riCount > 1) { pTarget->Next = (IP_ADDR_STRING*)((char*)pTarget + sizeof(IP_ADDR_STRING)); pTarget = pTarget->Next; pSrc = pSrc->Next; } else { pTarget->Next = NULL; break; } } while(TRUE); } else { pFixedInfo->DnsServerList.Next = NULL; } }
pFixedInfo->NodeType = HYBRID_NODETYPE; regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\VxD\\MSTCP", 0, KEY_READ, &hKey); if (regReturn != ERROR_SUCCESS) regReturn = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "SYSTEM\\CurrentControlSet\\Services\\NetBT\\Parameters", 0, KEY_READ, &hKey); if (regReturn == ERROR_SUCCESS) { DWORD size = sizeof(pFixedInfo->ScopeId);
RegQueryValueExA(hKey, "ScopeID", NULL, NULL, (PBYTE)pFixedInfo->ScopeId, &size); RegCloseKey(hKey); }
disposeResInfo( resInfo ); /* FIXME: can check whether routing's enabled in /proc/sys/net/ipv4/ip_forward I suppose could also check for a listener on port 53 to set EnableDns */ ret = NO_ERROR; TRACE("returning %ld\n", ret);
return ret;}
/****************************************************************** * GetNumberOfInterfaces (IPHLPAPI.@) * * PARAMS * pdwNumIf [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetNumberOfInterfaces(PDWORD pdwNumIf){ DWORD ret;
TRACE("pdwNumIf %p\n", pdwNumIf); if (!pdwNumIf) ret = ERROR_INVALID_PARAMETER; else { *pdwNumIf = getNumInterfaces(); ret = NO_ERROR; } TRACE("returning %ld\n", ret); return ret;}
static DWORD GetOwnerModuleFromPidEntry(DWORD OwningPid, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize){ HANDLE Process; DWORD FileLen, PathLen, Error; WCHAR File[MAX_PATH], Path[MAX_PATH]; PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo;
if (IsBadWritePtr(pdwSize, sizeof(DWORD)) || IsBadWritePtr(Buffer, *pdwSize)) { return ERROR_INVALID_PARAMETER; }
if (OwningPid == 0) { return ERROR_NOT_FOUND; }
Process = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, OwningPid); if (Process == NULL) { return GetLastError(); }
FileLen = GetModuleBaseNameW(Process, NULL, File, MAX_PATH); if (FileLen != 0) { PathLen = GetModuleFileNameExW(Process, NULL, Path, MAX_PATH); if (PathLen == 0) { CloseHandle(Process); return GetLastError(); }
/* Add NULL char */ ++FileLen; ++PathLen; PathLen *= sizeof(WCHAR); FileLen *= sizeof(WCHAR); } else { Error = GetLastError();
if (Error == ERROR_PARTIAL_COPY) { wcscpy(File, L"System"); wcscpy(Path, L"System");
PathLen = sizeof(L"System"); FileLen = sizeof(L"System"); } else { CloseHandle(Process); return Error; } }
CloseHandle(Process);
if (*pdwSize < sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen) { *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen; return ERROR_INSUFFICIENT_BUFFER; }
BasicInfo = Buffer; BasicInfo->pModuleName = (PVOID)((ULONG_PTR)BasicInfo + sizeof(TCPIP_OWNER_MODULE_BASIC_INFO)); BasicInfo->pModulePath = (PVOID)((ULONG_PTR)BasicInfo->pModuleName + FileLen); wcscpy(BasicInfo->pModuleName, File); wcscpy(BasicInfo->pModulePath, Path); *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + PathLen + FileLen;
return NO_ERROR;}
static DWORD GetOwnerModuleFromTagEntry(DWORD OwningPid, DWORD OwningTag, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize){ UINT Size; HRESULT Res; HANDLE hAdvapi32; WCHAR SysDir[MAX_PATH]; PTCPIP_OWNER_MODULE_BASIC_INFO BasicInfo; ULONG (NTAPI *_I_QueryTagInformation)(PVOID, DWORD, PVOID); struct { DWORD ProcessId; DWORD ServiceTag; DWORD TagType; PWSTR Buffer; } ServiceQuery;
if (IsBadWritePtr(pdwSize, sizeof(DWORD)) || IsBadWritePtr(Buffer, *pdwSize)) { return ERROR_INVALID_PARAMETER; }
/* First, secure (avoid injections) load advapi32.dll */ Size = GetSystemDirectoryW(SysDir, MAX_PATH); if (Size == 0) { return GetLastError(); }
Res = StringCchCatW(&SysDir[Size], MAX_PATH - Size, L"\\advapi32.dll"); if (FAILED(Res)) { return Res; }
hAdvapi32 = GetModuleHandleW(SysDir); if (hAdvapi32 == NULL) { return GetLastError(); }
/* Now, we'll query the service associated with the tag */ _I_QueryTagInformation = (PVOID)GetProcAddress(hAdvapi32, "I_QueryTagInformation"); if (_I_QueryTagInformation == NULL) { return GetLastError(); }
/* Set tag and PID for the query */ ServiceQuery.ProcessId = OwningPid; ServiceQuery.ServiceTag = OwningTag; ServiceQuery.TagType = 0; ServiceQuery.Buffer = NULL;
/* And query */ Res = _I_QueryTagInformation(NULL, 1, &ServiceQuery); if (Res != ERROR_SUCCESS) { return Res; }
/* Compute service name length */ Size = wcslen(ServiceQuery.Buffer) * sizeof(WCHAR) + sizeof(UNICODE_NULL);
/* We'll copy it twice, so make sure we have enough room */ if (*pdwSize < sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + 2 * Size) { *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + 2 * Size; LocalFree(ServiceQuery.Buffer); return ERROR_INSUFFICIENT_BUFFER; }
/* Copy back data */ BasicInfo = Buffer; BasicInfo->pModuleName = (PVOID)((ULONG_PTR)BasicInfo + sizeof(TCPIP_OWNER_MODULE_BASIC_INFO)); BasicInfo->pModulePath = (PVOID)((ULONG_PTR)BasicInfo->pModuleName + Size); wcscpy(BasicInfo->pModuleName, ServiceQuery.Buffer); wcscpy(BasicInfo->pModulePath, ServiceQuery.Buffer); *pdwSize = sizeof(TCPIP_OWNER_MODULE_BASIC_INFO) + 2 * Size; LocalFree(ServiceQuery.Buffer);
return NO_ERROR;}
/****************************************************************** * GetOwnerModuleFromTcpEntry (IPHLPAPI.@) * * Get data about the module that issued the context bind for a specific IPv4 TCP endpoint in a MIB table row * * PARAMS * pTcpEntry [in] pointer to a MIB_TCPROW_OWNER_MODULE structure * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data. * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes * * RETURNS * Success: NO_ERROR * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY * * NOTES * The type of data returned in Buffer is indicated by the value of the Class parameter. */DWORD WINAPI GetOwnerModuleFromTcpEntry(PMIB_TCPROW_OWNER_MODULE pTcpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize){ /* If we have a service tag, that's a service connection */ if (pTcpEntry->OwningModuleInfo[0] != 0) { return GetOwnerModuleFromTagEntry(pTcpEntry->dwOwningPid, (DWORD)(pTcpEntry->OwningModuleInfo[0]), Class, Buffer, pdwSize); } else { return GetOwnerModuleFromPidEntry(pTcpEntry->dwOwningPid, Class, Buffer, pdwSize); }}
/****************************************************************** * GetOwnerModuleFromUdpEntry (IPHLPAPI.@) * * Get data about the module that issued the context bind for a specific IPv4 UDP endpoint in a MIB table row * * PARAMS * pUdpEntry [in] pointer to a MIB_UDPROW_OWNER_MODULE structure * Class [in] TCPIP_OWNER_MODULE_INFO_CLASS enumeration value * Buffer [out] pointer a buffer containing a TCPIP_OWNER_MODULE_BASIC_INFO structure with the owner module data. * pdwSize [in, out] estimated size of the structure returned in Buffer, in bytes * * RETURNS * Success: NO_ERROR * Failure: ERROR_INSUFFICIENT_BUFFER, ERROR_INVALID_PARAMETER, ERROR_NOT_ENOUGH_MEMORY * ERROR_NOT_FOUND or ERROR_PARTIAL_COPY * * NOTES * The type of data returned in Buffer is indicated by the value of the Class parameter. */DWORD WINAPI GetOwnerModuleFromUdpEntry(PMIB_UDPROW_OWNER_MODULE pUdpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize){ /* If we have a service tag, that's a service connection */ if (pUdpEntry->OwningModuleInfo[0] != 0) { return GetOwnerModuleFromTagEntry(pUdpEntry->dwOwningPid, (DWORD)(pUdpEntry->OwningModuleInfo[0]), Class, Buffer, pdwSize); } else { return GetOwnerModuleFromPidEntry(pUdpEntry->dwOwningPid, Class, Buffer, pdwSize); }}
static void CreateNameServerListEnumNamesFunc( PWCHAR Interface, PWCHAR Server, PVOID Data){ IP_ADDR_STRING *pNext; PNAME_SERVER_LIST_CONTEXT Context = (PNAME_SERVER_LIST_CONTEXT)Data;
if (!Context->NumServers) { if (Context->uSizeAvailable >= Context->uSizeRequired) { WideCharToMultiByte(CP_ACP, 0, Server, -1, Context->pData->DnsServerList.IpAddress.String, 16, NULL, NULL); Context->pData->DnsServerList.IpAddress.String[15] = '\0'; Context->pLastAddr = &Context->pData->DnsServerList; } } else { Context->uSizeRequired += sizeof(IP_ADDR_STRING); if (Context->uSizeAvailable >= Context->uSizeRequired) { pNext = (IP_ADDR_STRING*)(((char*)Context->pLastAddr) + sizeof(IP_ADDR_STRING)); WideCharToMultiByte(CP_ACP, 0, Server, -1, pNext->IpAddress.String, 16, NULL, NULL); pNext->IpAddress.String[15] = '\0'; Context->pLastAddr->Next = pNext; Context->pLastAddr = pNext; pNext->Next = NULL; } } Context->NumServers++;}
/****************************************************************** * GetPerAdapterInfo (IPHLPAPI.@) * * PARAMS * IfIndex [In] * pPerAdapterInfo [In/Out] * pOutBufLen [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetPerAdapterInfo(ULONG IfIndex, PIP_PER_ADAPTER_INFO pPerAdapterInfo, PULONG pOutBufLen){ HKEY hkey; DWORD dwSize = 0; const char *ifName; NAME_SERVER_LIST_CONTEXT Context; WCHAR keyname[200] = L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces\\";
if (!pOutBufLen) return ERROR_INVALID_PARAMETER;
if (!pPerAdapterInfo || *pOutBufLen < sizeof(IP_PER_ADAPTER_INFO)) { *pOutBufLen = sizeof(IP_PER_ADAPTER_INFO); return ERROR_BUFFER_OVERFLOW; }
ifName = getInterfaceNameByIndex(IfIndex); if (!ifName) return ERROR_INVALID_PARAMETER;
MultiByteToWideChar(CP_ACP, 0, ifName, -1, &keyname[62], sizeof(keyname)/sizeof(WCHAR) - 63); HeapFree(GetProcessHeap(), 0, (LPVOID)ifName);
if (RegOpenKeyExW(HKEY_LOCAL_MACHINE, keyname, 0, KEY_READ, &hkey) != ERROR_SUCCESS) { return ERROR_NOT_SUPPORTED; } Context.NumServers = 0; Context.uSizeAvailable = *pOutBufLen; Context.uSizeRequired = sizeof(IP_PER_ADAPTER_INFO); Context.pData = pPerAdapterInfo;
if (*pOutBufLen >= sizeof(IP_PER_ADAPTER_INFO)) ZeroMemory(pPerAdapterInfo, sizeof(IP_PER_ADAPTER_INFO));
EnumNameServers(hkey, &keyname[62], &Context, CreateNameServerListEnumNamesFunc);
if (Context.uSizeRequired > Context.uSizeAvailable) { *pOutBufLen = Context.uSizeRequired; RegCloseKey(hkey); return ERROR_BUFFER_OVERFLOW; }
if(RegQueryValueExW(hkey, L"NameServer", NULL, NULL, NULL, &dwSize) == ERROR_SUCCESS) { pPerAdapterInfo->AutoconfigActive = FALSE; } else { pPerAdapterInfo->AutoconfigActive = TRUE; }
RegCloseKey(hkey); return NOERROR;}
/****************************************************************** * GetRTTAndHopCount (IPHLPAPI.@) * * PARAMS * DestIpAddress [In] * HopCount [In/Out] * MaxHops [In] * RTT [In/Out] * * RETURNS * BOOL */BOOL WINAPI GetRTTAndHopCount(IPAddr DestIpAddress, PULONG HopCount, ULONG MaxHops, PULONG RTT){ TRACE("DestIpAddress 0x%08lx, HopCount %p, MaxHops %ld, RTT %p\n", DestIpAddress, HopCount, MaxHops, RTT); FIXME(":stub\n"); return (BOOL) 0;}
/****************************************************************** * GetTcpStatisticsEx (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * dwFamily [In] * * RETURNS * DWORD */DWORD WINAPI GetTcpStatisticsEx(PMIB_TCPSTATS pStats, DWORD dwFamily){ HANDLE tcpFile; DWORD ret;
if (!pStats) return ERROR_INVALID_PARAMETER;
if (dwFamily != AF_INET && dwFamily != AF_INET6) return ERROR_INVALID_PARAMETER;
if (!NT_SUCCESS(openTcpFile(&tcpFile, FILE_READ_DATA))) return ERROR_NOT_SUPPORTED;
TRACE("pStats %p\n", pStats); ret = getTCPStats(tcpFile, pStats); closeTcpFile(tcpFile); TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetTcpStatistics (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetTcpStatistics(PMIB_TCPSTATS pStats){ return GetTcpStatisticsEx(pStats, PF_INET);}
/****************************************************************** * GetTcpTable (IPHLPAPI.@) * * Get the table of active TCP connections. * * PARAMS * pTcpTable [Out] buffer for TCP connections table * pdwSize [In/Out] length of output buffer * bOrder [In] whether to order the table * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * NOTES * If pdwSize is less than required, the function will return * ERROR_INSUFFICIENT_BUFFER, and *pdwSize will be set to * the required byte size. * If bOrder is true, the returned table will be sorted, first by * local address and port number, then by remote address and port * number. */DWORD WINAPI GetTcpTable(PMIB_TCPTABLE pTcpTable, PDWORD pdwSize, BOOL bOrder){ return GetExtendedTcpTable(pTcpTable, pdwSize, bOrder, AF_INET, TCP_TABLE_BASIC_ALL, 0);}
/****************************************************************** * GetUdpStatisticsEx (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * dwFamily [In] * * RETURNS * DWORD */DWORD WINAPI GetUdpStatisticsEx(PMIB_UDPSTATS pStats, DWORD dwFamily){ HANDLE tcpFile; DWORD ret;
if (!pStats) return ERROR_INVALID_PARAMETER;
if (dwFamily != AF_INET && dwFamily != AF_INET6) return ERROR_INVALID_PARAMETER;
if (!NT_SUCCESS(openTcpFile(&tcpFile, FILE_READ_DATA))) return ERROR_NOT_SUPPORTED;
TRACE("pStats %p\n", pStats); ret = getUDPStats(tcpFile, pStats); closeTcpFile(tcpFile); TRACE("returning %ld\n", ret); return ret;}
/****************************************************************** * GetUdpStatistics (IPHLPAPI.@) * * PARAMS * pStats [In/Out] * * RETURNS * DWORD */DWORD WINAPI GetUdpStatistics(PMIB_UDPSTATS pStats){ return GetUdpStatisticsEx(pStats, PF_INET);}
/****************************************************************** * GetUdpTable (IPHLPAPI.@) * * PARAMS * pUdpTable [In/Out] * pdwSize [In/Out] * bOrder [In] * * RETURNS * DWORD */DWORD WINAPI GetUdpTable(PMIB_UDPTABLE pUdpTable, PDWORD pdwSize, BOOL bOrder){ return GetExtendedUdpTable(pUdpTable, pdwSize, bOrder, AF_INET, UDP_TABLE_BASIC, 0);}
/****************************************************************** * GetUniDirectionalAdapterInfo (IPHLPAPI.@) * * This is a Win98-only function to get information on "unidirectional" * adapters. Since this is pretty nonsensical in other contexts, it * never returns anything. * * PARAMS * pIPIfInfo [Out] buffer for adapter infos * dwOutBufLen [Out] length of the output buffer * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns ERROR_NOT_SUPPORTED. */DWORD WINAPI GetUniDirectionalAdapterInfo(PIP_UNIDIRECTIONAL_ADAPTER_ADDRESS pIPIfInfo, PULONG dwOutBufLen){ TRACE("pIPIfInfo %p, dwOutBufLen %p\n", pIPIfInfo, dwOutBufLen); /* a unidirectional adapter?? not bloody likely! */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * IpReleaseAddress (IPHLPAPI.@) * * Release an IP obtained through DHCP, * * PARAMS * AdapterInfo [In] adapter to release IP address * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h */DWORD WINAPI IpReleaseAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo){ DWORD Status, Version = 0;
if (!AdapterInfo) return ERROR_INVALID_PARAMETER;
/* Maybe we should do this in DllMain */ if (DhcpCApiInitialize(&Version) != ERROR_SUCCESS) return ERROR_PROC_NOT_FOUND;
Status = DhcpReleaseParameters(AdapterInfo->Name);
DhcpCApiCleanup();
return Status;}
/****************************************************************** * IpRenewAddress (IPHLPAPI.@) * * Renew an IP obtained through DHCP. * * PARAMS * AdapterInfo [In] adapter to renew IP address * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h */DWORD WINAPI IpRenewAddress(PIP_ADAPTER_INDEX_MAP AdapterInfo){ DWORD Status, Version = 0;
if (!AdapterInfo) return ERROR_INVALID_PARAMETER;
/* Maybe we should do this in DllMain */ if (DhcpCApiInitialize(&Version) != ERROR_SUCCESS) return ERROR_PROC_NOT_FOUND;
Status = DhcpAcquireParameters(AdapterInfo->Name);
DhcpCApiCleanup();
return Status;}
/****************************************************************** * NotifyAddrChange (IPHLPAPI.@) * * Notify caller whenever the ip-interface map is changed. * * PARAMS * Handle [Out] handle usable in asynchronous notification * overlapped [In] overlapped structure that notifies the caller * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns ERROR_NOT_SUPPORTED. */DWORD WINAPI NotifyAddrChange(PHANDLE Handle, LPOVERLAPPED overlapped){ FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped); if (Handle) *Handle = INVALID_HANDLE_VALUE; if (overlapped) ((IO_STATUS_BLOCK *) overlapped)->Status = STATUS_PENDING; return ERROR_IO_PENDING;}
/****************************************************************** * NotifyRouteChange (IPHLPAPI.@) * * Notify caller whenever the ip routing table is changed. * * PARAMS * Handle [Out] handle usable in asynchronous notification * overlapped [In] overlapped structure that notifies the caller * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns ERROR_NOT_SUPPORTED. */DWORD WINAPI NotifyRouteChange(PHANDLE Handle, LPOVERLAPPED overlapped){ FIXME("(Handle %p, overlapped %p): stub\n", Handle, overlapped); return ERROR_NOT_SUPPORTED;}
/****************************************************************** * SendARP (IPHLPAPI.@) * * Send an ARP request. * * PARAMS * DestIP [In] attempt to obtain this IP * SrcIP [In] optional sender IP address * pMacAddr [Out] buffer for the mac address * PhyAddrLen [In/Out] length of the output buffer * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h */DWORD WINAPI SendARP(IPAddr DestIP, IPAddr SrcIP, PULONG pMacAddr, PULONG PhyAddrLen){ IPAddr IPs[2]; ULONG Size;
if (IsBadWritePtr(pMacAddr, sizeof(ULONG)) || IsBadWritePtr(PhyAddrLen, sizeof(ULONG))) return ERROR_INVALID_PARAMETER;
IPs[0] = DestIP; IPs[1] = SrcIP; Size = sizeof(IPs); return TCPSendIoctl(INVALID_HANDLE_VALUE, IOCTL_QUERY_IP_HW_ADDRESS, IPs, &Size, pMacAddr, PhyAddrLen);}
/****************************************************************** * SetIfEntry (IPHLPAPI.@) * * Set the administrative status of an interface. * * PARAMS * pIfRow [In] dwAdminStatus member specifies the new status. * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns ERROR_NOT_SUPPORTED. */DWORD WINAPI SetIfEntry(PMIB_IFROW pIfRow){ FIXME("(pIfRow %p): stub\n", pIfRow); /* this is supposed to set an interface administratively up or down. Could do SIOCSIFFLAGS and set/clear IFF_UP, but, not sure I want to, and this sort of down is indistinguishable from other sorts of down (e.g. no link). */ return ERROR_NOT_SUPPORTED;}
/****************************************************************** * SetIpForwardEntry (IPHLPAPI.@) * * Modify an existing route. * * PARAMS * pRoute [In] route with the new information * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h */DWORD WINAPI SetIpForwardEntry(PMIB_IPFORWARDROW pRoute){ return setIpForwardEntry( pRoute );}
/****************************************************************** * SetIpNetEntry (IPHLPAPI.@) * * Modify an existing ARP entry. * * PARAMS * pArpEntry [In] ARP entry with the new information * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h */DWORD WINAPI SetIpNetEntry(PMIB_IPNETROW pArpEntry){ HANDLE tcpFile; NTSTATUS status; TCP_REQUEST_SET_INFORMATION_EX_ARP_ENTRY req = TCP_REQUEST_SET_INFORMATION_INIT; TDIEntityID id; DWORD returnSize; PMIB_IPNETROW arpBuff;
if (!pArpEntry) return ERROR_INVALID_PARAMETER;
if (!NT_SUCCESS(openTcpFile( &tcpFile, FILE_READ_DATA | FILE_WRITE_DATA ))) return ERROR_NOT_SUPPORTED;
if (!NT_SUCCESS(getNthIpEntity( tcpFile, pArpEntry->dwIndex, &id ))) { closeTcpFile(tcpFile); return ERROR_INVALID_PARAMETER; }
req.Req.ID.toi_class = INFO_CLASS_PROTOCOL; req.Req.ID.toi_type = INFO_TYPE_PROVIDER; req.Req.ID.toi_id = IP_MIB_ARPTABLE_ENTRY_ID; req.Req.ID.toi_entity.tei_instance = id.tei_instance; req.Req.ID.toi_entity.tei_entity = AT_ENTITY; req.Req.BufferSize = sizeof(MIB_IPNETROW); arpBuff = (PMIB_IPNETROW)&req.Req.Buffer[0];
RtlCopyMemory(arpBuff, pArpEntry, sizeof(MIB_IPNETROW));
status = DeviceIoControl( tcpFile, IOCTL_TCP_SET_INFORMATION_EX, &req, sizeof(req), NULL, 0, &returnSize, NULL );
closeTcpFile(tcpFile);
if (status) return NO_ERROR; else return ERROR_INVALID_PARAMETER;}
/****************************************************************** * SetIpStatistics (IPHLPAPI.@) * * Toggle IP forwarding and det the default TTL value. * * PARAMS * pIpStats [In] IP statistics with the new information * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns NO_ERROR. */DWORD WINAPI SetIpStatistics(PMIB_IPSTATS pIpStats){ FIXME("(pIpStats %p): stub\n", pIpStats); return 0;}
/****************************************************************** * SetIpTTL (IPHLPAPI.@) * * Set the default TTL value. * * PARAMS * nTTL [In] new TTL value * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns NO_ERROR. */DWORD WINAPI SetIpTTL(UINT nTTL){ FIXME("(nTTL %d): stub\n", nTTL); return 0;}
/****************************************************************** * SetTcpEntry (IPHLPAPI.@) * * Set the state of a TCP connection. * * PARAMS * pTcpRow [In] specifies connection with new state * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns NO_ERROR. */DWORD WINAPI SetTcpEntry(PMIB_TCPROW pTcpRow){ FIXME("(pTcpRow %p): stub\n", pTcpRow); return 0;}
/****************************************************************** * UnenableRouter (IPHLPAPI.@) * * Decrement the IP-forwarding reference count. Turn off IP-forwarding * if it reaches zero. * * PARAMS * pOverlapped [In/Out] should be the same as in EnableRouter() * lpdwEnableCount [Out] optional, receives reference count * * RETURNS * Success: NO_ERROR * Failure: error code from winerror.h * * FIXME * Stub, returns ERROR_NOT_SUPPORTED. */DWORD WINAPI UnenableRouter(OVERLAPPED * pOverlapped, LPDWORD lpdwEnableCount){ FIXME("(pOverlapped %p, lpdwEnableCount %p): stub\n", pOverlapped, lpdwEnableCount); return ERROR_NOT_SUPPORTED;}
/* * @unimplemented */DWORD WINAPI GetIpErrorString(IP_STATUS ErrorCode,PWCHAR Buffer,PDWORD Size){ FIXME(":stub\n"); return 0L;}
/* * @unimplemented */PIP_ADAPTER_ORDER_MAP WINAPI GetAdapterOrderMap(VOID){ FIXME(":stub\n"); return 0L;}
#ifdef GetAdaptersAddressesV1DWORD WINAPI DECLSPEC_HOTPATCH GetAdaptersAddresses(ULONG Family,ULONG Flags,PVOID Reserved,PIP_ADAPTER_ADDRESSES pAdapterAddresses,PULONG pOutBufLen){ InterfaceIndexTable *indexTable; IFInfo ifInfo; int i; ULONG ret, requiredSize = 0; PIP_ADAPTER_ADDRESSES currentAddress; PUCHAR currentLocation; HANDLE tcpFile;
if (!pOutBufLen) return ERROR_INVALID_PARAMETER; if (Reserved) return ERROR_INVALID_PARAMETER;
indexTable = getInterfaceIndexTable(); if (!indexTable) return ERROR_NOT_ENOUGH_MEMORY;
ret = openTcpFile(&tcpFile, FILE_READ_DATA); if (!NT_SUCCESS(ret)) { free(indexTable); return ERROR_NO_DATA; }
for (i = indexTable->numIndexes; i >= 0; i--) { if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile, NULL, indexTable->indexes[i], &ifInfo))) { /* The whole struct */ requiredSize += sizeof(IP_ADAPTER_ADDRESSES);
/* Friendly name */ if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME)) requiredSize += ifInfo.if_info.ent.if_descrlen + 1; //FIXME
/* Adapter name */ requiredSize += ifInfo.if_info.ent.if_descrlen + 1;
/* Unicast address */ if (!(Flags & GAA_FLAG_SKIP_UNICAST)) requiredSize += sizeof(IP_ADAPTER_UNICAST_ADDRESS);
/* FIXME: Implement multicast, anycast, and dns server stuff */
/* FIXME: Implement dns suffix and description */ requiredSize += 2 * sizeof(WCHAR);
/* We're only going to implement what's required for XP SP0 */ } } TRACE("size: %d, requiredSize: %d\n", *pOutBufLen, requiredSize); if (!pAdapterAddresses || *pOutBufLen < requiredSize) { *pOutBufLen = requiredSize; closeTcpFile(tcpFile); free(indexTable); return ERROR_BUFFER_OVERFLOW; }
RtlZeroMemory(pAdapterAddresses, requiredSize);
/* Let's set up the pointers */ currentAddress = pAdapterAddresses; for (i = indexTable->numIndexes; i >= 0; i--) { if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile, NULL, indexTable->indexes[i], &ifInfo))) { currentLocation = (PUCHAR)currentAddress + (ULONG_PTR)sizeof(IP_ADAPTER_ADDRESSES);
/* FIXME: Friendly name */ if (!(Flags & GAA_FLAG_SKIP_FRIENDLY_NAME)) { currentAddress->FriendlyName = (PVOID)currentLocation; currentLocation += sizeof(WCHAR); }
/* Adapter name */ currentAddress->AdapterName = (PVOID)currentLocation; currentLocation += ifInfo.if_info.ent.if_descrlen + 1;
/* Unicast address */ if (!(Flags & GAA_FLAG_SKIP_UNICAST)) { currentAddress->FirstUnicastAddress = (PVOID)currentLocation; currentLocation += sizeof(IP_ADAPTER_UNICAST_ADDRESS); currentAddress->FirstUnicastAddress->Address.lpSockaddr = (PVOID)currentLocation; currentLocation += sizeof(struct sockaddr); }
/* FIXME: Implement multicast, anycast, and dns server stuff */
/* FIXME: Implement dns suffix and description */ currentAddress->DnsSuffix = (PVOID)currentLocation; currentLocation += sizeof(WCHAR);
currentAddress->Description = (PVOID)currentLocation; currentLocation += sizeof(WCHAR);
currentAddress->Next = (PVOID)currentLocation; /* Terminate the last address correctly */ if(i==0) currentAddress->Next = NULL;
/* We're only going to implement what's required for XP SP0 */
currentAddress = currentAddress->Next; } }
/* Now again, for real this time */
currentAddress = pAdapterAddresses; for (i = indexTable->numIndexes; i >= 0; i--) { if (NT_SUCCESS(getIPAddrEntryForIf(tcpFile, NULL, indexTable->indexes[i], &ifInfo))) { /* Make sure we're not looping more than we hoped for */ ASSERT(currentAddress);
/* Alignment information */ currentAddress->Length = sizeof(IP_ADAPTER_ADDRESSES); currentAddress->IfIndex = indexTable->indexes[i];
/* Adapter name */ memcpy(currentAddress->AdapterName, ifInfo.if_info.ent.if_descr, ifInfo.if_info.ent.if_descrlen); currentAddress->AdapterName[ifInfo.if_info.ent.if_descrlen] = '\0';
if (!(Flags & GAA_FLAG_SKIP_UNICAST)) { currentAddress->FirstUnicastAddress->Length = sizeof(IP_ADAPTER_UNICAST_ADDRESS); currentAddress->FirstUnicastAddress->Flags = 0; //FIXME currentAddress->FirstUnicastAddress->Next = NULL; //FIXME: Support more than one address per adapter currentAddress->FirstUnicastAddress->Address.lpSockaddr->sa_family = AF_INET; memcpy(currentAddress->FirstUnicastAddress->Address.lpSockaddr->sa_data, &ifInfo.ip_addr.iae_addr, sizeof(ifInfo.ip_addr.iae_addr)); currentAddress->FirstUnicastAddress->Address.iSockaddrLength = sizeof(ifInfo.ip_addr.iae_addr) + sizeof(USHORT); currentAddress->FirstUnicastAddress->PrefixOrigin = IpPrefixOriginOther; //FIXME currentAddress->FirstUnicastAddress->SuffixOrigin = IpPrefixOriginOther; //FIXME currentAddress->FirstUnicastAddress->DadState = IpDadStatePreferred; //FIXME currentAddress->FirstUnicastAddress->ValidLifetime = 0xFFFFFFFF; //FIXME currentAddress->FirstUnicastAddress->PreferredLifetime = 0xFFFFFFFF; //FIXME currentAddress->FirstUnicastAddress->LeaseLifetime = 0xFFFFFFFF; //FIXME }
/* FIXME: Implement multicast, anycast, and dns server stuff */ currentAddress->FirstAnycastAddress = NULL; currentAddress->FirstMulticastAddress = NULL; currentAddress->FirstDnsServerAddress = NULL;
/* FIXME: Implement dns suffix, description, and friendly name */ currentAddress->DnsSuffix[0] = UNICODE_NULL; currentAddress->Description[0] = UNICODE_NULL; currentAddress->FriendlyName[0] = UNICODE_NULL;
/* Physical Address */ memcpy(currentAddress->PhysicalAddress, ifInfo.if_info.ent.if_physaddr, ifInfo.if_info.ent.if_physaddrlen); currentAddress->PhysicalAddressLength = ifInfo.if_info.ent.if_physaddrlen;
/* Flags */ currentAddress->Flags = 0; //FIXME
/* MTU */ currentAddress->Mtu = ifInfo.if_info.ent.if_mtu;
/* Interface type */ currentAddress->IfType = ifInfo.if_info.ent.if_type;
/* Operational status */ if(ifInfo.if_info.ent.if_operstatus >= IF_OPER_STATUS_CONNECTING) currentAddress->OperStatus = IfOperStatusUp; else currentAddress->OperStatus = IfOperStatusDown;
/* We're only going to implement what's required for XP SP0 */
/* Move to the next address */ currentAddress = currentAddress->Next; } }
closeTcpFile(tcpFile); free(indexTable);
return NO_ERROR;}#endif
/* * @unimplemented */BOOL WINAPI CancelIPChangeNotify(LPOVERLAPPED notifyOverlapped){ FIXME(":stub\n"); return 0L;}
/* * @unimplemented */DWORD WINAPI GetBestInterfaceEx(struct sockaddr *pDestAddr,PDWORD pdwBestIfIndex){ FIXME(":stub\n"); return 0L;}
#ifdef GetAdaptersAddressesV1/* * @unimplemented */DWORD WINAPI NhpAllocateAndGetInterfaceInfoFromStack(IP_INTERFACE_NAME_INFO **ppTable,PDWORD pdwCount,BOOL bOrder,HANDLE hHeap,DWORD dwFlags){ FIXME(":stub\n"); return 0L;}#endif
/* * @unimplemented */DWORD WINAPI GetIcmpStatisticsEx(PMIB_ICMP_EX pStats,DWORD dwFamily){ FIXME(":stub\n");
if (!pStats) return ERROR_INVALID_PARAMETER;
if (dwFamily != AF_INET && dwFamily != AF_INET6) return ERROR_INVALID_PARAMETER;
return 0L;}
DWORD WINAPISetIpForwardEntryToStack(PMIB_IPFORWARDROW pRoute){ FIXME("SetIpForwardEntryToStack() stub\n"); return 0L;}
DWORD GetInterfaceNameInternal(_In_ const GUID * pInterfaceGUID, _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName, _Inout_ PULONG pOutBufLen){ UNICODE_STRING GuidString; DWORD result, type; WCHAR szKeyName[2*MAX_PATH]; HRESULT hr; HKEY hKey;
if (pInterfaceGUID == NULL || pOutBufLen == NULL) return ERROR_INVALID_PARAMETER;
result = RtlStringFromGUID(pInterfaceGUID, &GuidString);
if (!NT_SUCCESS(result)) { // failed to convert guid to string return RtlNtStatusToDosError(result); }
hr = StringCbPrintfW(szKeyName, sizeof(szKeyName), L"SYSTEM\\CurrentControlSet\\Control\\Network\\{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", GuidString.Buffer); RtlFreeUnicodeString(&GuidString);
if (FAILED(hr)) { // key name is too long return ERROR_BUFFER_OVERFLOW; }
result = RegOpenKeyExW(HKEY_LOCAL_MACHINE, szKeyName, 0, KEY_READ, &hKey);
if (result != ERROR_SUCCESS) { // failed to find adapter entry return ERROR_NOT_FOUND; }
result = RegQueryValueExW(hKey, L"Name", NULL, &type, (PVOID)pInterfaceName, pOutBufLen);
RegCloseKey(hKey);
if (result == ERROR_MORE_DATA) { *pOutBufLen = MAX_INTERFACE_NAME_LEN * 2; return ERROR_INSUFFICIENT_BUFFER; }
if (result != ERROR_SUCCESS || type != REG_SZ) { // failed to read adapter name return ERROR_NO_DATA; } return ERROR_SUCCESS;}
DWORD WINAPINhGetInterfaceNameFromDeviceGuid(_In_ const GUID * pInterfaceGUID, _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName, _Inout_ PULONG pOutBufLen, DWORD dwUnknown4, DWORD dwUnknown5){ SetLastError(ERROR_SUCCESS);
if (pInterfaceName == NULL) return ERROR_INVALID_PARAMETER;
return GetInterfaceNameInternal(pInterfaceGUID, pInterfaceName, pOutBufLen);}
DWORD WINAPINhGetInterfaceNameFromGuid(_In_ const GUID * pInterfaceGUID, _Out_writes_bytes_to_(*pOutBufLen, *pOutBufLen) PWCHAR pInterfaceName, _Inout_ PULONG pOutBufLen, DWORD dwUnknown4, DWORD dwUnknown5){ DWORD result;
result = GetInterfaceNameInternal(pInterfaceGUID, pInterfaceName, pOutBufLen);
if (result == ERROR_NOT_FOUND) SetLastError(ERROR_PATH_NOT_FOUND);
return result;}