⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 routeop.c

📁 《网络安全开发包详解》随书光盘源码 本书以计算机网络安全开发包技术为核心,详细讨论了几个著名的网络安全开发包
💻 C
字号:
#include "dnet.h"
/*
=======================================================================================================================
Libdnet头文件 ;
下面的函数是回调函数,它在函数route_loop()中调用,它的功能是对路由表进行操作,在这里是显示路由表信息
=======================================================================================================================
 */
int show_route_rule(const struct route_entry *entry, void *arg)
{
    printf("Destination :%s  =======  Gateway :%s\n", addr_ntoa(&entry->route_dst), addr_ntoa(&entry->route_gw));
    /* 显示路由表记录 */
    return (0);
}
int main(int argc, char *argv[])
{
    struct route_entry entry;
    /* 路由表的数据结构的变量 */
    route_t *handle;
    /* 路由表操作句柄 */
    handle = route_open();
    /* 打开路由表操作 */
    printf("Show the route rules:\n");
    printf("Route rules :\n");
    printf("Destination IP  ----------------------- Gateway IP\n");
    route_loop(handle, show_route_rule, NULL);
    /*
     * 注册回调函数show_route_rule,循环调用回调函数对路由表进行操作,这里是显示所有路由表信息
     */
    printf("Show the route rules about the Destination IP:\n");
    addr_aton("192.168.0.4", &entry.route_dst);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    route_get(handle, &entry);
    /* 根据地址获取其路由表信息 */
    printf("Destination is :\n");
    printf("%s\n", addr_ntoa(&entry.route_dst));
    /* 输出目的地址 */
    printf("Gateway is: \n");
    printf("%s\n", addr_ntoa(&entry.route_gw));
    /* 输出网关地址 */
    printf("Add a route rule :\n");
    addr_aton("192.168.0.5", &entry.route_dst);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    addr_aton("192.168.0.10", &entry.route_gw);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    route_add(handle, &entry);
    /* 添加路由表记录 */
    printf("Destination :%s Gateway :%s added:\n", addr_ntoa(&entry.route_dst), addr_ntoa(&entry.route_gw));
    printf("Add a route rule :\n");
    addr_aton("192.168.0.6", &entry.route_dst);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    addr_aton("192.168.0.20", &entry.route_gw);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    route_add(handle, &entry);
    /* 添加路由表记录 */
    printf("Destination :%s Gateway :%s added:\n", addr_ntoa(&entry.route_dst), addr_ntoa(&entry.route_gw));
    printf("Show the route rules:\n");
    printf("Route rules :\n");
    printf("Destination IP  ----------------------- Gateway IP\n");
    route_loop(handle, show_route_rule, NULL);
    /* 显示所有路由表记录 */
    printf("Delete a route rule :\n");
    addr_aton("192.168.0.5", &entry.route_dst);
    /* 把字符串形式的IP地址转换为二进制形式的IP地址 */
    route_delete(handle, &entry);
    /* 删除路由表记录 */
    printf("Destination :%s deleted\n", addr_ntoa(&entry.route_dst));
    printf("Show the route rules:\n");
    printf("Route rules :\n");
    printf("Destination IP  ----------------------- Gateway IP\n");
    route_loop(handle, show_route_rule, NULL);
    /* 再显示所有路由表记录 */
    route_close(handle);
    /* 关闭路由表操作 */
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -