📄 test-sctp_n.c
字号:
/***************************************************************************** @(#) test-sctp_n.c,v 0.7.8.1 2001/12/11 13:26:38 brian Exp ----------------------------------------------------------------------------- Copyright (C) 2001 OpenSS7 Corporation <http://www.openss7.com/> 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. OpenSS7 Corporation 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. OpenSS7 Corporation 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). ----------------------------------------------------------------------------- Modified 2001/12/11 13:26:38 by brian *****************************************************************************/#ident "@(#) test-sctp_n.c,v 0.7.8.1 2001/12/11 13:26:38 brian Exp"static char const ident[] = "test-sctp_n.c,v 0.7.8.1 2001/12/11 13:26:38 brian Exp";/* * This file is for testing the sctp_n driver. It is provided for the * purpose of testing the OpenSS7 sctp_n driver only. */#include <stropts.h>#include <stdlib.h>#include <unistd.h>#include <sys/ioctl.h>#include <sys/time.h>#include <sys/poll.h>#include <linux/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>#if 0#include "../include/sys/npi.h"#include "../include/sys/npi_sctp.h"#else#include <sys/npi.h>#include <sys/npi_sctp.h>#endif#define BUFSIZE 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 { np_ulong prim; union N_primitives npi; char cbuf[BUFSIZE];} cmd;char dbuf[BUFSIZE];struct strbuf ctrl = { BUFSIZE, 0, cmd.cbuf };struct strbuf data = { BUFSIZE, 0, dbuf };typedef struct addr { uint16_t port __attribute__((packed)); struct in_addr addr[3] __attribute__((packed));} addr_t;struct timeval when;#define INCONCLUSIVE -2#define FAILURE -1#define SUCCESS 0int show = 1;int state;int fd1, fd2, fd3;addr_t addr1, addr2, addr3;N_qos_sel_data_sctp_t qos_data ={ N_QOS_SEL_DATA_SCTP, /* n_qos_type */ 10, /* ppi */ 0, /* sid */ 0, /* ssn */ 0, /* tsn */ 0 /* more */};N_qos_sel_conn_sctp_t qos_conn ={ N_QOS_SEL_CONN_SCTP, /* n_qos_type */ 1, /* i_streams */ 1 /* o_streams */};N_qos_sel_info_sctp_t qos_info ={ N_QOS_SEL_INFO_SCTP, /* n_qos_type */ 1, /* i_streams */ 1, /* o_streams */ 10, /* ppi */ 0, /* sid */ 12, /* max_inits */ 12, /* max_retrans */ -1UL, /* ck_life */ -1UL, /* ck_inc */ -1UL, /* hmac */ -1UL, /* throttle */ 0, /* max_sack */ 0, /* rto_ini */ 0, /* rto_min */ 0, /* rto_max */ 0, /* rtx_path */ 200, /* hb_itvl */ 0 /* options */};char *err_string(ulong error){ switch ( error ) { case NBADADDR: return("NBADADDR"); case NBADOPT: return("NBADOPT"); case NACCESS: return("NACCESS"); case NNOADDR: return("NNOADDR"); case NOUTSTATE: return("NOUTSTATE"); case NBADSEQ: return("NBADSEQ"); case NSYSERR: return("NSYSERR"); case NBADDATA: return("NBADDATA"); case NBADFLAG: return("NBADFLAG"); case NNOTSUPPORT: return("NNOTSUPPORT"); case NBOUND: return("NBOUND"); case NBADQOSPARAM: return("NBADQOSPARAM"); case NBADQOSTYPE: return("NBADQOSTYPE"); case NBADTOKEN: return("NBADTOKEN"); case NNOPROTOID: return("NNOPROTOID"); default: return("(unknown)"); }}void print_error(ulong error){ printf("%s\n", err_string(error));}char *prim_string(ulong prim){ switch ( prim ) { case N_CONN_REQ: return("N_CONN_REQ"); case N_CONN_RES: return("N_CONN_RES"); case N_DISCON_REQ: return("N_DISCON_REQ"); case N_DATA_REQ: return("N_DATA_REQ"); case N_EXDATA_REQ: return("N_EXDATA_REQ"); case N_INFO_REQ: return("N_INFO_REQ"); case N_BIND_REQ: return("N_BIND_REQ"); case N_UNBIND_REQ: return("N_UNBIND_REQ"); case N_UNITDATA_REQ: return("N_UNITDATA_REQ"); case N_OPTMGMT_REQ: return("N_OPTMGMT_REQ"); case N_DATACK_REQ: return("N_DATACK_REQ"); case N_RESET_REQ: return("N_RESET_REQ"); case N_RESET_RES: return("N_RESET_RES"); case N_CONN_IND: return("N_CONN_IND"); case N_CONN_CON: return("N_CONN_CON"); case N_DISCON_IND: return("N_DISCON_IND"); case N_DATA_IND: return("N_DATA_IND"); case N_EXDATA_IND: return("N_EXDATA_IND"); case N_INFO_ACK: return("N_INFO_ACK"); case N_BIND_ACK: return("N_BIND_ACK"); case N_OK_ACK: return("N_OK_ACK"); case N_ERROR_ACK: return("N_ERROR_ACK"); case N_DATACK_IND: return("N_DATACK_IND"); case N_RESET_IND: return("N_RESET_IND"); case N_RESET_CON: return("N_RESET_CON"); case FAILURE: return("(nothing)"); default: return("(unexpected)"); }}void print_prim(ulong prim){ printf("%s", prim_string(prim));}void print_state(ulong state){ switch ( state ) { case NS_UNBND: printf("NS_UNBND"); break; case NS_WACK_BREQ: printf("NS_WACK_BREQ"); break; case NS_WACK_UREQ: printf("NS_WACK_UREQ"); break; case NS_IDLE: printf("NS_IDLE"); break; case NS_WACK_OPTREQ: printf("NS_WACK_OPTREQ"); break; case NS_WACK_RRES: printf("NS_WACK_RRES"); break; case NS_WCON_CREQ: printf("NS_WCON_CREQ"); break; case NS_WRES_CIND: printf("NS_WRES_CIND"); break; case NS_WACK_CRES: printf("NS_WACK_CRES"); break; case NS_DATA_XFER: printf("NS_DATA_XFER"); break; case NS_WCON_RREQ: printf("NS_WCON_RREQ"); break; case NS_WRES_RIND: printf("NS_WRES_RIND"); break; case NS_WACK_DREQ6: printf("NS_WACK_DREQ6"); break; case NS_WACK_DREQ7: printf("NS_WACK_DREQ7"); break; case NS_WACK_DREQ9: printf("NS_WACK_DREQ9"); break; case NS_WACK_DREQ10: printf("NS_WACK_DREQ10"); break; case NS_WACK_DREQ11: printf("NS_WACK_DREQ11"); break; default: printf("(unknown [%lu])", state); break; } printf("\n"); return;}void print_addr(char *add_ptr, size_t add_len){ sctp_addr_t *a = (sctp_addr_t *)add_ptr; size_t anum = add_len >= sizeof(a->port) ? (add_len - sizeof(a->port))/sizeof(a->addr[0]) : 0; if ( add_len ) { int i; if ( add_len != sizeof(a->port)+anum*sizeof(a->addr[0]) ) printf("Aaarrg! add_len = %d, anum = %d, ", add_len, anum); printf("[%d]", ntohs(a->port)); for ( i = 0; i < anum; i++ ) { printf("%s%d.%d.%d.%d", i?",":"", (a->addr[i]>> 0) & 0xff, (a->addr[i]>> 8) & 0xff, (a->addr[i]>>16) & 0xff, (a->addr[i]>>24) & 0xff); } } else printf("(no address)"); printf("\n");}void print_proto(char *pro_ptr, size_t pro_len){ uint32_t *p = (uint32_t *)pro_ptr; size_t pnum = pro_len/sizeof(p[0]); if ( pro_len ) { int i; if ( !pnum ) printf("(PROTOID_length = %d)",pro_len); for ( i = 0; i < pnum; i++ ) { printf("%s%d", i?",":"", p[i]); } } else printf("(no protoids)"); printf("\n");}void print_qos(char *qos_ptr, size_t qos_len){ N_qos_sctp_t *qos = (N_qos_sctp_t *)qos_ptr; if ( qos_len ) { switch ( qos->n_qos_type ) { case N_QOS_SEL_CONN_SCTP: printf("CONN:"); printf(" i_streams=%ld,", (long)qos->n_qos_conn.i_streams); printf(" o_streams=%ld ", (long)qos->n_qos_conn.o_streams); break; case N_QOS_SEL_DATA_SCTP: printf("DATA: "); printf(" ppi=%ld,", (long)qos->n_qos_data.ppi); printf(" sid=%ld,", (long)qos->n_qos_data.sid); printf(" ssn=%ld,", (long)qos->n_qos_data.ssn); printf(" tsn=%lu,", (ulong)qos->n_qos_data.tsn); printf(" more=%ld", (long)qos->n_qos_data.more); break; case N_QOS_SEL_INFO_SCTP: printf("INFO: "); printf(" i_streams=%ld,", (long)qos->n_qos_info.i_streams); printf(" o_streams=%ld,", (long)qos->n_qos_info.o_streams); printf(" ppi=%ld,", (long)qos->n_qos_info.ppi); printf(" sid=%ld,", (long)qos->n_qos_info.sid); printf("\n "); printf(" max_inits=%ld,", (long)qos->n_qos_info.max_inits); printf(" max_retrans=%ld,", (long)qos->n_qos_info.max_retrans); printf(" max_sack=%ld,", (long)qos->n_qos_info.max_sack); printf("\n "); printf(" ck_life=%ld,", (long)qos->n_qos_info.ck_life); printf(" ck_inc=%ld,", (long)qos->n_qos_info.ck_inc); printf(" hmac=%ld,", (long)qos->n_qos_info.hmac); printf(" throttle=%ld,", (long)qos->n_qos_info.throttle); printf("\n "); printf(" rto_ini=%ld,", (long)qos->n_qos_info.rto_ini); printf(" rto_min=%ld,", (long)qos->n_qos_info.rto_min); printf(" rto_max=%ld,", (long)qos->n_qos_info.rto_max); printf(" rtx_path=%ld,", (long)qos->n_qos_info.rtx_path); printf(" hb_itvl=%ld", (long)qos->n_qos_info.hb_itvl); printf("\n "); printf(" options="); if ( !qos->n_qos_info.options ) printf("(none)"); if ( qos->n_qos_info.options & SCTP_OPTION_DROPPING ) printf(" DEBUG-DROPPING"); if ( qos->n_qos_info.options & SCTP_OPTION_BREAK ) printf(" DEBUG-BREAK"); if ( qos->n_qos_info.options & SCTP_OPTION_DBREAK ) printf(" DEBUG-DBREAK"); if ( qos->n_qos_info.options & SCTP_OPTION_RANDOM ) printf(" DEBUG-RANDOM"); break; case N_QOS_RANGE_INFO_SCTP: printf("RANGE: "); break; default: printf("(unknown qos structure %lu)\n", qos->n_qos_type); break; } } else printf("(no qos)"); printf("\n");}void print_size(ulong size){ switch ( size ) { case -1UL: printf("UNLIMITED\n"); break; case -2UL: printf("UNDEFINED\n"); break; default: printf("%lu\n", size); break; }}void print_msg(int fd){ if ( ctrl.len > 0 ) { switch ( show ) { case 0: return; case 2: switch ( cmd.prim ) { case N_INFO_REQ: printf("%d-N_INFO_REQ:\n",fd); break; case N_INFO_ACK:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -