I am very new to static routing, our client requested to implement static routing for sockets. When I googled I came across with rtentry
to set routing information. When I opened this structure I saw the fields for static routing
struct sockaddr rt_dst; /* Target address. */
struct sockaddr rt_gateway; /* Gateway addr (RTF_GATEWAY). */
struct sockaddr rt_genmask; /* Target network mask (IP). */
But how can I setup multiple entry here?
creating multiple rtentry
and calling ioctl(FileDes, SIOCADDRT, &rtentry)
will fix my problem?
int32_t FileDes = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
for(auto RtEntry : RtEntriesList)
{
ioctl(FileDes, SIOCADDRT, RtEntry)`
}
If I configure, how can I test this? It will be helpful if you can provide a link to know more about these things.
The route command allows you to make manual entries into the network routing tables. The route command distinguishes between routes to hosts and routes to networks by interpreting the network address of the Destination variable, which can be specified either by symbolic name or numeric address.
Adding Static Routes in AIXStep 1: Go to the SMITTY menu for routes. Step 2: Select Type of route 'net' or 'host' (if default route then leave set to 'net'). Step 3: Enter the destination address. Step 6: Enter the network interface for this route.
In computing, route is a command used to view and manipulate the IP routing table in Unix-like and Microsoft Windows operating systems and also in IBM OS/2 and ReactOS. Manual manipulation of the routing table is characteristic of static routing.
Finally I got my answers.
int32_t FileDes = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP);
struct rtentry Route1;
struct rtentry Route2;
struct rtentry Route3;
// configure Route1
// configure Route2
// configure Route3
RtEntriesList.push_back(&Route1);
RtEntriesList.push_back(&Route2);
RtEntriesList.push_back(&Route3);
for(auto RtEntry : RtEntriesList)
{
ioctl(FileDes, SIOCADDRT, RtEntry);
}
will work, we can create multple routing entries and add to the socket FD. and this will update the system wide routing table.
its similar to route add ..
command
for testing i set the gateway as my PC ip address and started wireshark there. after setting routing configurations the given range of IP is routed to my PC. Thanks @osgx for the information that its actually setting the system wide routing table.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With