📄 ip_ctl.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/router/ip_ctl.c,v 1.2 2001/11/09 21:06:50 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved. Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** * Copyright 1994-1997 Epilogue Technology Corporation. * Copyright 1998-1999 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* * $Log: ip_ctl.c,v $ * Revision 1.2 2001/11/09 21:06:50 josh * demo router path modification * * Revision 1.1.1.1 2001/11/05 17:49:09 tneale * Tornado shuffle * * Revision 2.4 2001/01/19 22:24:37 paul * Update copyright. * * Revision 2.3 2000/03/17 00:14:18 meister * Update copyright message * * Revision 2.2 1999/11/05 22:24:01 paul * Eliminate dependence on ancient backward-compatibility code. * * Revision 2.1 1998/12/02 18:07:17 josh * additions to allow dynamic adding/deleting of IP addresses * * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*//* * Commands for adding/deleting IP addresses. */#include <stdio.h>#include <stdlib.h>#include <wrn/wm/attache/config.h>#include <wrn/wm/attache/mib.h>#include <wrn/wm/attache/timer.h>#include <wrn/wm/attache/packet.h>#include <wrn/wm/attache/net.h>#include <wrn/wm/attache/glue.h>#include <wrn/wm/attache/route.h>#include <wrn/wm/attache/ip.h>#include <wrn/wm/demo/snarklib.h>enum help_level { help_none, help_short, help_long };/* add an ip address to a net interface. */boolean_t cmd_add_address(struct sty *sty, enum help_level help, int argc, char **argv){ ipaddr_t addr, brd, mask; net_if *n; int err; switch (help) { case help_short: sty_puts(sty, "add-address add an IP address\n"); break; case help_long: sty_puts(sty, "\Add an IP address to Attache using the given net_if.\n"); break; case help_none: if (argc < 4) { sty_puts(sty, "usage: add-address <ip-address> <netmask> <net> [brd]\n"); break; } string_to_ipaddr(argv[1], &addr); if (argc > 4) string_to_ipaddr(argv[4], &brd); else { IPADDR_ALL_ONES(&brd); SET_IPADDR_TYPE(&brd, GET_IPADDR_TYPE(&addr)); } if (!(n=if_lookup(argv[3]))) { sty_puts(sty, "No interface called "); sty_puts(sty, argv[3]); sty_puts(sty, ".\n"); break; } string_to_ipaddr(argv[2], &mask); err = route_add_address(&addr, ipv4_mask_to_pfxlen(&mask), &brd, n); switch (err) { case RCERR_NONE: sty_puts(sty, "IP address "); sty_puts(sty, argv[1]); sty_puts(sty, " successfully added to "); sty_puts(sty, argv[3]); sty_puts(sty, ".\n"); break; case RCERR_BADMASK: sty_puts(sty, "Invalid mask.\n"); break; case RCERR_BADBRD: sty_puts(sty, "Invalid broadcast address.\n"); break; default: sty_puts(sty, "address create error"); break; } } return 1;}boolean_t cmd_delete_address(struct sty *sty, enum help_level help, int argc, char **argv){ ipaddr_t addr; int err; switch (help) { case help_short: sty_puts(sty, "delete-address remove an IP address\n"); break; case help_long: sty_puts(sty, "\Removes an IP address from Attache.\n"); break; case help_none: if (argc < 2) { sty_puts(sty, "usage: delete-address <ip-address>\n"); break; } string_to_ipaddr(argv[1], &addr); err = route_delete_address(&addr); switch (err) { case RTE_ERR_NONE: sty_puts(sty, "IP address "); sty_puts(sty, argv[1]); sty_puts(sty, " successfully removed.\n"); break; case RTE_ERR_NOENTRY: sty_puts(sty, "IP address "); sty_puts(sty, argv[1]); sty_puts(sty, " does not exist.\n"); break; default: sty_puts(sty, "address deletion error"); break; } } return 1;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -