router.c
来自「基于routed的RIP2, 实现了multicast 和Broadcast」· C语言 代码 · 共 146 行
C
146 行
/* * * NX-ROUTED * RIP-2 Routing Daemon * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. * * Copyright (C) 2002 Valery Kholodkov * Copyright (C) 2002 Andy Pershin * Copyright (C) 2002 Antony Kholodkov * */#include <stdio.h>#include <stdlib.h>#include <string.h>#include <time.h>#include "router.h"#include "socket.h"#include "util.h"#include "timers.h"#ifdef LINUX#include "sys_linux.h"#endif#define DEBUGstruct rproto *routing_protocols;struct rtable *main_rtable;int last_rtimeout = INT_MAX;int register_routing_protocol(struct rproto *rproto) { struct rproto *p; p = routing_protocols; while(p) { if(!strcmp(p->name, rproto->name)) return -1; p = p->next; } rproto->next = routing_protocols; routing_protocols = rproto; return 0;}void unregister_routing_protocol(struct rproto *rproto) { struct rproto *p,*next; if(routing_protocols != NULL) { if(!strcmp(routing_protocols->name, rproto->name)) { routing_protocols = routing_protocols->next; return; } } p = routing_protocols; while(p) { next = p->next; if(!strcmp(next->name, rproto->name)) { p->next = next->next; return; } p = next; }}void shutdown_routing_protocols() { struct rproto *p,*next; p = routing_protocols; while(p) { next = p->next; if(p->ops->shutdown) p->ops->shutdown(p); p = next; }}//// Routing table operations//struct rtable *new_rtable() { struct rtable *rtable; if((rtable = malloc(sizeof(struct rtable))) == NULL) return NULL; rtable->num_routes = 0; rtable->routes = NULL; return rtable;}void free_rtable(struct rtable *rtable) { struct route *p,*next; if(rtable == NULL) return; p = rtable->routes; while(p) { next = p->next; free(p); p = next; } free(rtable);}struct rtable *copy_rtable(struct rtable *tbl1,struct rtable *tbl2) { struct route *p,*n; if((tbl1 == NULL) || (tbl2 == NULL)) return NULL; p = tbl2->routes; while(p) { if((n = malloc(sizeof(struct route))) == NULL) { error("Insufficient memory allocating route"); return NULL; } memcpy(n,p,sizeof(struct route)); add_route(tbl1,n); p = p->next; } return tbl1;}//// 跄撂稍
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?