Главная страница
Top.Mail.Ru    Яндекс.Метрика
Текущий архив: 2007.05.27;
Скачать: CL | DM;

Вниз

Как задать gateway сетевому интерфейсу?   Найти похожие ветки 

 
kay ©   (2006-10-17 01:51) [0]

нужно реализовать смену gateway в программе


 
kay ©   (2006-10-17 02:12) [1]

нашёл:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wcecomm5/html/wce50conchangingthedefaultgateway.asp


 
kay ©   (2006-10-17 02:53) [2]

хотя нед. совсем запутался с преобразованием из c++ в дельфи. может есть готовый вариант?


 
kay ©   (2006-10-17 04:05) [3]

Получилось шлюз задать. Но не совсем так как нужно. Он то задаётся, а вот в натсройках IP сетевого адаптера всё равно висит. И причем именно в настроках.
Вот код процедуры:
procedure setgateway;
var
 pIpForwardTable:PMIB_IPFORWARDTABLE;
 pRow:PMIB_IPFORWARDROW;
 dwSize:ULONG;
 bOrder:boolean;
 dwStatus:DWORD;
 NewGateway,tmp:DWORD;
 i:integer;
begin
 bOrder:=false;
 NewGateWay:=$0100A8C8;
 pRow:=nil;
 dwSize:=0;
 if GetIpForwardTable(nil, dwSize, bOrder) = ERROR_INSUFFICIENT_BUFFER then
   begin
     // Áåðåì íóæíîå êîë-âî
     GetMem(pIpForwardTable, dwSize);
     try
       // âûïîëíåíèå ôóíêöèè
       dwStatus:=GetIpForwardTable(pIpForwardTable, dwSize, bOrder);
       if dwStatus=ERROR_SUCCESS then
         begin
           // Search for the row in the table we want. The default gateway has a destination
           // of 0.0.0.0. Notice that we continue looking through the table, but copy only
           // one row. This is so that if there happen to be multiple default gateways, we can
           // be sure to delete them all.
           for i:=0 to pIpForwardTable.dwNumEntries-1 do
             begin
               if pIpForwardTable.table[i].dwForwardDest=0 then
                 begin
               // We have found the default gateway.
               if (pRow=nil) then
                 begin
                   // Allocate some memory to store the row in. This is easier than filling
                   // in the row structure ourselves, and we can be sure to change only the
                   // gateway address.
                   GetMem(pRow, sizeof(MIB_IPFORWARDROW));
                   // Copy the row.
                   CopyMemory(pRow, @(pIpForwardTable.table[i]), sizeof(MIB_IPFORWARDROW));
                 end;

                 // Delete the old default gateway entry.
                 dwStatus:=DeleteIpForwardEntry((pIpForwardTable.table[i]));

                 if (dwStatus = ERROR_SUCCESS) then
                   break;
             end;
           end;

           // Set the nexthop field to our new gateway. All the other properties of the route will
           // be the same as they were previously.
           dwStatus:=0;

           if pRow<>nil then
             begin
               pRow.dwForwardNextHop := NewGateway;
               // Create a new route entry for the default gateway.
               dwStatus:=SetIpForwardEntry((pRow)^);
             end;

           if (dwStatus = NO_ERROR) then
             ShowMessage("Gateway changed successfully")
           else
             ShowMessage("Gateway change failed");
       end;
     finally
       FreeMem(pIpForwardTable);
       FreeMem(pRow);
     end;
   end;
end;


Заголовки:

 PMIB_IPFORWARDROW = ^MIB_IPFORWARDROW;
 MIB_IPFORWARDROW = record
   dwForwardDest:DWORD;
   dwForwardMask:DWORD;
   dwForwardPolicy:DWORD;
   dwForwardNextHop:DWORD;
   dwForwardIfIndex:DWORD;
   dwForwardType:DWORD;
   dwForwardProto:DWORD;
   dwForwardAge:DWORD;
   dwForwardNextHopAS:DWORD;
   dwForwardMetric1:DWORD;
   dwForwardMetric2:DWORD;
   dwForwardMetric3:DWORD;
   dwForwardMetric4:DWORD;
   dwForwardMetric5:DWORD;
 end;

 PMIB_IPFORWARDTABLE = ^MIB_IPFORWARDTABLE;
 MIB_IPFORWARDTABLE = record
   dwNumEntries:DWORD;
   table: array[0..ANY_SIZE - 1] of MIB_IPFORWARDROW;
 end;

......................................................................

 function GetIpForwardTable(pIpForwardTable: PMIB_IPFORWARDTABLE;
   var pdwSize: ULONG; bOrder: BOOL): DWORD; stdcall; external IPHelper;

 function DeleteIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD;
 stdcall; external IPHelper;

 function SetIpForwardEntry(const pRoute: MIB_IPFORWARDROW): DWORD;
 stdcall; external IPHelper;


 
kay ©   (2006-10-19 14:06) [4]

up


 
user51   (2006-11-21 16:11) [5]

Все легко и просто
ff:="route.exe -f -p add 0.0.0.0 mask 0.0.0.0 "+gateway+" metric 1";
winexec(pchar(ff),0);

и зачем изобретать велосипед с километровым кодом



Страницы: 1 вся ветка

Текущий архив: 2007.05.27;
Скачать: CL | DM;

Наверх




Память: 0.48 MB
Время: 0.037 c
15-1177489164
db2admin
2007-04-25 12:19
2007.05.27
Это не обьявление войны это пропоганда, зачем?


2-1178604351
RomanLN
2007-05-08 10:05
2007.05.27
Мастера посоветуйте как лучше организовать печать


2-1178433546
Doom-2
2007-05-06 10:39
2007.05.27
новое подключение Flash или ZIV


15-1177663610
CCili
2007-04-27 12:46
2007.05.27
Как проверить данные 2 аксесовских таблиц?


15-1177957189
GEd
2007-04-30 22:19
2007.05.27
Вопрос по C, прошу прощения что не там.