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

📄 rapi_fmt.c

📁 radius协议源码÷The Radius Stack will connect to a Radius Server. This stack implementation is built upo
💻 C
📖 第 1 页 / 共 2 页
字号:
/* * @(#) $Id: rapi_fmt.c,v 1.1.1.1 2000/05/08 22:51:24 wenqing Exp $ *//************************ rapi_fmt.c ***************************** *                                                               * *  RSVP API library routines for formatting flowspecs, Tspecs,  * *  adspecs, and filter specs.                                   * *                                                               * *****************************************************************//*****************************************************************************//*                                                                           *//*          RSVPD -- ReSerVation Protocol Daemon                             *//*                                                                           *//*              USC Information Sciences Institute                           *//*              Marina del Rey, California                                   *//*                                                                           *//*		Original Version: Shai Herzog, Nov. 1993.                    *//*		Current Version:  Steven Berson & Bob Braden, May 1996.      *//*                                                                           *//*      Copyright (c) 1996 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 any purpose and     *//*	without fee is hereby granted, provided that both the above          *//*	copyright notice and this permission notice appear in all copies,    *//*	and that any documentation, advertising materials, and other         *//*	materials related to such distribution and use acknowledge that      *//*	the software was developed in part 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.                *//*                                                                           *//*****************************************************************************/#include <stdio.h>#include <sys/param.h>#include <sys/types.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>#include <string.h>#include <assert.h>#ifdef RSVP_TCPDUMP#define _MACHINE_ENDIAN_H_ 1#endif#include "rsvp_socks.h"#include "rsvp_trans.h"#include "rsvp_types.h"#include "rsvp.h"#include "rsvp_specs.h"#include "rsvp_api.h"void	rapi_fmt_flowspec(rapi_flowspec_t *, char *, int);void	rapi_fmt_tspec(rapi_tspec_t *, char *, int);void	rapi_fmt_adspec(rapi_adspec_t *, char *, int);void	rapi_fmt_filtspec(rapi_filter_t *, char *, int);char *	rapi_fmt_specbody2(qos_flowspecx_t *);char *	rapi_fmt_tspecbody2(qos_tspecx_t *);char *  rapi_fmt_specbody3(IS_specbody_t *);char *	rapi_fmt_tspecbody3(IS_tspbody_t *);char *	rapi_fmt_gen_Tspecbody3(TB_Tsp_parms_t *gp);char *	rapi_fmt_adspecbody2(qos_adspecx_t *);char *	rapi_fmt_adspecbody3(IS_adsbody_t *);char *	fspec_fmtf(float32_t, char *);static 	char	out[256];static  char	out1[80];static  char	*serv_name[] = {"", "Gen", "G", "P", "C-D", "CL"}; /* conversion buffers */char	b1[8], b2[8], b3[8], b4[8], b5[8], b6[8], b7[8]; /* *	Format RAPI flowspec into buffer of given length. */voidrapi_fmt_flowspec(rapi_flowspec_t * specp, char *buff, int len)	{	char *	cp;	int	body_len;	if (len < 16)		return;	if (!specp) {		strcpy(buff, " [ ]");		return;	}	switch (specp->form) {            case RAPI_EMPTY_OTYPE:                sprintf(buff, " [ ]");		return;	    case RAPI_FLOWSTYPE_Simplified:		if (specp->len != sizeof(qos_flowspecx_t) + sizeof(rapi_hdr_t)){			sprintf(buff, "CSZX spec len?? %d\n", specp->len);			return;		}		cp = rapi_fmt_specbody2(&specp->specbody_qosx);		break;	    case RAPI_FLOWSTYPE_Intserv:		body_len = Intserv_Obj_size(&specp->specbody_IS) 				-sizeof(Object_header);		if (specp->len < body_len+8){			sprintf(buff, "IS spec len?? %d\n", specp->len);			return;		}		cp = rapi_fmt_specbody3(&specp->specbody_IS);		break;	    default:		cp = "??RAPI Flowspec format\n";		break;	}	if (strlen(cp) > len)		strncpy(buff, "!Fmt overflow\n", len);	else		strcpy(buff, cp);}/* *	Format RAPI Tspec into buffer of given length. */voidrapi_fmt_tspec(rapi_tspec_t * tspecp, char *buff, int len)	{	char *	cp;	int	body_len;	if (len < 16)		return;	if (!tspecp) {		strcpy(buff, " [ ]");		return;	}		switch (tspecp->form) {            case RAPI_EMPTY_OTYPE:                sprintf(buff, " TS[ ]");		return;	    case RAPI_TSPECTYPE_Simplified:		if (tspecp->len != sizeof(qos_tspecx_t) + sizeof(rapi_hdr_t)){			sprintf(buff, "CSZX spec len?? %d\n", tspecp->len);			return;		}		cp = rapi_fmt_tspecbody2(&tspecp->tspecbody_qosx);		break;	    case RAPI_TSPECTYPE_Intserv:		body_len = Intserv_Obj_size(&tspecp->tspecbody_IS) 							-sizeof(Object_header);		if (tspecp->len < body_len+8){			sprintf(buff, "IS Tspec len?? %d\n", tspecp->len);			return;		}		cp = rapi_fmt_tspecbody3(&tspecp->tspecbody_IS);		break;	    default:		cp = "??RAPI Tspec format\n";		break;	}	if (strlen(cp) > len)		strncpy(buff, "!Fmt overflow\n", len);	else		strcpy(buff, cp);}/* *	Format RAPI Adspec into buffer of given length. */voidrapi_fmt_adspec(rapi_adspec_t * adspecp, char *buff, int len)	{	char *	cp;	if (len < 16)		return;	if (!adspecp) {		strcpy(buff, " [ ]");		return;	}		switch (adspecp->form) {            case RAPI_EMPTY_OTYPE:                sprintf(buff, " Adspec()");		return;	    case RAPI_ADSTYPE_Simplified:		if (adspecp->len != sizeof(qos_adspecx_t)+sizeof(rapi_hdr_t)){			sprintf(buff, "CSZX adspec len?? %d\n", adspecp->len);			return;		}		cp = rapi_fmt_adspecbody2(&adspecp->adspecbody_qosx);		break;	    case RAPI_ADSTYPE_Intserv:		if (size_api2d(adspecp->len) !=				Intserv_Obj_size(&adspecp->adspecbody_IS)) {		sprintf(buff, "IS Adspec len?? %d\n", adspecp->len);			return;		}		cp = rapi_fmt_adspecbody3(				(IS_adsbody_t *)RAPIObj_data(adspecp));		break;	    default:		cp = "??RAPI Adspec format\n";		break;	}	if (strlen(cp) > len)		strncpy( buff, "!Fmt overflow\n",len);	else		strcpy(buff, cp);}/* *	Format body of "Simplified format" flowspec */char *rapi_fmt_specbody2(qos_flowspecx_t *csxp)	{	char *qos_name[] = {"T", "CL", "G"};	if (csxp->spec_type > QOS_GUARANTEED)		sprintf(out, "[?spec_type %d ]", csxp->spec_type);	else		sprintf(out, " [%s [%s(%s) p=%s m=%s M=%s] R=%s S=%s]",			qos_name[csxp->spec_type],			fspec_fmtf(csxp->xspec_r, b1),			fspec_fmtf(csxp->xspec_b, b2),			fspec_fmtf(csxp->xspec_p, b3),			fspec_fmtf((float32_t)csxp->xspec_m, b4),			fspec_fmtf((float32_t)csxp->xspec_M, b5),			fspec_fmtf(csxp->xspec_R, b6),			fspec_fmtf((float32_t)csxp->xspec_S, b7));        return(out);}/* *	Format body of "Integrated Services format" flowspec */char *rapi_fmt_specbody3(IS_specbody_t *sbp)	{	IS_serv_hdr_t	*shp = (IS_serv_hdr_t *) &sbp->spec_u;	char		 out1[80], out2[80];	int		 vers;	vers = sbp->spec_mh.ismh_version & INTSERV_VERS_MASK;	if (vers != INTSERV_VERSION0) {		sprintf(out, "IS flowspec version? %d\n", vers);		return(out);	}	if (Issh_len32b(shp) != sbp->spec_mh.ismh_len32b - 1) {		sprintf(out, ">1 serv hdr: unsupported.\n");		return(out);	}	switch (shp->issh_service) {	    case GUARANTEED_SERV:		{		Guar_flowspec_t *gp = &sbp->spec_u.G_spec;		/* Don't print if invalid */		if (gp->Gspec_T_flags & ISPH_FLG_INV ||		    gp->Gspec_R_flags & ISPH_FLG_INV) {			strcpy(out1, "INV");			out2[0] = '\0';		} else {			sprintf(out1, "R=%s S=%s",				fspec_fmtf(gp->Gspec_R, b1),				fspec_fmtf((float32_t)gp->Gspec_S, b2));			strcpy(out2,				rapi_fmt_gen_Tspecbody3(&gp->Guar_Tspec_parms));		}		}		break;	    case CONTROLLED_LOAD_SERV:		{		CL_flowspec_t *clp = &sbp->spec_u.CL_spec;					out2[0] = '\0';		if (clp->CLspec_flags & ISPH_FLG_INV) {			strcpy(out1, "INV");		} else {			strcpy(out1,				rapi_fmt_gen_Tspecbody3(&clp->CL_spec_parms));		}		}		break;	}	sprintf(out, "[%s %s %s]", serv_name[shp->issh_service], out1, out2);	return(out);}/* *	Format body of "Simplified format" tspec */char *rapi_fmt_tspecbody2(qos_tspecx_t *ctxp)	{	char *qos_name[] = {"T"};	if (ctxp->spec_type != QOS_TSPEC)		sprintf(out, "[?spec_type %d ]", ctxp->spec_type);	else		sprintf(out, " [%s [%s(%s) p=%s m=%s M=%s]]",

⌨️ 快捷键说明

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