Пример #1
0
void termination_handler(int sig) {
	PRINT_DEBUG("**********Terminating *******");

	//shutdown all module threads in backwards order of startup
	//rtm_shutdown();

	udp_shutdown();
	tcp_shutdown();
	icmp_shutdown();
	ipv4_shutdown();
	arp_shutdown();

	interface_shutdown(); //TODO finish
	daemon_shutdown(); //TODO finish
	switch_shutdown(); //TODO finish

	//have each module free data & que/sem //TODO finish each of these
	//rtm_release();
	udp_release();
	tcp_release();
	icmp_release();
	ipv4_release();
	arp_release();

	interface_release();
	daemon_release();
	switch_release();

	PRINT_DEBUG("FIN");
	exit(-1);
}
Пример #2
0
/*------------------------------------------------------------------------
 * xsh_ping - shell command to ping a remote host
 *------------------------------------------------------------------------
 */
shellcmd xsh_ping(int nargs, char *args[])
{
	uint32	ipaddr;			/* IP address in binary		*/
	int32	retval;			/* return value			*/
	int32	icmpid;			/* ICMP ID to use		*/
	static	int32	seq = 0;	/* sequence number		*/
	char	buf[56];		/* buffer of chars		*/
	int32	i;			/* index into buffer		*/
	int32	nextval;		/* next value to use		*/

	/* For argument '--help', emit help about the 'ping' command	*/

	if (nargs == 2 && strncmp(args[1], "--help", 7) == 0) {
		printf("Use: %s  address\n\n", args[0]);
		printf("Description:\n");
		printf("\tUse ICMP Echo to ping a remote host\n");
		printf("Options:\n");
		printf("\t--help\t display this help and exit\n");
		printf("\taddress\t an IP address in dotted decimal\n");
		return 0;
	}

	/* Check for valid number of arguments */

	if (nargs != 2) {
		fprintf(stderr, "%s: invalid arguments\n", args[0]);
		fprintf(stderr, "Try '%s --help' for more information\n",
				args[0]);
		return 1;
	}

	/* convert argument to binary */

	retval = dot2ip(args[1], &ipaddr);
	if ((int32)retval == SYSERR) {
		fprintf(stderr, "%s: invalid IP address\n", args[0]);
		return 1;
	}

	/* Register to receive an ICMP Echo Reply */

	icmpid = icmp_register(ipaddr);
	if (icmpid == SYSERR) {
		fprintf(stderr, "%s: ICMP registration fails\n", args[0]);
		return 1;
	}

	/* Fill the buffer with values - start with low-order byte of	*/
	/*	the sequence number and increment			*/

	nextval = seq;
	for (i = 0; i<sizeof(buf); i++) {
		buf[i] = 0xff & nextval++;
	}

	/* Send an ICMP Echo Request */

	retval = icmp_send(ipaddr, ICMP_ECHOREQST, icmpid, seq++, buf,
				sizeof(buf));
	if (retval == SYSERR) {
		fprintf(stderr, "%s: cannot send a ping\n", args[0]);
		icmp_release(icmpid);
		return 1;
	}

	/* Read a reply */

	retval = icmp_recv(icmpid, buf, sizeof(buf), 3000);
	icmp_release(icmpid);
	if (retval == TIMEOUT) {
		fprintf(stderr, "%s: no response from %s\n\n", args[0],
					args[1]);
		return 1;
	}
	fprintf(stderr, "host %s is alive\n", args[1]);
	return 0;
}