?? test-inet_tcp.c
字號:
/***************************************************************************** @(#) test-inet_tcp.c,v LiS-2_16_18-8(1.1.4.1) 2004/01/12 23:33:18 ----------------------------------------------------------------------------- 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/01/12 23:33:18 by <bidulock@openss7.org> ----------------------------------------------------------------------------- test-inet_tcp.c,v Revision 1.1.4.1 2004/01/12 23:33:18 brian - Updated LiS-2.16.18 gcom release to autoconf. Revision 1.1.2.3 2004/01/07 11:34:53 brian - Updated copyright dates. Revision 1.1.2.2 2004/01/04 11:31:23 brian - Corrected xti include. Revision 1.1.2.1 2003/12/23 11:12:23 brian - Added INET streams test programs. *****************************************************************************/#ident "@(#) test-inet_tcp.c,v LiS-2_16_18-8(1.1.4.1) 2004/01/12 23:33:18"static char const ident[] = "test-inet_tcp.c,v LiS-2_16_18-8(1.1.4.1) 2004/01/12 23:33:18";/* * Simple test program for INET streams. */#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 <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#ifdef _GNU_SOURCE#include <getopt.h>#endif#include <stropts.h>#define NEED_T_USCALAR_T#include <xti.h>#include <tihdr.h>#include <xti_inet.h>int verbose = 1;#define BUFSIZE 5*4096#define FFLUSH(stream)#define SHORT_WAIT 10#define NORMAL_WAIT 100#define LONG_WAIT 2000ulong 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, 0, cmd.cbuf };struct strbuf data = { BUFSIZE, 0, dbuf };struct strfdinsert fdi = { {BUFSIZE, 0, cmd.cbuf}, {BUFSIZE, 0, dbuf}, 0, 0, 0};struct timeval when;#define INCONCLUSIVE -2#define SUCCESS 0#define FAILURE -1const char *device = "/dev/tcp";int show = 1;int state;int fd1, fd2, fd3;struct sockaddr_in addr1, addr2, addr3;unsigned short port1 = 10000, port2 = 10001, port3 = 10002;/* * Options *//* * data options */struct { struct t_opthdr tos_hdr __attribute__ ((packed)); t_scalar_t tos_val __attribute__ ((packed)); struct t_opthdr ttl_hdr __attribute__ ((packed)); t_scalar_t ttl_val __attribute__ ((packed)); struct t_opthdr drt_hdr __attribute__ ((packed)); t_scalar_t drt_val __attribute__ ((packed)); struct t_opthdr csm_hdr __attribute__ ((packed)); t_scalar_t csm_val __attribute__ ((packed)); struct t_opthdr ppi_hdr __attribute__ ((packed)); t_scalar_t ppi_val __attribute__ ((packed)); struct t_opthdr sid_hdr __attribute__ ((packed)); t_scalar_t sid_val __attribute__ ((packed));} opt_data = { { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TOS, T_SUCCESS} , 0x1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TTL, T_SUCCESS} , 64, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_DONTROUTE, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_UDP, T_UDP_CHECKSUM, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_PPI, T_SUCCESS} , 10, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_SID, T_SUCCESS}, 0};/* * receive data options */typedef struct rdat_opt { struct t_opthdr tos_hdr __attribute__ ((packed)); t_scalar_t tos_val __attribute__ ((packed)); struct t_opthdr ttl_hdr __attribute__ ((packed)); t_scalar_t ttl_val __attribute__ ((packed)); struct t_opthdr ppi_hdr __attribute__ ((packed)); t_scalar_t ppi_val __attribute__ ((packed)); struct t_opthdr sid_hdr __attribute__ ((packed)); t_scalar_t sid_val __attribute__ ((packed)); struct t_opthdr ssn_hdr __attribute__ ((packed)); t_scalar_t ssn_val __attribute__ ((packed)); struct t_opthdr tsn_hdr __attribute__ ((packed)); t_scalar_t tsn_val __attribute__ ((packed));} rdat_opt_t;/* * connect options */struct { struct t_opthdr tos_hdr __attribute__ ((packed)); t_scalar_t tos_val __attribute__ ((packed)); struct t_opthdr ttl_hdr __attribute__ ((packed)); t_scalar_t ttl_val __attribute__ ((packed)); struct t_opthdr drt_hdr __attribute__ ((packed)); t_scalar_t drt_val __attribute__ ((packed)); struct t_opthdr bca_hdr __attribute__ ((packed)); t_scalar_t bca_val __attribute__ ((packed)); struct t_opthdr reu_hdr __attribute__ ((packed)); t_scalar_t reu_val __attribute__ ((packed)); struct t_opthdr ist_hdr __attribute__ ((packed)); t_scalar_t ist_val __attribute__ ((packed)); struct t_opthdr ost_hdr __attribute__ ((packed)); t_scalar_t ost_val __attribute__ ((packed));} opt_conn = { { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TOS, T_SUCCESS} , 0x1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TTL, T_SUCCESS} , 64, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_DONTROUTE, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_BROADCAST, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_REUSEADDR, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_ISTREAMS, T_SUCCESS} , 1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_OSTREAMS, T_SUCCESS}, 1};/* * management options */struct { struct t_opthdr tos_hdr __attribute__ ((packed)); t_scalar_t tos_val __attribute__ ((packed)); struct t_opthdr ttl_hdr __attribute__ ((packed)); t_scalar_t ttl_val __attribute__ ((packed)); struct t_opthdr drt_hdr __attribute__ ((packed)); t_scalar_t drt_val __attribute__ ((packed)); struct t_opthdr bca_hdr __attribute__ ((packed)); t_scalar_t bca_val __attribute__ ((packed)); struct t_opthdr reu_hdr __attribute__ ((packed)); t_scalar_t reu_val __attribute__ ((packed)); struct t_opthdr ndl_hdr __attribute__ ((packed)); t_scalar_t ndl_val __attribute__ ((packed)); struct t_opthdr mxs_hdr __attribute__ ((packed)); t_scalar_t mxs_val __attribute__ ((packed)); struct t_opthdr kpa_hdr __attribute__ ((packed)); t_scalar_t kpa_val __attribute__ ((packed)); struct t_opthdr csm_hdr __attribute__ ((packed)); t_scalar_t csm_val __attribute__ ((packed)); struct t_opthdr nod_hdr __attribute__ ((packed)); t_scalar_t nod_val __attribute__ ((packed)); struct t_opthdr crk_hdr __attribute__ ((packed)); t_scalar_t crk_val __attribute__ ((packed)); struct t_opthdr ppi_hdr __attribute__ ((packed)); t_scalar_t ppi_val __attribute__ ((packed)); struct t_opthdr sid_hdr __attribute__ ((packed)); t_scalar_t sid_val __attribute__ ((packed)); struct t_opthdr rcv_hdr __attribute__ ((packed)); t_scalar_t rcv_val __attribute__ ((packed)); struct t_opthdr ckl_hdr __attribute__ ((packed)); t_scalar_t ckl_val __attribute__ ((packed)); struct t_opthdr skd_hdr __attribute__ ((packed)); t_scalar_t skd_val __attribute__ ((packed)); struct t_opthdr prt_hdr __attribute__ ((packed)); t_scalar_t prt_val __attribute__ ((packed)); struct t_opthdr art_hdr __attribute__ ((packed)); t_scalar_t art_val __attribute__ ((packed)); struct t_opthdr irt_hdr __attribute__ ((packed)); t_scalar_t irt_val __attribute__ ((packed)); struct t_opthdr hbi_hdr __attribute__ ((packed)); t_scalar_t hbi_val __attribute__ ((packed)); struct t_opthdr rin_hdr __attribute__ ((packed)); t_scalar_t rin_val __attribute__ ((packed)); struct t_opthdr rmn_hdr __attribute__ ((packed)); t_scalar_t rmn_val __attribute__ ((packed)); struct t_opthdr rmx_hdr __attribute__ ((packed)); t_scalar_t rmx_val __attribute__ ((packed)); struct t_opthdr ist_hdr __attribute__ ((packed)); t_scalar_t ist_val __attribute__ ((packed)); struct t_opthdr ost_hdr __attribute__ ((packed)); t_scalar_t ost_val __attribute__ ((packed)); struct t_opthdr cin_hdr __attribute__ ((packed)); t_scalar_t cin_val __attribute__ ((packed)); struct t_opthdr tin_hdr __attribute__ ((packed)); t_scalar_t tin_val __attribute__ ((packed)); struct t_opthdr mac_hdr __attribute__ ((packed)); t_scalar_t mac_val __attribute__ ((packed)); struct t_opthdr dbg_hdr __attribute__ ((packed)); t_scalar_t dbg_val __attribute__ ((packed));} opt_optm = { { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TOS, T_SUCCESS} , 0x1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_TTL, T_SUCCESS} , 64, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_DONTROUTE, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_BROADCAST, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_IP, T_IP_REUSEADDR, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_TCP, T_TCP_NODELAY, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_TCP, T_TCP_MAXSEG, T_SUCCESS} , 576, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_TCP, T_TCP_KEEPALIVE, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_UDP, T_UDP_CHECKSUM, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_NODELAY, T_SUCCESS} , T_YES, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_CORK, T_SUCCESS} , T_YES, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_PPI, T_SUCCESS} , 10, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_SID, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_RECVOPT, T_SUCCESS} , T_NO, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_COOKIE_LIFE, T_SUCCESS} , 60000, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_SACK_DELAY, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_PATH_MAX_RETRANS, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_ASSOC_MAX_RETRANS, T_SUCCESS} , 12, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_MAX_INIT_RETRIES, T_SUCCESS} , 12, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_HEARTBEAT_ITVL, T_SUCCESS} , 200, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_RTO_INITIAL, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_RTO_MIN, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_RTO_MAX, T_SUCCESS} , 0, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_OSTREAMS, T_SUCCESS} , 1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_ISTREAMS, T_SUCCESS} , 1, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_COOKIE_INC, T_SUCCESS} , 1000, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_THROTTLE_ITVL, T_SUCCESS} , 50, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_MAC_TYPE, T_SUCCESS} , SCTP_HMAC_NONE, { sizeof(struct t_opthdr) + sizeof(t_scalar_t), T_INET_SCTP, T_SCTP_DEBUG, T_SUCCESS}, 0};char *err_string(ulong error){ switch (error) { case TBADADDR: return ("TBADADDR"); case TBADOPT: return ("TBADOPT"); case TACCES: return ("TACCES"); case TBADF: return ("TBADF"); case TNOADDR: return ("TNOADDR"); case TOUTSTATE: return ("TOUTSTATE"); case TBADSEQ: return ("TBADSEQ"); case TSYSERR: return ("TSYSERR"); case TLOOK: return ("TLOOK"); case TBADDATA: return ("TBADDATA"); case TBUFOVFLW: return ("TBUFOVFLW"); case TFLOW: return ("TFLOW"); case TNODATA: return ("TNODATA"); case TNODIS: return ("TNODIS"); case TNOUDERR: return ("TNOUDERR"); case TBADFLAG: return ("TBADFLAG"); case TNOREL: return ("TNOREL"); case TNOTSUPPORT: return ("TNOTSUPPORT"); case TSTATECHNG: return ("TSTATECHNG"); case TNOSTRUCTYPE: return ("TNOSTRUCTTYPE"); case TBADNAME: return ("TBADNAME"); case TBADQLEN: return ("TBADQLEN"); case TADDRBUSY: return ("TADDRBUSY"); case TINDOUT: return ("TINDOUT"); case TPROVMISMATCH: return ("TPROVMISMATCH"); case TRESQLEN: return ("TRESQLEN"); case TRESADDR: return ("TRESADDR"); case TQFULL: return ("TQFULL"); case TPROTO: return ("TPROTO"); default: return ("(unknown)"); }}voidprint_error(ulong error){ printf("%s\n", err_string(error));}char *prim_string(ulong prim){ switch (prim) { case T_CONN_REQ: return ("T_CONN_REQ"); case T_CONN_RES: return ("T_CONN_RES"); case T_DISCON_REQ: return ("T_DISCON_REQ"); case T_DATA_REQ: return ("T_DATA_REQ"); case T_EXDATA_REQ: return ("T_EXDATA_REQ"); case T_OPTDATA_REQ: return ("T_OPTDATA_REQ"); case T_INFO_REQ: return ("T_INFO_REQ"); case T_BIND_REQ: return ("T_BIND_REQ"); case T_UNBIND_REQ: return ("T_UNBIND_REQ"); case T_UNITDATA_REQ: return ("T_UNITDATA_REQ"); case T_OPTMGMT_REQ: return ("T_OPTMGMT_REQ");
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -