/* Safety wrapper for "traceroute" */ /* See the copyright notice at the end of this file. */ /* Last edited on 2024-12-25 10:17:06 by stolfi */ #include #include #include #include #include #define MYNAME mailroute #define MAXLEN 255 #define TRACEROUTE /n/net/bin/traceroute typedef unsigned char byte; void error(char *msg, char *arg); int main(int argc, char **argv); int main (int argc, char **argv) { static char *usage = "usage: %s: hostname"; char *h; byte *p; byte valid[256]; /* Set up valid charset */ { int i; byte *p; for(i=0;i<256;i++){ valid[i] = 0; } for(p=((byte *)"-+_.");*p;p++){ valid[*p] = 1; } for(i='0';i<='9';i++){ valid[i] = 1; } for(i='A';i<='Z';i++){ valid[i+32] = valid[i] = 1; } } /* Check argument */ if (argc != 2) { error(usage, argv[0]); } h = argv[1]; if (strlen(h) > MAXLEN) { error("%s: argument too long", argv[0]); } for(p=(byte *)h;*p;p++) { if(!valid[*p]) { error("%s: bad char in hostname", argv[0]); } } /* Call traceroute: */ execl("TRACEROUTE", "TRACEROUTE", h, NULL); /* If we get here, the exec failed: */ perror("MYNAME"); exit(1); } void error(char *msg, char *arg) { fprintf(stderr, msg, arg); exit(1); } /****************************************************************************/ /* (C) Copyright 1992 Universidade Estadual de Campinas (UNICAMP) */ /* Campinas, SP, Brazil */ /* */ /* Authors: */ /* */ /* Jorge Stolfi - Inst. Computing, UNICAMP */ /* */ /* This file can be freely distributed, modified, and used for any */ /* non-commercial purpose, provided that this copyright and authorship */ /* notice are included in any copy or derived version of this file. */ /* */ /* DISCLAIMER: This software is offered ``as is'', without any guarantee */ /* as to fitness for any particular purpose. Neither the copyright */ /* holder nor the authors or their employers can be held responsible for */ /* any damages that may result from its use. */ /****************************************************************************/