RtmAddRouteToDest Help

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance

From: Suja (sujamoljames_at_yahoo.com)
Date: 12/14/04


Date: 14 Dec 2004 07:11:03 -0800

Hi All,

As there is no success with IP helper functions when RRAS is running, I
moved to Routing Table Manager Version 2 Functions. But the sample code
I wrote based on MSDN help is running with out an any error. Only thing
is the routes are note updated. When I check the route using route.exe,
no addition is happend. I pasting my code below. Please have a look.

Thanks,
Suja
void AddRouteEntry()
{
RTM_ENTITY_INFO EntityInfo;
DWORD Status,VendorId=10;
RTM_ENTITY_EXPORT_METHODS ExportMethods;
RTM_REGN_PROFILE RegnProfile;
RTM_ENTITY_HANDLE RtmRegHandle;

EntityInfo.RtmInstanceId = 0; // Must be set to default for now
EntityInfo.AddressFamily = AF_INET;
EntityInfo.EntityId.EntityProtocolId = PROTO_IP_RIP;
EntityInfo.EntityId.EntityInstanceId = MS_IP_RIP;

RegnProfile.MaxNextHopsInRoute = 1;
RegnProfile.MaxHandlesInEnum =1;
RegnProfile.ViewsSupported = 1;
RegnProfile.NumberOfViews = 1;

ExportMethods.NumMethods = 0;

Status = RtmRegisterEntity(&EntityInfo,
&ExportMethods,
NULL,
TRUE,
&RegnProfile,
&RtmRegHandle);

if (Status != NO_ERROR)
{
MessageBox(NULL, "Registration failed - Log an Error and
Quit","Test",0);
return ;
}

// Add a route to a destination given by (addr, masklen)
// using a next hop reachable with an interface
RTM_NEXTHOP_INFO NextHopInfo;
unsigned int nexthop = ntohl (inet_addr ("172.16.2.1"));

// First, create and add a next hop to the caller's
// next-hop tree (if it does not already exist)

ZeroMemory(&NextHopInfo, sizeof(RTM_NEXTHOP_INFO));

RTM_IPV4_MAKE_NET_ADDRESS(&NextHopInfo.NextHopAddress,
nexthop, // Address of the next hop
32);

NextHopInfo.InterfaceIndex = 1;//0x2000003; //0x8000004;

RTM_NEXTHOP_HANDLE NextHopHandle = NULL;
RTM_NEXTHOP_CHANGE_FLAGS ChangeFlags;

Status = RtmAddNextHop(RtmRegHandle,
&NextHopInfo,
&NextHopHandle,
&ChangeFlags);

unsigned int addr =ntohl (inet_addr ("172.16.2.33"));

if (Status == NO_ERROR)
{
// Created a new next hop or found an old one

// Fill in the route information for the route
RTM_ROUTE_INFO RouteInfo;
ZeroMemory(&RouteInfo, sizeof(RTM_ROUTE_INFO));
RTM_NET_ADDRESS NetAddress;
unsigned int masklen = 32;
unsigned int metric = 10;
// Fill in the destination network's address and mask values

RTM_IPV4_MAKE_NET_ADDRESS(&NetAddress, addr, masklen);
// Assume 'neighbour learnt from' is the first next hop
RouteInfo.Neighbour = NextHopHandle;
// Set metric for route; Preference set internally
RouteInfo.PrefInfo.Metric = metric;
// Adding a route to both the unicast and multicast views
RouteInfo.BelongsToViews = RTM_VIEW_MASK_UCAST;
RouteInfo.NextHopsList.NumNextHops = 1;
RouteInfo.NextHopsList.NextHops[0] = NextHopHandle;
// If you want to add a new route, regardless of
// whether a similar route already exists, use the following
// ChangeFlags = RTM_ROUTE_CHANGE_NEW;
ChangeFlags = RTM_ROUTE_CHANGE_NEW;
RTM_ROUTE_HANDLE RouteHandle = NULL;
RTM_ROUTE_LIST_HANDLE RouteListHandle1 = NULL;
Status = RtmAddRouteToDest(RtmRegHandle,
&RouteHandle, // Can be NULL if you do not need handle
&NetAddress,
&RouteInfo,
INFINITE ,
RouteListHandle1, // Also add the route to this list
0,
NULL,
&ChangeFlags);

if (Status == NO_ERROR)
{
if (ChangeFlags & RTM_ROUTE_CHANGE_NEW)
{
// A new route has been created
MessageBox(NULL, "RTM ROUTE CHANGE NEW","Test",0);
}
else
{
// An existing route is updated
MessageBox(NULL, "Existing route is updated","Test",0);
}
}
if (ChangeFlags & RTM_ROUTE_CHANGE_BEST)
{
// Best route information has changed
MessageBox(NULL, "Best route information has changed","Test",0);
}
// Release the route handle if you do not need it
//RtmReleaseRoutes(RtmRegHandle, 1, &RouteHandle);
}
// Also release the next hop since it is no longer needed
// RtmReleaseNextHops(RtmRegHandle, 1, &NextHopHandle);
 
}



Relevant Pages

  • Re: I have 6 PCs with Linux installed and Cable modem with LAN connection, How can I hookup all thes
    ... >> layer, with bugs. ... >> particularly good as firewalls. ... >They do route, in that they direct traffic to an external network. ... The 1 hop is on a lightly loaded T3, the 3 hop is on a fairly ...
    (comp.os.linux.networking)
  • Re: 2 interfaces, 2 gateways, no internet
    ... There is only one operative default route at anytime, ... route whose next hop is unreachable. ... Ie, that network gateway is down, but the system keeps trying. ... disconnected and then disconnecting that default route. ...
    (comp.os.linux.networking)
  • Re: Puppies!
    ... of the route to the kitchen but for better or worse the ... other dogs don't respect him much and so hop right over him. ... Poor guy. ...
    (rec.pets.dogs.behavior)
  • Re: ip route 0 & metric?
    ... you have specified a next hop IP address and not an interface. ... route 0.0.0.0 fe0/2 200> or something like that, ... advertise them via a routing protocol. ...
    (comp.dcom.sys.cisco)