/* On OSF/1 (Digital Unix), pointers are 64 bits wide; the only exception to this is C programs for which one may * specify compiler and link editor options in order to use (and allocate) 32-bit pointers. However, since C is * the only exception and, in particular because the operating system does not support such an exception, the argv * array passed to the main program is an array of 64-bit pointers. Thus the C program needs to declare argv[] * as an array of 64-bit pointers and needs to do the same for any pointer it sets to an element of argv[]. */ int main(int argc, char_ptr_t argv[]) { omi_fd fd; char buff[OMI_BUFSIZ], *bptr, *xptr, *end, *chr; int cc, blen, bunches, i, n, len, buf[5], j, rdmr; omi_vi mlen, xlen; omi_li nx; omi_si hlen; omi_req_hdr rh; DCL_THREADGBL_ACCESS; GTM_THREADGBL_INIT; bunches = 0; if (argc == 3) { if (argv[1][0] != '-' || argv[1][1] != 'b' || argv[1][2] != '\0') { PRINTF("%s: bad command line arguments\n\t%s [ -b ] filename\n", argv[0], argv[0]); exit(-1); } else if (INV_FD_P((fd = open(argv[argc - 1], O_RDONLY)))) { PRINTF("%s: open(\"%s\"): %s\n", argv[0], argv[argc - 1], STRERROR(errno)); exit(-1); } } else if (argc == 2) { if (argv[1][0] == '-' && argv[1][1] == 'b' && argv[1][2] == '\0') fd = fileno(stdin); else if (INV_FD_P((fd = open(argv[argc - 1], O_RDONLY)))) { PRINTF("%s: open(\"%s\"): %s\n", argv[0], argv[argc - 1], STRERROR(errno)); exit(-1); } } else if (argc == 1) fd = fileno(stdin); else { PRINTF("%s: bad command line arguments\n\t%s [ -b ] [ filename ]\n", argv[0], argv[0]); exit(-1); } for (blen = 0, bptr = buff, n = 1, rdmr = 1; ; ) { if (rdmr) { cc = (int)(ARRAYTOP(buff) - &bptr[blen]); if ((cc = (int)(read(fd, &bptr[blen], cc))) < 0) { PRINTF("%s: read(): %s", argv[0], STRERROR(errno)); exit(-1); } else if (cc == 0) break; blen += cc; if (blen < OMI_VI_SIZ) { if (bptr != buff) { memmove(buff, bptr, blen); bptr = buff; } continue; } } xptr = bptr; OMI_VI_READ(&mlen, xptr); if (blen < mlen.value + 4) { if (bptr != buff) { memmove(buff, bptr, blen); bptr = buff; } rdmr = 1; continue; } rdmr = 0; PRINTF("Message %d, %ld bytes", n, (long)mlen.value); if (argc == 3 && bunches) { OMI_LI_READ(&nx, xptr); PRINTF(", %d transactions in bunch", nx.value); bptr += OMI_VI_SIZ + OMI_LI_SIZ; blen -= OMI_VI_SIZ + OMI_LI_SIZ; } else { nx.value = 1; xlen = mlen; } puts(""); for (i = 1; i <= nx.value; i++) { if (argc == 3 && bunches) { OMI_VI_READ(&xlen, xptr); } end = xptr + xlen.value; OMI_SI_READ(&hlen, xptr); OMI_LI_READ(&rh.op_class, xptr); OMI_SI_READ(&rh.op_type, xptr); OMI_LI_READ(&rh.user, xptr); OMI_LI_READ(&rh.group, xptr); OMI_LI_READ(&rh.seq, xptr); OMI_LI_READ(&rh.ref, xptr); if (rh.op_class.value == 1) { PRINTF(" %s (%ld bytes)", (omi_oprlist[rh.op_type.value]) ? omi_oprlist[rh.op_type.value] : "unknown",(long)xlen.value); if (argc == 3 && bunches) PRINTF(", transaction #%d in bunch", i); puts(""); } else PRINTF(" (%ld bytes)\n", (long)xlen.value); chr = (char *)buf; while (xptr < end) { fputc('\t', stdout); if ((len = (int)(end - xptr)) > 20) len = 20; memcpy(chr, xptr, len); xptr += len; for (j = len; j < 20; j++) chr[j] = '\0'; for (j = 0; j < 5; j++) PRINTF("%08x ", buf[j]); for (j = 0; j < 20; j++) { if (j >= len) chr[j] = ' '; else if (chr[j] < 32 || chr[j] > 126) chr[j] = '.'; } PRINTF("%20s\n", chr); } bptr += xlen.value + 4; blen -= xlen.value + 4; } if (argc == 3) bunches = 1; n++; } return 0; }
/* On OSF/1 (Digital Unix), pointers are 64 bits wide; the only exception to this is C programs for which one may * specify compiler and link editor options in order to use (and allocate) 32-bit pointers. However, since C is * the only exception and, in particular because the operating system does not support such an exception, the argv * array passed to the main program is an array of 64-bit pointers. Thus the C program needs to declare argv[] * as an array of 64-bit pointers and needs to do the same for any pointer it sets to an element of argv[]. */ int main(int argc, char_ptr_t argv[]) { #ifndef __linux__ #ifdef __osf__ #pragma pointer_size (save) #pragma pointer_size (long) #endif extern char *sys_errlist[]; #ifdef __osf__ #pragma pointer_size (restore) #endif #endif omi_fd fd; char buff[OMI_BUFSIZ], *bptr, *xptr, *end, *chr; int cc, blen, bunches, i, n, len, buf[5], j, rdmr; omi_vi mlen, xlen; omi_li nx; omi_si hlen; omi_req_hdr rh; bunches = 0; if (argc == 3) { if (argv[1][0] != '-' || argv[1][1] != 'b' || argv[1][2] != '\0') { printf("%s: bad command line arguments\n\t%s [ -b ] filename\n", argv[0], argv[0]); exit(-1); } else if (INV_FD_P((fd = open(argv[argc - 1], O_RDONLY)))) { printf("%s: open(\"%s\"): %s\n", argv[0], argv[argc - 1], sys_errlist[errno]); exit(-1); } } else if (argc == 2) { if (argv[1][0] == '-' && argv[1][1] == 'b' && argv[1][2] == '\0') fd = fileno(stdin); else if (INV_FD_P((fd = open(argv[argc - 1], O_RDONLY)))) { printf("%s: open(\"%s\"): %s\n", argv[0], argv[argc - 1], sys_errlist[errno]); exit(-1); } } else if (argc == 1) fd = fileno(stdin); else { printf("%s: bad command line arguments\n\t%s [ -b ] [ filename ]\n", argv[0], argv[0]); exit(-1); } for (blen = 0, bptr = buff, n = 1, rdmr = 1; ; ) { if (rdmr) { cc = &buff[sizeof(buff)] - &bptr[blen]; if ((cc = read(fd, &bptr[blen], cc)) < 0) { printf("%s: read(): %s", argv[0], sys_errlist[errno]); exit(-1); } else if (cc == 0) break; blen += cc; if (blen < OMI_VI_SIZ) { if (bptr != buff) { memmove(buff, bptr, blen); bptr = buff; } continue; } } xptr = bptr; OMI_VI_READ(&mlen, xptr); if (blen < mlen.value + 4) { if (bptr != buff) { memmove(buff, bptr, blen); bptr = buff; } rdmr = 1; continue; } rdmr = 0; printf("Message %d, %d bytes", n, mlen.value); if (argc == 3 && bunches) { OMI_LI_READ(&nx, xptr); printf(", %d transactions in bunch", nx.value); bptr += OMI_VI_SIZ + OMI_LI_SIZ; blen -= OMI_VI_SIZ + OMI_LI_SIZ; } else { nx.value = 1; xlen = mlen; } puts(""); for (i = 1; i <= nx.value; i++) { if (argc == 3 && bunches) { OMI_VI_READ(&xlen, xptr); } end = xptr + xlen.value; OMI_SI_READ(&hlen, xptr); OMI_LI_READ(&rh.op_class, xptr); OMI_SI_READ(&rh.op_type, xptr); OMI_LI_READ(&rh.user, xptr); OMI_LI_READ(&rh.group, xptr); OMI_LI_READ(&rh.seq, xptr); OMI_LI_READ(&rh.ref, xptr); if (rh.op_class.value == 1) { printf(" %s (%d bytes)", (omi_oprlist[rh.op_type.value]) ? omi_oprlist[rh.op_type.value] : "unknown",xlen.value); if (argc == 3 && bunches) printf(", transaction #%d in bunch", i); puts(""); } else printf(" (%d bytes)\n", xlen.value); chr = (char *)buf; while (xptr < end) { fputc('\t', stdout); if ((len = end - xptr) > 20) len = 20; memcpy(chr, xptr, len); xptr += len; for (j = len; j < 20; j++) chr[j] = '\0'; for (j = 0; j < 5; j++) printf("%08x ", buf[j]); for (j = 0; j < 20; j++) { if (j >= len) chr[j] = ' '; else if (chr[j] < 32 || chr[j] > 126) chr[j] = '.'; } printf("%20s\n", chr); } bptr += xlen.value + 4; blen -= xlen.value + 4; } if (argc == 3) bunches = 1; n++; } return 0; }
int gtcm_cn_acpt(omi_conn_ll *cll, int now) /* now --> current time in seconds */ { int i; omi_conn *cptr; omi_fd fd; int rc; char *tmp_time; #ifdef BSD_TCP GTM_SOCKLEN_TYPE sln; struct sockaddr_storage sas; int optsize; const boolean_t keepalive = TRUE; /* Accept the connection from the network layer */ sln = SIZEOF(sas); if ((fd = accept(cll->nve, (struct sockaddr *)&sas, (GTM_SOCKLEN_TYPE *)&sln)) < 0) return -1; #endif /* defined(BSD_TCP) */ /* Build the client data structure */ if (!(cptr = (omi_conn *)malloc(SIZEOF(omi_conn))) || !(cptr->buff = (char *)malloc(OMI_BUFSIZ))) { if (cptr) free(cptr); CLOSEFILE_RESET(fd, rc); /* resets "fd" to FD_INVALID */ return -1; } /* Initialize the connection structure */ cptr->next = (omi_conn *)0; cptr->fd = fd; cptr->ping_cnt = 0; cptr->timeout = now + conn_timeout; cptr->bsiz = OMI_BUFSIZ; cptr->bptr = cptr->buff; cptr->xptr = (char *)0; cptr->blen = 0; cptr->exts = 0; cptr->state = OMI_ST_DISC; cptr->ga = (ga_struct *)0; /* struct gd_addr_struct */ cptr->of = (oof_struct *) malloc(SIZEOF(struct rc_oflow)); memset(cptr->of, 0, SIZEOF(struct rc_oflow)); cptr->pklog = FD_INVALID; /* Initialize the statistics */ memcpy(&cptr->stats.sas, &sas, sln); cptr->stats.ai.ai_addr = (struct sockaddr *)&cptr->stats.sas; cptr->stats.ai.ai_addrlen = sln; cptr->stats.bytes_recv = 0; cptr->stats.bytes_send = 0; cptr->stats.start = time((time_t *)0); for (i = 0; i < OMI_OP_MAX; i++) cptr->stats.xact[i] = 0; for (i = 0; i < OMI_ER_MAX; i++) cptr->stats.errs[i] = 0; /* if we only allowing one connection per internet address, close any existing ones with the same addr. */ if (one_conn_per_inaddr) { omi_conn *this, *prev; for (prev = NULL, this = cll->head; this; prev = this, this = this->next) { if (0 == memcmp((sockaddr_ptr)(&this->stats.sas), (sockaddr_ptr)&sas, sln)) { if (cll->tail == this) cll->tail = cptr; if (prev) prev->next = cptr; else cll->head = cptr; cptr->next = this->next; OMI_DBG_STMP; OMI_DBG((omi_debug, "%s: dropping old connection to %s\n", SRVR_NAME, gtcm_hname(&cptr->stats.ai))); gtcm_cn_disc(this, cll); break; } } /* not found - add to the end of the list */ if (!this) { if (cll->tail) { cll->tail->next = cptr; cll->tail = cptr; } else cll->head = cll->tail = cptr; } } else { /* Insert the client into the list of connections */ if (cll->tail) { cll->tail->next = cptr; cll->tail = cptr; } else cll->head = cll->tail = cptr; } cptr->stats.id = ++cll->stats.conn; DEBUG_ONLY( if (omi_pklog) { int errno_save; char pklog[1024]; (void)SPRINTF(pklog, "%s.%04d", omi_pklog, cptr->stats.id); if (INV_FD_P((cptr->pklog = OPEN3(pklog, O_WRONLY|O_CREAT|O_APPEND|O_TRUNC, 0644)))) { errno_save = errno; OMI_DBG_STMP; OMI_DBG((omi_debug, "%s: unable to open packet log \"%s\"\n\t%s\n", SRVR_NAME, pklog, STRERROR(errno_save))); } } )
/* On OSF/1 (Digital Unix), pointers are 64 bits wide; the only exception to this is C programs for which one may * specify compiler and link editor options in order to use (and allocate) 32-bit pointers. However, since C is * the only exception and, in particular because the operating system does not support such an exception, the argv * array passed to the main program is an array of 64-bit pointers. Thus the C program needs to declare argv[] * as an array of 64-bit pointers and needs to do the same for any pointer it sets to an element of argv[]. */ int main(int argc, char_ptr_t argv[]) { omi_conn *cptr, conn; int i; char buff[OMI_BUFSIZ]; DCL_THREADGBL_ACCESS; GTM_THREADGBL_INIT; set_blocksig(); gtm_env_init(); /* read in all environment variables before calling any function particularly malloc (from err_init below)*/ /* Open the packet log file for playback */ if (argc == 1) conn.fd = fileno(stdin); else if (argc == 2) { if (INV_FD_P((conn.fd = open(argv[argc - 1], O_RDONLY)))) { PRINTF("%s: open(\"%s\"): %s\n", argv[0], argv[argc - 1], STRERROR(errno)); exit(-1); } } else { PRINTF("%s: bad command line arguments\n\t%s [ filename ]\n", argv[0], argv[0]); exit(-1); } /* Initialize everything but the network */ err_init(gtcm_exit_ch); omi_errno = OMI_ER_NO_ERROR; ESTABLISH_RET(omi_dbms_ch, -1); /* any return value to signify error return */ gtcm_init(argc, argv); #ifdef GTCM_RC rc_create_cpt(); #endif REVERT; if (omi_errno != OMI_ER_NO_ERROR) exit(omi_errno); /* Initialize the connection structure */ conn.next = (omi_conn *)0; conn.bsiz = OMI_BUFSIZ; conn.bptr = conn.buff = buff; conn.xptr = (char *)0; conn.blen = 0; conn.exts = 0; conn.state = OMI_ST_DISC; conn.ga = (ga_struct *)0; /* struct gd_addr_struct */ conn.of = (oof_struct *)0; /* struct rc_oflow */ conn.pklog = FD_INVALID; /* Initialize the statistics */ conn.stats.bytes_recv = 0; conn.stats.bytes_send = 0; conn.stats.start = time((time_t *)0); for (i = 0; i < OMI_OP_MAX; i++) conn.stats.xact[i] = 0; for (i = 0; i < OMI_ER_MAX; i++) conn.stats.errs[i] = 0; for (;;) if (omi_srvc_xact(&conn) < 0) break; PRINTF("%ld seconds connect time\n", time((time_t)0) - conn.stats.start); PRINTF("%d OMI transactions\n", omi_nxact); PRINTF("%d OMI errors\n", omi_nerrs); #ifdef GTCM_RC PRINTF("%d RC transactions\n", rc_nxact); PRINTF("%d RC errors\n", rc_nerrs); #endif /* defined(GTCM_RC) */ PRINTF("%d bytes recv'd\n", conn.stats.bytes_recv); PRINTF("%d bytes sent\n", conn.stats.bytes_send); gtcm_exit(); return 0; }