⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rsvpeep.c

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  @(#) $Id: rsvpeep.c,v 1.1.1.1 2000/05/08 22:51:24 wenqing Exp $ *//******************************************************************** * *            rsvpeep - Display RSVP status packets *                                                                           *              Written by: Bob Braden (braden@isi.edu) *              USC Information Sciences Institute *              Marina del Rey, California *		November 1993                                    *                                                                           *  Copyright (c) 1993 by the University of Southern California *  All rights reserved. * *  Permission to use, copy, modify, and distribute this software and its *  documentation in source and binary forms for non-commercial purposes *  and without fee is hereby granted, provided that the above copyright *  notice appear in all copies and that both the copyright notice and *  this permission notice appear in supporting documentation. and that *  any documentation, advertising materials, and other materials related *  to such distribution and use acknowledge that the software was *  developed by the University of Southern California, Information *  Sciences Institute.  The name of the University may not be used to *  endorse or promote products derived from this software without *  specific prior written permission. * *  THE UNIVERSITY OF SOUTHERN CALIFORNIA makes no representations about *  the suitability of this software for any purpose.  THIS SOFTWARE IS *  PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, *  INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF *  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. * *  Other copyrights might apply to parts of this software and are so *  noted when applicable. * ********************************************************************//* Older versions of rsvpd send junk in FF reports which may crash * this program. Drive defensively... */#define BAD_FF_REPORTS /*                            rsvpeep.c * *      Display routine for status packets from RSVP daemon.  This is a *	simple ASCII-based display program, an alternative to the *	 window-based dmap program. * *      rsvpeep listens for status summary messages to a specific *      multicast/unicast address and port, and displays either all *	status packets it receives, or else a specific subset. */#include "rsvp_daemon.h"#include "rapi_lib.h"#include "rsvp_mstat.h"char *version = "R3.3  May 96";/* *  Global control variables * */int Xdebug= 0;u_long src_host = 0;int Time_Stamp = 0;#define MAX_NAMES 20char *Names[MAX_NAMES];int Num_names = 0;char lastName[128] = "";SESSION_ipv4 last_session;	/* initialized to zero below */#define ADDR_NEQ(a, b) ((* (u_long *)&(a)->sess_destaddr != \				*(u_long *)&(b)->sess_destaddr)|| \			((a)->sess_destport != (b)->sess_destport))#define filtsptoa(x)	(Obj_Class(x) != class_NULL)? fmt_filtspec(x):"*/*[*]"#define fspectoa(x)	fmt_flowspec((Obj_Class(x) != class_NULL)? (x):NULL)#define ftspectoa(x)	(Obj_Class(x) != class_NULL)? fmt_tspec(x): "TS[]"char Stat_addr[64];char *Heading = "\ Style  Iface     Next/Prev Hop    Filterspec          Flowspec\n";int udpsock = -1;static int IP_NumOnly;#define NIFACES 8#define NSTATS 32/* Forward and external declarations */u_long resolve_name();extern char *fmt_filtspec(), *fmt_flowspec(), *fmt_tspec();extern void ntoh_flowspec(FLOWSPEC *), ntoh_tspec(SENDER_TSPEC *);#define ip_convert(addr)  (IP_NumOnly ? net_inaddr_print((char *) &(addr),AF_INET) : net_inaddr_host((char *) &(addr),AF_INET))void	recvstatus(void);void	print_Path(PathInfo_t *, int);void	print_Resv(ResvInfo_t *, int);void	print_session(SESSION_ipv4 *, POLICY_DATA *);int	wrong_name(char *);char   *argscan(int *, char ***);void	hexf(FILE *,  char *, int);int	ntoh_info(RSVPInfo_t *);int	ntoh_session_ipv4(SESSION_ipv4 *);int	ntoh_policydata(POLICY_DATA *);int	ntoh_filterspec(FILTER_SPEC *);char *Type_name[] = {"", "PATH  ", "RESV  ", "PATH-ERR", "RESV-ERR",			 "PATH-TEAR", "RESV-TEAR"};voidUsage() {    fprintf(stderr,   "Usage: rsvpeep [-x] [-n] [ -d <mcast addr>:<port> ] [ node-name ] ...\n");}intmain(argc, argv)    int argc ;    char **argv ;    {    char  *argscan(), *rmsuffix(), *tp;    u_int32_t host;    u_int16_t port;    struct timeval timenow;    struct ip_mreq mreq;    int one = 1;    struct sockaddr_in sin;        bzero(&last_session, sizeof(SESSION_ipv4));    strcpy(Stat_addr, STAT_DEST_ADDR);    IP_NumOnly = 0;    if (--argc > 0 && **++argv == '?') {        Usage() ;        exit(0) ;    }    while (argc > 0 && **argv == '-') {	switch (argv[0][1]) {        	case 'x':   /* -x -- Debug flag  */		Xdebug = 1 ;		break ;       	case 'd':   /* -d -- Destination for status packets <mcast addr>:<port>  */		strcpy(Stat_addr, argscan(&argc, &argv));		break ;	case 'n':   /* -n -- Suppress conversion of host addrs to names */		IP_NumOnly = 1;		break;     	case 't':  /* -t: timestamp arriving packets */		Time_Stamp = 1;		break;	default:    		Usage() ;		exit(1) ;	};	argv++;	argc--;    }    if (argc > MAX_NAMES) {	printf("Too many names\n");	exit(1);    }    while (argc > 0) {	Names[Num_names++] = *argv++;	argc--;    }	/* 	 *  Convert data collection identifier/mcast group: <host>.<port>	 */    if ((tp = rmsuffix(Stat_addr))) {        port = htons((u_int16_t)atoi(tp));        host = resolve_name(Stat_addr);    }    else {	port = htons((u_int16_t)atoi(*argv));	host = INADDR_ANY;    }    /*     *  Setup socket to wait for data packets     */    bzero((char *) &sin, sizeof(struct sockaddr_in));    sin.sin_family = AF_INET;    sin.sin_addr.s_addr = host;    sin.sin_port = port;    if ((udpsock = socket(AF_INET, SOCK_DGRAM, 0))< 0) {	perror("Socket Error") ;	exit(1) ;    }    if (setsockopt(udpsock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one))){        perror("sockopt");        exit(1);    }    if (bind(udpsock,(struct sockaddr *)&sin,sizeof(struct sockaddr_in)) < 0) {	perror("Bind error");	exit(1);    }    if (IN_MULTICAST(ntoh32(host))) {        * (u_long *) &mreq.imr_multiaddr = host;        * (u_long *) &mreq.imr_interface = INADDR_ANY;        if (0 > setsockopt(udpsock, IPPROTO_IP, IP_ADD_MEMBERSHIP,                        &mreq, sizeof(mreq))) {                perror("Can't add to multicast group");                exit(1);        }    }    gettimeofday(&timenow, NULL) ;     printf("rsvpeep starting  %s\n", ctime(&timenow.tv_sec));    printf(Heading);    for (;;) {	recvstatus();    }}/* *  recvstatus():  Receive UDP packets and display status */voidrecvstatus(){	struct sockaddr_in from;	int fromlen = sizeof(struct sockaddr_in);	char buff[STAT_MSG_SIZE];	RSVPInfo_t	*Infop = (RSVPInfo_t *) buff;	struct timeval timenow;	int n;	n = recvfrom(udpsock, buff, sizeof(buff), 0,		     (struct sockaddr *)&from, &fromlen);	if (n < 0) {		perror("recvfrom");		exit(1);	}	/* If this is not a node we want, return.	 * Else parse and display the packet.	 */	if (src_host && from.sin_addr.s_addr != src_host) return; /* XXX */#if BYTE_ORDER == LITTLE_ENDIAN	if (ntoh_info(Infop))	    return;#endif	switch (Infop->type) {	/* first fullword is type */            case TYPE_RSVP_VPATH:		if (wrong_name(Infop->name)) return;			 /* Wanted particular node, and this is not it. */		if (Xdebug) {			printf("RCVD PATH:\n");			hexf(stdout, buff, n);			fflush(stdout);		}		if (Time_Stamp) {			gettimeofday(&timenow, NULL) ; 			printf("\n%.19s.%06ld\n",				ctime(&timenow.tv_sec), timenow.tv_usec);		}		if ((lastName[0] == '\0')||strcmp(Infop->name, lastName)) {			bzero(&last_session, sizeof(SESSION_ipv4));			printf("\nNODE= %s\n", Infop->name);		}		strcpy(lastName, Infop->name);		print_Path(&Infop->Session_un.pathInfo, Infop->nSession);		break;            case TYPE_RSVP_VRESV:		if (wrong_name(Infop->name)) return;			 /* Wanted particular node, and this is not it. */		if (Xdebug) {			printf("RCVD RESV:\n");			hexf(stdout, buff, n);		}		if (Time_Stamp) {			gettimeofday(&timenow, NULL) ; 			printf("\n%.19s.%06ld\n",				ctime(&timenow.tv_sec), timenow.tv_usec);		}		if ((lastName[0] == '\0')||strcmp(Infop->name, lastName)) {			bzero(&last_session, sizeof(SESSION_ipv4));			printf("\nNODE= %s\n", Infop->name);		}		strcpy(lastName, Infop->name);		print_Resv(&Infop->Session_un.resvInfo, Infop->nSession);		break;	    default:		fprintf(stderr, "Unknown RSVP mstat pkt type %d from host %s\n",				Infop->type, inet_ntoa(from.sin_addr));		if (Xdebug)			hexf(stdout, buff, n);		break;	}		}/* *  Display Path State from vector of n per-session data items */voidprint_Path(sesp, n)	PathInfo_t *sesp;        int n;	{	PathSender_t *Pp;	int i, j;	if (n == 0) {		printf("  PATH  (Session Gone)\n");		return;	}	for (i= 0; i<n; i++) {		if (ADDR_NEQ(&sesp->path_session, &last_session))			print_session(&sesp->path_session, NULL /* XXX */);		last_session = sesp->path_session;		Pp = &sesp->path_sender;		for (j=0; j < sesp->nSender; j++) {			FilterSpec *fip = (FILTER_SPEC *) 						Next_Object(&Pp->pathS_policy);			FlowSpec   *fsp =  (FLOWSPEC *)  Next_Object(fip);			printf("  %4.4s  %-9.9s %-16.16s ",

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -