How to programmatically edit the routing table

后端 未结 3 1451
不思量自难忘°
不思量自难忘° 2020-12-30 15:10

I am writing a daemon running on an embedded platform that needs to change the default route of the device according to which interface it is connecting on at a given time.

相关标签:
3条回答
  • 2020-12-30 15:50

    Check out SIOCADDRT/SIOCDELRT ioctls (Stevens' "Unix Network Programming" would be a good reference.)

    0 讨论(0)
  • 2020-12-30 15:54

    I would recommend just using that route command. Thats what it's there for, and anything else will just be a hack.

    0 讨论(0)
  • 2020-12-30 15:57

    I typed

    man route
    

    cause I know sometimes I can get a hint in the "see also" section for how to do the same thing programatically. I saw there was a man page on page 4 for "route" (route(4) was in the see also section). So tried

    man 4 route
    

    and it looked promising for doing what the route command can do programmitically.

    Note I just noticed this is only for BSD systems. Here is a URL with the manpage http://www.manpagez.com/man/4/route/. This may or may not be helpful. Maybe you can google some of the stuff in here and add the word "linux".

    0 讨论(0)
提交回复
热议问题