Default Gateway
Mike Bertosh
mbertosh at motioncontrol.org
Mon May 9 20:54:23 UTC 2005
Hi all,
I am trying to create a function that I can call to change the default gateway address. I
am using the rtrequest() function to remove the default gateway from the routing table
and then add the new address.Is there a function that will already do this for me?
Here is the code I have been trying to get to work.
struct rtentry **net_nrt;
memset (&address, '\0', sizeof address);
address.sin_len = sizeof address;
address.sin_family =AF_INET;
address.sin_addr.s_addr = INADDR_ANY;
memset (&netmask, '\0', sizeof netmask);
netmask.sin_len = sizeof netmask;netmask.sin_family =AF_INET;
netmask.sin_addr.s_addr = INADDR_ANY;
memset (&gateway, '\0', sizeof gateway);
gateway.sin_len = sizeof gateway;
gateway.sin_family = AF_INET;
gateway.sin_addr.s_addr = inet_addr(rtems_gateway);
rtems_bsdnet_semaphore_obtain ();
rtems_bsdnet_rtrequest (RTM_DELETE,
(struct sockaddr *)&address,
(struct sockaddr *)&gateway,
(struct sockaddr *)&netmask,
(RTF_UP | RTF_GATEWAY | RTF_STATIC),net_nrt);
rtfree(*net_nrt);
memset (&gateway, '\0', sizeof gateway);
gateway.sin_len = sizeof gateway;
gateway.sin_family = AF_INET;
gateway.sin_addr.s_addr = inet_addr (tempGateway);
rtems_bsdnet_rtrequest (RTM_ADD,
(struct sockaddr *)&address,
(struct sockaddr *)&gateway,
(struct sockaddr *)&netmask,
(RTF_UP | RTF_GATEWAY | RTF_STATIC), NULL);
rtems_bsdnet_semaphore_release ();
This code seems to work when I remove the rtfree() function. Is there something
wrong with rtfree() or I am doing something wrong? I'd really appreciate any help.
Thanks for your time.
Mike Bertosh
Motion Control Systems, Inc.
New River, Va
540.731.0540
More information about the users
mailing list