📄 acusaptest.c
字号:
/* **************************************************************** * * * HULA project - connectionless ISODE * * * * module: acusaptest.c * * author: Bill Haggerty, Kurt Dobbins * * date: 4/89 * * * * This code implements a test driver for A-UNIT-DATA service. * * * **************************************************************** * * * NOTICE * * * * Use of this module is subject to the restrictions of the * * ISODE license agreement. * * * **************************************************************** */#include <stdio.h>#include <ctype.h>#define ACSE#include "acupkt.h"#include "isoservent.h"#include "isoaddrs.h"#include "internet.h"#include "ADD-types.h"#include "varargs.h"#include "ssap.h"#include "susap.h"static char *myhost = "loopback";static char *myservice = "acusaptest";static char *mycontext = "acusaptest context";static char *mypci = "acusaptest pci";/* */char *gets (), *calloc ();static int mode;#define CLIENT_MODE 0#define SERVER_MODE 1static struct QOStype qos;static struct PSAPaddr *pa;static struct PSAPaddr *cpa;static struct AEInfo clientaei;static AEI aei;static AEI pclientaei;static OID ctx;static OID pci;static struct PSAPctxlist pcs;static struct PSAPctxlist *pc = &pcs;static struct AcSAPindication acis;static struct AcSAPindication *aci = &acis;static struct AcSAPabort *aca = &acis.aci_abort;static int csd, ssd;static PE cpe;static PE spe;static struct AcuSAPstart cacs, sacs;static struct AcuSAPstart *pcacs = &cacs;static struct AcuSAPstart *psacs = &sacs;static struct type_ADD_Addends Addends;static struct type_ADD_Addends *pAddends = &Addends;static struct type_ADD_Sum Sum;static struct type_ADD_Sum *pSum = ∑void acs_adios();void acs_advise();void adios();void advise(); /* *//* ARGSUSED */int main(argc, argv, envp)int argc;char **argv, **envp;{ char buffer[80], *bptr; printf ("\n AcuSAP test driver for AUNITDATA\n"); bptr = buffer; *bptr = 'h'; while (1) { switch (toupper(*bptr)) { case 'H': printf("\n\nCommands are:\n"); printf(" T - Toggle mode (default is client)\n"); printf(" B - Bind service\n"); printf(" U - Unbind service\n"); printf(" L - Listen on a socket \n"); printf(" X - Send an AUDT request\n"); printf(" S - Send an AUDT datagram on binding\n"); printf(" R - Receive an AUDT datagram on binding\n"); printf(" V - Validate received application context/title\n"); printf(" C - Rebind to last read caller\n"); printf(" Q - Quit\n"); break; case 'Q': printf("\nAcuSAP tester terminated by user\n"); exit(0); case 'T': printf ("\n Toggle mode \n"); togglemode (); break; case 'B': bind(); break; case 'U': unbind(); break; case 'L': listenup(); break; case 'X': printf ("\n Sending AUDT datagram directly\n"); audtsendreq(); break; case 'S': printf ("\n Sending AUDT datagram on the binding\n"); audtsend(); break; case 'R': printf ("\n Reading AUDT datagram on the binding\n"); audtread(); break; case 'C': printf ("\n Rebinding to last caller\n"); audtrebind(); break; case '\0': break; /* for empty line */ default: if (*bptr != '\0') printf("** Unrecognized command\n"); break; } printf("\nCommand: "); (void)fflush(stdout); bptr = gets(buffer); if (feof (stdin)) exit (1); while (isspace(*bptr) && (*bptr != '\0')) ++bptr; }}/*-------------------------------------*/togglemode()/*-------------------------------------*/{ printf ("\n Current mode is "); if (mode == SERVER_MODE) { printf ("SERVER\n"); mode = CLIENT_MODE; printf ("\n Changing to CLIENT\n"); } else { printf ("CLIENT\n"); mode = SERVER_MODE; printf ("\n Changing to SERVER\n"); }}/*-------------------------------------*/int bind()/*-------------------------------------*/{/* set binding variables: title, presentation address, and ctxlist */ initbindvars(); { if (mode == CLIENT_MODE) { printf ("\n Binding the client side\n"); if ((csd = AcUnitDataBind (NOTOK, BIND_STATIC, ctx, NULLAEI, aei, NULLPA, pa, pc, qos, aci) ) == NOTOK ) { printf ("\n Bind unit data service failed\n"); acs_adios (aca, "A-UNIT-DATA BIND"); } else printf ("\n application bound to socket = %d \n", csd); } else /* SERVER_MODE */ { printf ("\n Binding the server side\n"); if ((ssd = AcUnitDataBind (NOTOK, BIND_DYNAMIC, ctx, aei, NULLAEI, pa, NULLPA, pc, qos, aci) ) == NOTOK ) { printf ("\n Bind unit data service failed\n"); acs_adios (aca, "A-UNIT-DATA BIND"); } else printf ("\n application bound to socket = %d \n", ssd); } } }/*-------------------------------------*/initbindvars()/*-------------------------------------*/{/* set up bind static variables for test */ if ((aei = str2aei (myhost, myservice)) == NULLAEI) adios (NULLCP, "%s-%s: unknown application-entity", myhost, myservice); if ((pa = aei2addr (aei)) == NULLPA) adios (NULLCP, "address translation failed"); printpaddr ( pa ); if ((ctx = ode2oid (mycontext)) == NULLOID) adios (NULLCP, "%s: unknown object descriptor", mycontext); if ((ctx = oid_cpy (ctx)) == NULLOID) adios (NULLCP, "out of memory"); if ((pci = ode2oid (mypci)) == NULLOID) adios (NULLCP, "%s: unknown object descriptor", mypci); if ((pci = oid_cpy (pci)) == NULLOID) adios (NULLCP, "out of memory"); pc -> pc_nctx = 1; pc -> pc_ctx[0].pc_id = 1; pc -> pc_ctx[0].pc_asn = pci; pc -> pc_ctx[0].pc_atn = NULLOID;}/*-------------------------------------*/int unbind()/*-------------------------------------*/{ if (mode == CLIENT_MODE) { printf ("\n Unbinding the client\n"); if ( AcUnitDataUnbind (csd,aci) == NOTOK ) printf ("unbind failed"); else printf ( "unbind worked"); } else { printf ("\n Unbinding the server\n"); if ( AcUnitDataUnbind (ssd,aci) == NOTOK ) printf ("unbind failed"); else printf ( "unbind worked"); }} /*-------------------------------------*/int listenup()/*-------------------------------------*/{;/* struct TSAPaddr *ta; register int n = ta -> ta_naddr - 1; register struct NSAPaddr *na = ta -> ta_addrs;static struct TSAPaddr *tz;static struct TSAPaddr tas[NTADDRS]; int port; struct NSAPaddr *tcp_na; if (mode != SERVER_MODE) printf ("failed - may only listen on socket in SERVER mode"); initbindvars();*/ /* if ((sp = getservbyname ("tsap", "tcp")) == NULL) printf ("failed - \ntcp/tsap: unknown service"); */ /* tz = tas; tcp_na = tz -> ta_addrs; tcp_na -> na_type = NA_TCP; tcp_na -> na_domain[0] = NULL; tcp_na -> na_port = sp -> s_port; tz -> ta_naddr = 1; sd = TUnitDataListen (tcp_na, NULL); if (sd == NOTOK) printf ("\n TNetListen failed\n"); else { printf ("\n listening on socket = %d \n", sd); printf ("\n port = %d \n", tcp_na -> na_port); }*/}/*-------------------------------------*/int audtsendreq()/*-------------------------------------*/{/* first set binding variables: title, presentation address, and ctxlist */ initbindvars(); { if (mode == CLIENT_MODE) { Addends.addend1 = 3; Addends.addend2 = 2; printf ("\n Client sending pair of addends directly: "); printf ("%d, %d\n", Addends.addend1, Addends.addend2); if ( encode_ADD_Addends ( &cpe, 1, 0, NULLCP, &Addends ) == NOTOK ) { printf ("\n encode failed\n"); return; } cpe->pe_context = 1; if ( AcUnitDataRequest ( ctx, NULLAEI, aei, NULLPA, pa, pc, &cpe, 1, qos, aci ) == NOTOK ) { printf ("\n AcUnitDataRequest failed\n"); acs_adios (aca, "A-UNIT-DATA REQUEST"); } else printf ("\n AUDT sent\n"); } else /* SERVER_MODE */ { printf ("\n Only supported on client side\n"); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -