home *** CD-ROM | disk | FTP | other *** search
- /* IP-related user commands */
- #include <stdio.h>
- #include <string.h>
- #include <stdlib.h>
- #include "dbox.h"
- #include "werr.h"
- #include "global.h"
- #include "mbuf.h"
- #include "internet.h"
- #include "timer.h"
- #include "netuser.h"
- #include "iface.h"
- #include "ip.h"
- #include "cmdparse.h"
- #include "icmp.h"
- #include "misc.h"
-
- #define IP_TTL 1
- #define IP_OK 0
-
- extern char badhost[];
- struct cmds ipcmds[] = {
- "address", doipaddr, 0, NULLCHAR, NULLCHAR,
- "ttl", dottl, 0, NULLCHAR, NULLCHAR,
- NULLCHAR, NULLFP, 0,
- "ip subcommands: address ttl", NULLCHAR,
- };
- int doip(int argc, char **argv)
- {
- return subcmd(ipcmds,argc,argv);
- }
- int doipaddr(int argc, char **argv)
- {
- int32 n;
-
- if(argc > 1) {
- if ((n = resolve(argv[1])) == 0) {
- werr(1,badhost,argv[1]);
- return 1;
- }
-
- ip_addr = n;
- }
-
- return 0;
- }
- int dottl(int argc, char **argv)
- {
- if (argc > 1) ip_ttl = atoi(argv[1]);
- return 0;
- }
- void ip_parms(void)
- {
- dbox d;
-
- if ((d = dbox_new("IP_Parms")) == NULL)
- return;
-
- dbox_setnumeric(d, IP_TTL, ip_ttl);
-
- dbox_show(d);
-
- if (dbox_fillin(d) == IP_OK)
- ip_ttl = dbox_getnumeric(d, IP_TTL);
-
- dbox_dispose(&d);
- }
- /* "route" subcommands */
- static struct cmds rtcmds[] = {
- "add", doadd, 3,
- "route add <dest addr>[/<bits>] <if name> [gateway] [metric]",
- "Add failed",
-
- "drop", dodrop, 2,
- "route drop <dest addr>[/<bits>]",
- "Not in table",
-
- NULLCHAR, NULLFP, 0,
- "route subcommands: add, drop",
- NULLCHAR,
- };
-
- /* Display and/or manipulate routing table */
- int doroute(int argc, char **argv)
- {
- return subcmd(rtcmds,argc,argv);
- }
- /* Add an entry to the routing table
- * E.g., "add 1.2.3.4 ax0 5.6.7.8 3"
- */
- int doadd(int argc, char **argv)
- {
- struct interface *ifp;
- int32 dest,gateway;
- unsigned bits;
- char *bitp;
- int metric;
-
- if(strcmp(argv[1],"default") == 0){
- dest = 0;
- bits = 0;
- } else {
- if((dest = resolve(argv[1])) == 0){
- werr(0,badhost,argv[1]);
- return 1;
- }
-
- /* If IP address is followed by an optional slash and
- * a length field, (e.g., 128.96/16) get it;
- * otherwise assume a full 32-bit address
- */
- if((bitp = strchr(argv[1],'/')) != NULLCHAR){
- bitp++;
- bits = atoi(bitp);
- } else
- bits = 32;
- }
- for(ifp=ifaces;ifp != NULLIF;ifp = ifp->next){
- if(strcmp(argv[2],ifp->name) == 0)
- break;
- }
- if(ifp == NULLIF){
- werr(0,"Interface \"%s\" unknown\n",argv[2]);
- return 1;
- }
- if(argc > 3){
- if((gateway = resolve(argv[3])) == 0){
- werr(0,badhost,argv[3]);
- return 1;
- }
- } else {
- gateway = 0;
- }
- if(argc > 4)
- metric = atoi(argv[4]);
- else
- metric = 0;
-
- rt_add(dest,bits,gateway,metric,ifp);
- return 0;
- }
- /* Drop an entry from the routing table
- * E.g., "drop 128.96/16
- */
- int dodrop(int argc, char **argv)
- {
- char *bitp;
- unsigned bits;
- int32 n;
-
- argc = argc;
-
- if(strcmp(argv[1],"default") == 0){
- n = 0;
- bits = 0;
- } else {
- /* If IP address is followed by an optional slash and length field,
- * (e.g., 128.96/16) get it; otherwise assume a full 32-bit address
- */
- if((bitp = strchr(argv[1],'/')) != NULLCHAR){
- bitp++;
- bits = atoi(bitp);
- } else
- bits = 32;
-
- if((n = resolve(argv[1])) == 0){
- werr(0,badhost,argv[1]);
- return 1;
- }
- }
- return rt_drop(n,bits);
- }
-
-