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

📄 test-inet_udp.c

📁 This a separate release of the OpenSS7 X/Open XTI/TLI library, TLI modules (timod, tirdwr) and the I
💻 C
📖 第 1 页 / 共 5 页
字号:
/***************************************************************************** @(#) test-inet_udp.c,v strxnet-0_9_2-4(0.9.2.1) 2004/05/16 04:12:36 ----------------------------------------------------------------------------- Copyright (c) 2001-2004 OpenSS7 Corporation <http://www.openss7.com/> Copyright (c) 1997-2000 Brian F. G. Bidulock <bidulock@dallas.net> All Rights Reserved. Unauthorized distribution or duplication is prohibited. This software and related documentation is protected by copyright and distributed under licenses restricting its use, copying, distribution and decompilation.  No part of this software or related documentation may be reproduced in any form by any means without the prior written authorization of the copyright holder, and licensors, if any. The recipient of this document, by its retention and use, warrants that the recipient will protect this information and keep it confidential, and will not disclose the information contained in this document without the written permission of its owner. The author reserves the right to revise this software and documentation for any reason, including but not limited to, conformity with standards promulgated by various agencies, utilization of advances in the state of the technical arts, or the reflection of changes in the design of any techniques, or procedures embodied, described, or referred to herein. The author is under no obligation to provide any feature listed herein. ----------------------------------------------------------------------------- U.S. GOVERNMENT RESTRICTED RIGHTS.  If you are licensing this Software on behalf of the U.S. Government ("Government"), the following provisions apply to you.  If the Software is supplied by the Department of Defense ("DoD"), it is classified as "Commercial Computer Software" under paragraph 252.227-7014 of the DoD Supplement to the Federal Acquisition Regulations ("DFARS") (or any successor regulations) and the Government is acquiring only the license rights granted herein (the license rights customarily provided to non-Government users).  If the Software is supplied to any unit or agency of the Government other than DoD, it is classified as "Restricted Computer Software" and the Government's rights in the Software are defined in paragraph 52.227-19 of the Federal Acquisition Regulations ("FAR") (or any success regulations) or, in the cases of NASA, in paragraph 18.52.227-86 of the NASA Supplement to the FAR (or any successor regulations). ----------------------------------------------------------------------------- Commercial licensing and support of this software is available from OpenSS7 Corporation at a fee.  See http://www.openss7.com/ ----------------------------------------------------------------------------- Last Modified 2004/05/16 04:12:36 by <bidulock@openss7.org> ----------------------------------------------------------------------------- test-inet_udp.c,v Revision 0.9.2.1  2004/05/16 04:12:36  brian - Updating strxnet release. Revision 1.1.4.11  2004/04/13 12:12:57  brian - Rearranged header files. Revision 1.1.4.10  2004/04/13 06:04:05  brian - INET driver works pretty good now. Revision 1.1.4.9  2004/04/12 20:50:05  brian - Added ability to list test cases. Revision 1.1.4.8  2004/04/12 20:17:59  brian - Test cases pass. Revision 1.1.4.7  2004/04/12 11:34:31  brian - INET driver working better now for UDP. Revision 1.1.4.6  2004/04/09 11:24:57  brian - Cleaned up printouts and verbosity. Revision 1.1.4.5  2004/04/08 14:53:59  brian - Added more test cases. Revision 1.1.4.4  2004/04/08 13:14:33  brian - Updated INET-UDP test program. Revision 1.1.4.3  2004/03/31 09:00:53  brian - Working up new inet driver and documentation. Revision 1.1.4.2  2004/03/28 17:30:21  brian - First clean compile of inet updates. Revision 1.1.4.1  2004/01/12 23:33:19  brian - Updated LiS-2.16.18 gcom release to autoconf. Revision 1.1.2.3  2004/01/07 11:34:54  brian - Updated copyright dates. Revision 1.1.2.2  2004/01/04 11:31:24  brian - Corrected xti include. Revision 1.1.2.1  2003/12/23 11:12:24  brian - Added INET streams test programs. *****************************************************************************/#ident "@(#) test-inet_udp.c,v strxnet-0_9_2-4(0.9.2.1) 2004/05/16 04:12:36"static char const ident[] = "test-inet_udp.c,v strxnet-0_9_2-4(0.9.2.1) 2004/05/16 04:12:36";/*  *  Simple test program for INET streams. */#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <stdio.h>#include <sys/stat.h>#include <fcntl.h>#include <errno.h>#include <string.h>#include <signal.h>#include <sys/uio.h>#ifdef _GNU_SOURCE#include <getopt.h>#endif#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#define NEED_T_USCALAR_T#include <sys/types.h>#include <tihdr.h>#include <xti.h>#include <xti_inet.h>#include <sys/xti_sctp.h>/*  *  ------------------------------------------------------------------------- * *  Configuration * *  ------------------------------------------------------------------------- */static int verbose = 1;static int show_msg = 0;static int show_acks = 0;static int show_timeout = 0;static int last_event = 0;static int last_errno = 0;static int last_prim = 0;static int conn_fd = 0;static int resp_fd = 0;static int list_fd = 0;#define BUFSIZE 5*4096#define FFLUSH(stream)#define SHORT_WAIT 10#define NORMAL_WAIT 100#define LONG_WAIT 500ulong seq[10] = { 0, };ulong tok[10] = { 0, };ulong tsn[10] = { 0, };ulong sid[10] = { 0, };union {	union T_primitives tpi;	char cbuf[BUFSIZE];} cmd;char dbuf[BUFSIZE];struct strbuf ctrl = { BUFSIZE, -1, cmd.cbuf };struct strbuf data = { BUFSIZE, -1, dbuf };struct strfdinsert fdi = {	{BUFSIZE, 0, cmd.cbuf},	{BUFSIZE, 0, dbuf},	0,	0,	0};int flags = 0;struct timeval when;/*  *  ------------------------------------------------------------------------- * *  Events and Actions * *  ------------------------------------------------------------------------- */enum {	__EVENT_NO_MSG = -6, __EVENT_TIMEOUT = -5, __EVENT_UNKNOWN = -4,	__RESULT_DECODE_ERROR = -3, __RESULT_SCRIPT_ERROR = -2,	__RESULT_INCONCLUSIVE = -1, __RESULT_SUCCESS = 0,	__RESULT_FAILURE = 1, __EVENT_CONN_REQ = 2, __EVENT_CONN_RES,	__EVENT_DISCON_REQ, __EVENT_DATA_REQ, __EVENT_EXDATA_REQ,	__EVENT_INFO_REQ, __EVENT_BIND_REQ, __EVENT_UNBIND_REQ,	__EVENT_UNITDATA_REQ, __EVENT_OPTMGMT_REQ, __EVENT_ORDREL_REQ,	__EVENT_OPTDATA_REQ, __EVENT_ADDR_REQ, __EVENT_CAPABILITY_REQ,	__EVENT_CONN_IND, __EVENT_CONN_CON, __EVENT_DISCON_IND,	__EVENT_DATA_IND, __EVENT_EXDATA_IND, __EVENT_INFO_ACK,	__EVENT_BIND_ACK, __EVENT_ERROR_ACK, __EVENT_OK_ACK,	__EVENT_UNITDATA_IND, __EVENT_UDERROR_IND, __EVENT_OPTMGMT_ACK,	__EVENT_ORDREL_IND, __EVENT_OPTDATA_IND, __EVENT_ADDR_ACK,	__EVENT_CAPABILITY_ACK, __EVENT_WRITE, __EVENT_WRITEV,	__EVENT_PUTMSG_DATA, __EVENT_PUTPMSG_DATA, __EVENT_PUSH, __EVENT_POP,	__EVENT_READ, __EVENT_READV, __EVENT_GETMSG, __EVENT_GETPMSG,	__EVENT_DATA,};/*  *  ------------------------------------------------------------------------- */const char *device = "/dev/udp";int show = 1;struct sockaddr_in addr1, addr2, addr3, addr4;unsigned short port1 = 10000, port2 = 10001, port3 = 10002, port4 = 10003;/*  *  ------------------------------------------------------------------------- * *  Timer Functions * *  ------------------------------------------------------------------------- *//*  *  Timer values for tests: each timer has a low range (minus error margin) *  and a high range (plus error margin). */static long timer_scale = 1;#define TEST_TIMEOUT 5000typedef struct timer_range {	long lo;	long hi;} timer_range_t;enum {	t1 = 0, t2, t3, t4, t5, t6, t7, t8, t9, t10, t11, t12, t13, t14, t15,	t16, t17, t18, t19, t20, t21, t22, t23, t24, t25, t26, t27, t28, t29,	t30, t31, t32, t33, t34, t35, t36, t37, t38, tmax};#undef HZ#define HZ 1000/* *INDENT-OFF* */static timer_range_t timer[tmax] = {	{(15 * HZ),		(60 * HZ)},		/* T1 15-60 seconds */	{(3 * 60 * HZ),		(3 * 60 * HZ)},		/* T2 3 minutes */	{(2 * 60 * HZ),		(2 * 60 * HZ)},		/* T3 2 minutes */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T4 5-15 minutes */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T5 5-15 minutes */	{(10 * HZ),		(32 * HZ)},		/* T6 10-32 seconds (specified in Q.118) */	{(20 * HZ),		(30 * HZ)},		/* T7 20-30 seconds */	{(10 * HZ),		(15 * HZ)},		/* T8 10-15 seconds */	{(2 * 60 * HZ),		(4 * 60 * HZ)},		/* T9 2-4 minutes (specified in Q.118) */	{(4 * HZ),		(6 * HZ)},		/* T10 4-6 seconds */	{(15 * HZ),		(20 * HZ)},		/* T11 15-20 seconds */	{(15 * HZ),		(60 * HZ)},		/* T12 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T13 5-15 minutes */	{(15 * HZ),		(60 * HZ)},		/* T14 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T15 5-15 minutes */	{(15 * HZ),		(60 * HZ)},		/* T16 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T17 5-15 minutes */	{(15 * HZ),		(60 * HZ)},		/* T18 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T19 5-15 minutes */	{(15 * HZ),		(60 * HZ)},		/* T20 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T21 5-15 minutes */	{(15 * HZ),		(60 * HZ)},		/* T22 15-60 seconds */	{(5 * 60 * HZ),		(15 * 60 * HZ)},	/* T23 5-15 minutes */	{(1 * HZ),		(2 * HZ)},		/* T24 < 2 seconds */	{(1 * HZ),		(10 * HZ)},		/* T25 1-10 seconds */	{(1 * 60 * HZ),		(3 * 60 * HZ)},		/* T26 1-3 minutes */	{(4 * 60 * HZ),		(4 * 60 * HZ)},		/* T27 4 minutes */	{(10 * HZ),		(10 * HZ)},		/* T28 10 seconds */	{(300 * HZ / 1000),	(600 * HZ / 1000)},	/* T29 300-600 milliseconds */	{(5 * HZ),		(10 * HZ)},		/* T30 5-10 seconds */	{(6 * 60 * HZ),		(7 * 60 * HZ)},		/* T31 > 6 minutes */	{(3 * HZ),		(5 * HZ)},		/* T32 3-5 seconds */	{(12 * HZ),		(15 * HZ)},		/* T33 12-15 seconds */	{(12 * HZ),		(15 * HZ)},		/* T34 12-15 seconds */	{(15 * HZ),		(20 * HZ)},		/* T35 15-20 seconds */	{(15 * HZ),		(20 * HZ)},		/* T36 15-20 seconds */	{(2 * HZ),		(4 * HZ)},		/* T37 2-4 seconds */	{(15 * HZ),		(20 * HZ)}		/* T38 15-20 seconds */};/* *INDENT-ON* */long test_start = 0;static int state;/*  *  Return the current time in milliseconds. */static longnow(void){	long ret;	struct timeval now;	if (gettimeofday(&now, NULL)) {		last_errno = errno;		lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "***************ERROR! couldn't get time!            !  !                    \n");		fprintf(stdout, "%20s! %-54s\n", __FUNCTION__, strerror(last_errno));		fflush(stdout);		lockf(fileno(stdout), F_ULOCK, 0);		return (0);	}	if (!test_start)	/* avoid blowing over precision */		test_start = now.tv_sec;	ret = (now.tv_sec - test_start) * 1000L;	ret += (now.tv_usec + 999L) / 1000L;	return ret;}static longmilliseconds(char *t){	if (verbose > 0) {		lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "                    .               :               .  .                    \n");		fprintf(stdout, "                    .             %6s            .  .                    <%d>\n", t, state);		fprintf(stdout, "                    .               :               .  .                    \n");		fflush(stdout);		lockf(fileno(stdout), F_ULOCK, 0);	}	return now();}static longmilliseconds_2nd(char *t){	if (verbose > 0) {		lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "                    .               :   :           .  .                    \n");		fprintf(stdout, "                    .               : %6s        .  .                    <%d>\n", t, state);		fprintf(stdout, "                    .               :   :           .  .                    \n");		fflush(stdout);		lockf(fileno(stdout), F_ULOCK, 0);	}	return now();}/*  *  Check the current time against the beginning time provided as an argnument *  and see if the time inverval falls between the low and high values for the *  timer as specified by arguments.  Return SUCCESS if the interval is within *  the allowable range and FAILURE otherwise. */static intcheck_time(const char *t, long i, long lo, long hi){	float tol, dlo, dhi, itv;	itv = i * timer_scale;	dlo = lo;	dhi = hi;	tol = 100 * timer_scale;	itv = itv / 1000;	dlo = dlo / 1000;	dhi = dhi / 1000;	tol = tol / 1000;	if (verbose > 0) {		lockf(fileno(stdout), F_LOCK, 0);		fprintf(stdout, "                    |(%7.3g <= %7.3g <= %7.3g)|  | %6s             <%d>\n", dlo - tol, itv, dhi + tol, t, state);		fflush(stdout);		lockf(fileno(stdout), F_ULOCK, 0);	}	if (dlo - tol <= itv && itv <= dhi + tol)		return __RESULT_SUCCESS;	else		return __RESULT_FAILURE;}static inttime_event(int event)

⌨️ 快捷键说明

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