void gtcm_pktdmp(char *ptr, int length, char *msg) { char *end; char *chr; int buf[5]; int len; int j; int offset = 0; static int fileID = 0; char tbuf[16]; char fileName[256]; time_t ctim; struct tm *ltime; FILE *fp; char *gtm_dist; ctim = time(0); GTM_LOCALTIME(ltime, &ctim); SPRINTF(tbuf, "%02d%02d%02d%02d",ltime->tm_mon + 1,ltime->tm_mday, ltime->tm_hour,ltime->tm_min); if (gtm_dist=getenv("gtm_dist")) { char subdir[256]; struct stat buf; /* check for the subdirectory $gtm_dist/log/<omi_service> * If the subdirectory exists, place the log file there. * Otherwise...place the file in $gtm_dist/log. */ SPRINTF(subdir,"%s/log/%s", gtm_dist, omi_service); if (stat(subdir,&buf) == 0 && S_ISDIR(buf.st_mode)) { SPRINTF(fileName,"%s/%s_%s.%d", subdir, omi_service, tbuf, fileID++); } else { SPRINTF(fileName,"%s/log/%s_%s.%d", gtm_dist, omi_service, tbuf, fileID++); } } else SPRINTF(fileName,"/usr/tmp/%s_%s.%d", omi_service, tbuf, fileID++); #ifdef __MVS__ if (-1 == gtm_zos_create_tagged_file(fileName, TAG_EBCDIC)) { FPRINTF(stderr,"Could not create and tag new packet dump file (%s).\n", fileName); perror(fileName); } #endif fp = fopen(fileName, "w"); if (fp == NULL) { FPRINTF(stderr,"Could not open packet dump file (%s).\n", fileName); perror(fileName); return; } OMI_DBG((omi_debug, "%s\n", msg)); OMI_DBG((omi_debug, "Log dumped to %s.\n", fileName)); FPRINTF(fp,"%s\n", msg); buf[4] = '\0'; end = ptr + length; chr = (char *)buf; while (ptr < end) { fputc('\t', fp); if ((len = (int)(end - ptr)) > 16) len = 16; memcpy(chr, ptr, len); ptr += len; offset += len; for (j = len; j < 16; j++) chr[j] = '\0'; for (j = 0; j < 4; j++) FPRINTF(fp,"%08x ", buf[j]); for (j = 0; j < 16; j++) if (j >= len) chr[j] = ' '; else if (chr[j] < 32 || chr[j] > 126) chr[j] = '.'; FPRINTF(fp,"%16s %x\n", chr, offset); } FFLUSH(fp); fclose(fp); }
/* 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 gtcm_prsopt(int argc, char_ptr_t argv[]) { enum opt_enum opt; int i,j, t; boolean_t inv_option = FALSE; for (i = 1, argv++; i < argc; argv += optlist[j].args + 1, i += optlist[j].args + 1) { for(j = 0; opt = optlist[j].option; j++) if (!strcmp(*argv,optlist[j].name)) break; if (i + optlist[j].args >= argc) { FPRINTF(stderr, "%s option requires an argument - ignored\n", *argv); continue; } switch(opt) { case opt_debug: if ((*(argv + 1))[0] == '-' && (*(argv + 1))[1] == '\0') omi_debug = stdout; else if ((*(argv + 1))[0] == '=' && (*(argv + 1))[1] == '\0') omi_debug = stderr; else { #ifdef __MVS__ if (-1 == gtm_zos_create_tagged_file(*(argv + 1), TAG_EBCDIC)) perror("error tagging log file"); #endif Fopen(omi_debug, *(argv + 1), "w+"); if (!omi_debug) { perror("error opening log file"); EXIT(1); } } break; case opt_pktlog: omi_pklog = *(argv + 1); break; case opt_service: omi_service = *(argv + 1); break; case opt_rc_id: rc_server_id = atoi(*(argv + 1)); break; case opt_pktlog_addr: omi_pklog_addr = *(argv + 1); break; case opt_authenticate: authenticate = 1; break; case opt_multipleconn: one_conn_per_inaddr = 0; break; case opt_ping: ping_keepalive = 1; break; case opt_null: inv_option = TRUE; FPRINTF(stderr,"Unknown option: %s\n",*argv); break; case opt_conn_timeout: t = atoi(*(argv + 1)); if (t < MIN_TIMEOUT_INTERVAL) FPRINTF(stderr,"-timeout parameter must be >= %d seconds. The default value %d seconds will be used\n" , MIN_TIMEOUT_INTERVAL, TIMEOUT_INTERVAL); else conn_timeout = t; break; case opt_servtime: t = atoi(*(argv + 1)); if (t < MIN_TIMEOUT_INTERVAL) FPRINTF(stderr, "-servtime parameter must be >= %d seconds. The default value %d seconds will be used\n", MIN_TIMEOUT_INTERVAL, MIN_TIMEOUT_INTERVAL); else per_conn_servtime = t; break; case opt_history: history = 1; break; default: inv_option = TRUE; FPRINTF(stderr,"Unsupported option: %s\n",*argv); break; } if (inv_option) return -1; } return 0; }