/* * XX_SUPPORT.H * * Copyright 2019 VMS Software, Inc. * * Contains VMS specific definitions and XX common definitions. * * To use, include this code: * * #include "xx_support.h" * * And build * cc xx+xx_support+sys$library:sys$lib_c.tlb/lib * * And during program initialization: * * xx$common_args(argc, argv); * xx$init(); */ #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include "nmadef.h" #define DEBUG_CERR 1 #ifndef SS$_FAIL #define SS$_FAIL 0 #endif #ifndef SS$_NORMAL #define SS$_NORMAL 1 #endif #ifndef STS$M_SUCCESS #define STS$M_SUCCESS 1 #endif #define $FAIL(sts) (((sts) & STS$M_SUCCESS) != SS$_NORMAL) #define $SUCCESS(sts) (((sts) & STS$M_SUCCESS) == SS$_NORMAL) typedef __unaligned short * UNALIGNED_SHORTP; #define TRUE 1 #define FALSE 0 $DESCRIPTOR(sysoutput,"SYS$OUTPUT"); /* Terminal output device name */ uint32 tt_chan = 0; /* Terminal channel */ uint32 controlt_mask[2] = {0,0x100000}; /* Mask to enable Control-T */ uint32 nobroadcast_mask[2] = {0x40,0}; /* Mask to disable broadcast of Control-T */ uint32 broadcast_mask[2] = {0,0}; /* Mask to enable broadcast of Control-T */ /* Statistics context */ #define HDR_INTERVAL 10 uint64_t interval_usec, total_usec, total_sec; int override_interval_flag = FALSE; /* Test flags */ int compare_flag = FALSE; int verbose_flag = FALSE; int swap_flag = FALSE; int rand_flag = FALSE; int discard_flag = FALSE; int force_cerr_flag = FALSE; /* Display context */ #define DATE_START 11 #define DATE_END 19 int echo_size = 65536; /* Amount of data to echo */ int echo_num = 0; /* Number of packets to echo */ int nprint = 0; /* Number of stats lines printed */ char pline[256]; struct FAB log_fab; /* Log file FAB */ struct RAB log_rab; /* Log file RAB */ char log_prefix[16]; /* Log file prefix */ char log_name[256]; /* Log file name */ char log_line[512]; /* Log output line */ int log_flag; /* Log file valid flag */ /* Time context */ time_t cur_time, stat_time, end_time, rcv_time, tmp_time; char *cur_time_str; struct timeval begin_stats_time, last_stats_time, cur_stats_time; int test_duration = 0x7FFFFFFF; int stats_interval = 10; /* Stats display interval (seconds) */ /* Miscellaneous */ char is_initiator = FALSE, is_target = TRUE; char nodename[32]; #define COMMON_ARGS "b:cde:f:hi:m:n:o:rsu:vw:z:" /* Unused letters are agjklpqtxy */ /* Byte swap macros */ #define bswp16(w) (((w&0xff)<<8) | ((w>>8)&0xff)) #define bswp32(l) ((bswp16(l) << 16) | (bswp16(l >> 16))) /* Define IOSB structure */ typedef struct __iosb { short w_err; /* Completion status */ short w_xfer_size; /* Transfer size */ short w_addl; /* Additional status */ short w_misc; /* Miscellaneous */ } IOSB; /* Define item lists */ struct item_entry { /* Item list entry */ short buflen; /* Supplied buffer length */ short code; /* Item code */ char *bufadr; /* Buffer address */ int *lenadr; /* Returned buffer length */ }; typedef struct dev_item { /* Device scan itemlist buffer */ uint16 bufflen; uint16 itemcode; uint32 buffaddr; uint32 retlenaddr; } DEV_ITEM; /* Control-T handlers */ void xx$ctrl_t_cancel (); void xx$ctrl_t_handle (); /* Packet/message length macros */ #define GEN_PKT_LEN \ do { \ if (rand_flag) \ do pkt_len = (((pkt_len - PKT_MIN) * 69069) & pkt_mod) + PKT_MIN; \ while ((pkt_len > pkt_max) || (pkt_len < PKT_MIN)); \ } while (0) #define GEN_MSG_LEN \ do { \ if (rand_flag) { \ do msg_len = (((msg_len - MSG_MIN) * 69069) & msg_mod) + MSG_MIN; \ while ((msg_len > msg_max) || (msg_len < MSG_MIN)); \ } \ } while (0) /* Burst time context */ int burst_num = 1, burst_max, burst_mod; int rand_burst_flag = FALSE; #define GEN_BURST \ do { \ if (rand_burst_flag) \ do burst_num = (((burst_num) * 69069) & burst_mod); \ while ((burst_num > burst_max) || (burst_num < 1)); \ } while (0) /* Forward declarations */ void print_line (char *line, char *logline); void print_vline (char *pline); void pk_dump (char *what, uint32_t *pk, int pkt_len); void pk_dump_packet (uint32_t *pk, int dump_len); uint64_t get_delta (struct timeval *cur_time, struct timeval *last_time); void cvt_value (uint64_t val, char *val_str); void cvt_value_short (uint64_t val, char *val_str); void xx$get_sys_name (); void xx$init (); void xx$common_args (int argc, char *argv[], char *program_args);