5 kx /*
5 kx * icmpinfo
5 kx * It is a tool to look at the icmp you receive
5 kx * Its source comes from a modified BSD ping source by Laurent Demailly
5 kx *
5 kx * it comes AS IS - no warranty, etc...
5 kx * <dl@hplyot.obspm.fr>
5 kx *
5 kx * see the README for usage infos...etc...
5 kx *
5 kx */
5 kx /*
5 kx * Copyright (c) 1987 Regents of the University of California.
5 kx * All rights reserved.
5 kx *
5 kx * Redistribution and use in source and binary forms are permitted
5 kx * provided that the above copyright notice and this paragraph are
5 kx * duplicated in all such forms and that any documentation,
5 kx * advertising materials, and other materials related to such
5 kx * distribution and use acknowledge that the software was developed
5 kx * by the University of California, Berkeley. The name of the
5 kx * University may not be used to endorse or promote products derived
5 kx * from this software without specific prior written permission.
5 kx * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
5 kx * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
5 kx * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
5 kx */
5 kx
5 kx #ifndef lint
5 kx char copyright[] =
5 kx "@(#) Copyright (c) 1987 Regents of the University of California.\n\
5 kx All rights reserved.\n augmented 4/94 by dl\n";
5 kx #endif /* not lint */
5 kx
5 kx #ifndef lint
5 kx static char sccsid[] = "@(#)ping.c 4.10 (Berkeley) 10/10/88 - $Author: icmpinfo-1.11- Laurent Demailly <dl@hplyot.obspm.fr>$";
5 kx #endif /* not lint */
5 kx
5 kx #define DCLARE /* def : */
5 kx
5 kx #include <stdlib.h>
5 kx #include "defs.h"
5 kx
5 kx /*
5 kx * P I N G . C
5 kx *
5 kx * Using the InterNet Control Message Protocol (ICMP) "ECHO" facility,
5 kx * measure round-trip-delays and packet loss across network paths.
5 kx *
5 kx * Author -
5 kx * Mike Muuss
5 kx * U. S. Army Ballistic Research Laboratory
5 kx * December, 1983
5 kx * Modified at Uc Berkeley
5 kx *
5 kx * Status -
5 kx * Public Domain. Distribution Unlimited.
5 kx *
5 kx * Bugs -
5 kx * More statistics could always be gathered.
5 kx * This program has to run SUID to ROOT to access the ICMP socket.
5 kx */
5 kx
5 kx char usage[] = "Usage: icmpinfo [-v[v[v]]] [-s] [-n] [-p] [-l] [-k]\n -v : more and more info\n -s : show local interface address\n -n : no name query (dot ip only)\n -p : no port -> service name query\n -l : fork + syslog output\n -k : kill background process\nv1.11 - 8/1995 - dl";
5 kx char *pname;
5 kx
5 kx int main(argc, argv)
5 kx int argc;
5 kx char **argv;
5 kx {
5 kx int sockoptions, on;
5 kx struct protoent *proto;
5 kx
5 kx on = 1;
5 kx pname = argv[0];
5 kx argc--;
5 kx argv++;
5 kx
5 kx sockoptions=nonamequery=noportquery=syslogdoutput=showsrcip=0;
5 kx while (argc > 0 && *argv[0] == '-') {
5 kx while (*++argv[0]) switch (*argv[0]) {
5 kx case 'd':
5 kx sockoptions |= SO_DEBUG;
5 kx break;
5 kx case 'r':
5 kx sockoptions |= SO_DONTROUTE;
5 kx break;
5 kx case 'v':
5 kx verbose++;
5 kx break;
5 kx case 'n':
5 kx nonamequery++;
5 kx break;
5 kx case 'p':
5 kx noportquery++;
5 kx break;
5 kx case 'l':
5 kx syslogdoutput++;
5 kx break;
5 kx case 's':
5 kx showsrcip++;
5 kx break;
5 kx case 'k':
5 kx pid_kill();
5 kx exit(0);
5 kx break;
5 kx case 'h':
5 kx default :
5 kx err_quit(usage);
5 kx }
5 kx argc--, argv++;
5 kx }
5 kx if (argc!=0) err_quit(usage);
5 kx if ( (proto = getprotobyname("icmp")) == NULL)
5 kx err_quit("unknown protocol: icmp");
5 kx if ( (sockfd = socket(AF_INET, SOCK_RAW, proto->p_proto)) < 0)
5 kx err_sys("can't create raw socket (root and/or bit s needed)");
5 kx if (sockoptions & SO_DEBUG)
5 kx if (setsockopt(sockfd, SOL_SOCKET, SO_DEBUG, &on,
5 kx sizeof(on)) < 0)
5 kx err_sys("setsockopt SO_DEBUG error");
5 kx if (sockoptions & SO_DONTROUTE)
5 kx if (setsockopt(sockfd, SOL_SOCKET, SO_DONTROUTE, &on,
5 kx sizeof(on)) < 0)
5 kx err_sys("setsockopt SO_DONTROUTE error");
5 kx
5 kx if (syslogdoutput) {
5 kx if (getuid()!=0)
5 kx err_quit("You need root id to use the syslog/daemon -l option");
5 kx if (fork()) {exit(0);}
5 kx /* Can't check openlog & syslog retcodes 'cause lot of
5 kx unixes have void openlog(); and void syslog(); !! */
5 kx openlog("icmpinfo",0,LOG_DAEMON);
5 kx syslog(LOG_NOTICE,"started, PID=%d.",getpid());
5 kx setsid();
5 kx pid_file();
5 kx close(0);
5 kx close(1);
5 kx close(2);
5 kx } else {
5 kx printf("icmpinfo: Icmp monitoring in progress...\n");
5 kx }
5 kx recv_ping(); /* and start the receive */
5 kx /* NOTREACHED */
5 kx return(0);
5 kx }