Home All Groups Group Topic Archive Search About

Route addition in vista

Author
8 Aug 2006 9:16 AM
Jothi
Hi All,
I am using Windows Vista for my network application development under
administrator login(full access). I am trying to add a route to the
exisisting route table using CreateIpForwardEntry API.
I am getting following error.
"160 - One or more argument are not correct." .
But From command prompt I was able to add/delete the route uusing route

commands.

Anybody have idea on solving this issue.


the source is here


BOOL Add_Route_x( DWORD destination,
                  DWORD gateway,
                  DWORD mask,
                  DWORD metric,
                  int row_number,
                  DWORD index,
                  DWORD fwdType)
{
        BOOL bRet = FALSE;
        MIB_IPFORWARDROW        pfwrow;
        DWORD                   dwStatus;


        pfwrow.dwForwardNextHop = gateway;
        pfwrow.dwForwardDest    = destination;
        pfwrow.dwForwardMask    = mask;
        pfwrow.dwForwardMetric1 = metric;


        pfwrow.dwForwardPolicy  = 0;
        pfwrow.dwForwardType    = fwdType;
        pfwrow.dwForwardProto   = 3;//PROTO_IP_NETMGMT;
        pfwrow.dwForwardAge     = -1 ;
        pfwrow.dwForwardNextHopAS  =0;


        pfwrow.dwForwardMetric2 = 0xffffffff;
        pfwrow.dwForwardMetric3 = 0xffffffff;
        pfwrow.dwForwardMetric4 = 0xffffffff;
        pfwrow.dwForwardMetric5 = 0xffffffff;
        pfwrow.dwForwardIfIndex = index;


        LOG("Adding route for following parameters");
        LOG("Gateway     = %s",print_in_addr_t(ntohl(gateway)));
        LOG("Destination = %s",print_in_addr_t(ntohl(destination)));
        LOG("Mask        = %s",print_in_addr_t(ntohl(mask)));
        LOG("Forward Type = %d", fwdType);
        LOG("Index       = %x",index);
        LOG("Metric      = %d",metric);


        // Create a new route entry for the default gateway.
        dwStatus = CreateIpForwardEntry(&pfwrow);
        if (dwStatus == NO_ERROR)
        {
                LOG("Add route successfull");
                bRet = TRUE;
        }
        else
        {
             LOG("Add route failed. CreateIpForwardEntry returning
Error
code = %d", dwStatus);
        if(ERROR_INVALID_PARAMETER == dwStatus)
        {
            LOG("One of the members of the MIB_IPFORWARDROW structure
is invalid.");
        }
        else if(ERROR_NOT_SUPPORTED == dwStatus)
        {
            LOG("The IP transport is not configured on the local
computer");
        }
        bRet = FALSE;
    }


   return bRet;



} // End of AddRoute()


log file contains following info
============================================================
Routing Table in System...
ForwardDest     ForwardMask     ForwardNextHop  ForwardMetric   IfIndex

0.0.0.0                 0.0.0.0                 172.16.2.1
276                   0000000b
127.0.0.0                       255.0.0.0                       0.0.0.0

306     00000001
127.0.0.1                       255.255.255.255 0.0.0.0           306
        00000001
127.255.255.255 255.255.255.255 0.0.0.0           306   00000001
172.16.0.0                      255.255.0.0     0.0.0.0           276
0000000b
172.16.91.15    255.255.255.255 0.0.0.0           276   0000000b
172.16.255.255  255.255.255.255 0.0.0.0           276   0000000b
224.0.0.0                       240.0.0.0                       0.0.0.0

306     00000001
224.0.0.0                       240.0.0.0                       0.0.0.0

276     0000000b
224.0.0.0                       240.0.0.0                       0.0.0.0

266     0000000f
239.255.255.255 255.255.255.255 0.0.0.0           306   00000001
239.255.255.255 255.255.255.255 0.0.0.0           276   0000000b
239.255.255.255 255.255.255.255 0.0.0.0           266   0000000f
255.255.255.255 255.255.255.255 0.0.0.0           306   00000001
255.255.255.255 255.255.255.255 0.0.0.0                   276
0000000b
255.255.255.255 255.255.255.255 0.0.0.0           266   0000000f
Adding route for following parameters
Gateway     = 172.16.91.15
Destination = 172.16.100.68
Mask        = 255.255.255.255
Forward Type = 3
Index       = b
Metric      = 1
Add route failed. CreateIpForwardEntry returning Error code = 160

============================================================


If anybody know how to solve this issue, please let me know. Parallely
I will change parameter details and try.


I am not getting meaning of
"On Windows Vista and Windows Server "Longhorn", the
CreateIpForwardEntry only works on interfaces with a single
sub-interface (where the interface LUID and subinterface LUID are the
same). The dwForwardIfIndex member of the MIB_IPFORWARDROW structure
specifies the interface.


"
in the following link.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphl...



Please explain if anybody understood.


-- Jothi

Author
8 Aug 2006 3:31 PM
Jim
Show quote Hide quote
"Jothi" <srmjo***@gmail.com> wrote in message
news:1155028568.513826.52930@i3g2000cwc.googlegroups.com...
> Hi All,
> I am using Windows Vista for my network application development under
> administrator login(full access). I am trying to add a route to the
> exisisting route table using CreateIpForwardEntry API.
> I am getting following error.
> "160 - One or more argument are not correct." .
> But From command prompt I was able to add/delete the route uusing route
>
> commands.
>
> Anybody have idea on solving this issue.
>
>
> the source is here
>
>
> BOOL Add_Route_x( DWORD destination,
>                  DWORD gateway,
>                  DWORD mask,
>                  DWORD metric,
>                  int row_number,
>                  DWORD index,
>                  DWORD fwdType)
> {
>        BOOL bRet = FALSE;
>        MIB_IPFORWARDROW        pfwrow;
>        DWORD                   dwStatus;
>
>
>        pfwrow.dwForwardNextHop = gateway;
>        pfwrow.dwForwardDest    = destination;
>        pfwrow.dwForwardMask    = mask;
>        pfwrow.dwForwardMetric1 = metric;
>
>
>        pfwrow.dwForwardPolicy  = 0;
>        pfwrow.dwForwardType    = fwdType;
>        pfwrow.dwForwardProto   = 3;//PROTO_IP_NETMGMT;
>        pfwrow.dwForwardAge     = -1 ;
>        pfwrow.dwForwardNextHopAS  =0;
>
>
>        pfwrow.dwForwardMetric2 = 0xffffffff;
>        pfwrow.dwForwardMetric3 = 0xffffffff;
>        pfwrow.dwForwardMetric4 = 0xffffffff;
>        pfwrow.dwForwardMetric5 = 0xffffffff;
>        pfwrow.dwForwardIfIndex = index;
>
>
>        LOG("Adding route for following parameters");
>        LOG("Gateway     = %s",print_in_addr_t(ntohl(gateway)));
>        LOG("Destination = %s",print_in_addr_t(ntohl(destination)));
>        LOG("Mask        = %s",print_in_addr_t(ntohl(mask)));
>        LOG("Forward Type = %d", fwdType);
>        LOG("Index       = %x",index);
>        LOG("Metric      = %d",metric);
>
>
>        // Create a new route entry for the default gateway.
>        dwStatus = CreateIpForwardEntry(&pfwrow);
>        if (dwStatus == NO_ERROR)
>        {
>                LOG("Add route successfull");
>                bRet = TRUE;
>        }
>        else
>        {
>             LOG("Add route failed. CreateIpForwardEntry returning
> Error
> code = %d", dwStatus);
>        if(ERROR_INVALID_PARAMETER == dwStatus)
>        {
>            LOG("One of the members of the MIB_IPFORWARDROW structure
> is invalid.");
>        }
>        else if(ERROR_NOT_SUPPORTED == dwStatus)
>        {
>            LOG("The IP transport is not configured on the local
> computer");
>        }
>        bRet = FALSE;
>    }
>
>
>   return bRet;
>
>
>
> } // End of AddRoute()
>
>
> log file contains following info
> ============================================================
> Routing Table in System...
> ForwardDest     ForwardMask     ForwardNextHop  ForwardMetric   IfIndex
>
> 0.0.0.0                 0.0.0.0                 172.16.2.1
> 276                   0000000b
> 127.0.0.0                       255.0.0.0                       0.0.0.0
>
> 306     00000001
> 127.0.0.1                       255.255.255.255 0.0.0.0           306
>        00000001
> 127.255.255.255 255.255.255.255 0.0.0.0           306   00000001
> 172.16.0.0                      255.255.0.0     0.0.0.0           276
> 0000000b
> 172.16.91.15    255.255.255.255 0.0.0.0           276   0000000b
> 172.16.255.255  255.255.255.255 0.0.0.0           276   0000000b
> 224.0.0.0                       240.0.0.0                       0.0.0.0
>
> 306     00000001
> 224.0.0.0                       240.0.0.0                       0.0.0.0
>
> 276     0000000b
> 224.0.0.0                       240.0.0.0                       0.0.0.0
>
> 266     0000000f
> 239.255.255.255 255.255.255.255 0.0.0.0           306   00000001
> 239.255.255.255 255.255.255.255 0.0.0.0           276   0000000b
> 239.255.255.255 255.255.255.255 0.0.0.0           266   0000000f
> 255.255.255.255 255.255.255.255 0.0.0.0           306   00000001
> 255.255.255.255 255.255.255.255 0.0.0.0                   276
> 0000000b
> 255.255.255.255 255.255.255.255 0.0.0.0           266   0000000f
> Adding route for following parameters
> Gateway     = 172.16.91.15
> Destination = 172.16.100.68
> Mask        = 255.255.255.255
> Forward Type = 3
> Index       = b
> Metric      = 1
> Add route failed. CreateIpForwardEntry returning Error code = 160
>
> ============================================================
>
>
> If anybody know how to solve this issue, please let me know. Parallely
> I will change parameter details and try.
>
>
> I am not getting meaning of
> "On Windows Vista and Windows Server "Longhorn", the
> CreateIpForwardEntry only works on interfaces with a single
> sub-interface (where the interface LUID and subinterface LUID are the
> same). The dwForwardIfIndex member of the MIB_IPFORWARDROW structure
> specifies the interface.
>
>
> "
> in the following link.
> http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iphl...
>
>
>
> Please explain if anybody understood.
>
>
> -- Jothi
>
No, I don't.  However, it would never occur to me to post Vista questions to
an XP newsgroup.
Jim
Author
21 Aug 2006 8:45 AM
dr.lior
The routing metric in Vista is the sum of the interface metric and the
routing metric. You can query them individually with netsh\itf\ip.
A workaround can be to set the metric to 21.

HTH,
Lior