$create socket_scan.cob identification division. program-id. socket_scan with ident "V1.0". author. Richard Maher All Rights Reserved. * data division. working-storage section. 01 ucx$c_stream pic s9(9) comp value external ucx$c_stream. 01 ucb$m_template pic s9(9) comp value external ucb$m_template. 01 io$_sensemode pic s9(9) comp value external io$_sensemode. 01 ss$_devalloc pic s9(9) comp value external ss$_devalloc. 01 ss$_badparam pic s9(9) comp value external ss$_badparam. 01 ss$_nosuchdev pic s9(9) comp value external ss$_nosuchdev. 01 ss$_nomoredev pic s9(9) comp value external ss$_nomoredev. 01 ss$_nolinks pic s9(9) comp value external ss$_nolinks. 01 ss$_normal pic s9(9) comp value external ss$_normal. 01 sys_status pic s9(9) comp global. * 01 out_devnam pic x(64) global. 01 out_devnam_len pic 9(4) comp global. * 01 lookup_chan pic s9(4) comp external. * 01 dvi_item_list. 03 item_devbufsiz. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_devbufsiz. 05 pointer value reference dev_bufsiz. 05 pic s9(9) comp. 03 item_optcnt. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_opcnt. 05 pointer value reference dev_opcnt. 05 pic s9(9) comp. 03 item_ownuic. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_ownuic. 05 pointer value reference dev_ownuic. 05 pic s9(9) comp. 03 item_pid. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_pid. 05 pointer value reference dev_pid. 05 pic s9(9) comp. 03 item_refcnt. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_refcnt. 05 pointer value reference dev_refcnt. 05 pic s9(9) comp. 03 item_sts. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_sts. 05 pointer value reference dev_sts. 05 pic s9(9) comp. 03 item_unit. 05 pic s9(4) comp value 4. 05 pic s9(4) comp value external dvi$_unit. 05 pointer value reference dev_unit. 05 pic s9(9) comp. 03 pic s9(9) comp. * 01 dev_bufsiz pic s9(9) comp. 01 dev_opcnt pic s9(9) comp. 01 dev_ownuic pic s9(9) comp. 01 dev_pid pic s9(9) comp. 01 dev_refcnt pic s9(9) comp. 01 dev_sts pic s9(9) comp. 01 dev_unit pic s9(9) comp. * 01 dvi_iosb. 03 dvi_status pic s9(9) comp. 03 pic s9(9) comp. * 01 dvifao_ctrl. 03 pic x(24) value "Socket: !AS!_Type: !AS!/". 03 pic x(26) value "!_Owner PID !XL UIC !%I !/". 03 pic x(48) value "!_Reference Count !ZL Operations Completed !ZL!/". 03 pic x(27) value "!_Default Buffer Size !ZL!/". 01 dvifao_out pic x(256). 01 dvifao_out_len pic s9(4) comp. * 01 buffao_ctrl. 03 pic x(51) value "!/!_Buffer Quota -!_Send: !ZL Recv: !ZL MaxSeg: !ZL". 03 pic x(36) value "!/!_!_!_Not read: !ZL At OOB: !ZL!/". 03 pic x(11) value "!/!_Flags: ". 01 buffao_out pic x(256). 01 buffao_out_len pic s9(4) comp. * 01 iosb. 03 cond_val pic s9(4) comp. 03 pic x(6). * 01 bg_chan pic s9(4) comp. 01 ioctl_list. 03 pic s9(4) comp value 16. 03 pic s9(4) comp value external ucx$c_ioctl. 03 pointer value reference ioctl_data. 01 ioctl_data. 03 pic s9(9) comp value external siocatmark. 03 pointer value reference at_oob. 03 pic s9(9) comp value external fionread. 03 pointer value reference unread_cnt. * 01 unread_cnt pic 9(9) comp. 01 at_oob pic 9(9) comp. * 01 sockopt_list. 03 pic s9(4) comp value 72. 03 pic s9(4) comp value external ucx$c_sockopt. 03 pointer value reference sockopt_data. * 01 sockopt_data. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_type. 03 pointer value reference socket_type. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_sndbuf. 03 pointer value reference sndbuf. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_rcvbuf. 03 pointer value reference rcvbuf. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_oobinline. 03 pointer value reference oobinline. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_keepalive. 03 pointer value reference keepalive. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_reuseaddr. 03 pointer value reference reuseaddr. 03 pointer value reference who_cares. * 01 keepalive pic 9(9) comp. 01 reuseaddr pic 9(9) comp. 01 sndbuf pic 9(9) comp. 01 rcvbuf pic 9(9) comp. 01 oobinline pic 9(9) comp. 01 socket_type pic 9(9) comp. 01 who_cares pic 9(9) comp. * 01 socket_type_table. 03 pic x(6) value "STREAM". 03 pic x(6) value "DGRAM". 03 pic x(6) value "RAW". 01 socket_type_array redefines socket_type_table. 03 socket_type_name pic x(6) occurs 3. * 01 tcpopt_list. 03 pic s9(4) comp value 24. 03 pic s9(4) comp value external ucx$c_tcpopt. 03 pointer value reference tcpopt_data. * 01 tcpopt_data. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_tcp_maxseg. 03 pointer value reference maxseg. 03 pointer value reference who_cares. 03 pic s9(4) comp value 4. 03 pic s9(4) comp value external ucx$c_tcp_nodelay. 03 pointer value reference nodelay. 03 pointer value reference who_cares. * 01 maxseg pic 9(9) comp. 01 nodelay pic 9(9) comp. * 01 rem_sock_desc. 03 pic s9(9) comp value 16. 03 pointer value reference rem_sock_name. 03 pointer value reference rsn_len. * 01 rem_sock_name. 03 addr_dom pic s9(4) comp. 03 port_number. 05 high_byte pic x. 05 low_byte pic x. 03 host_addr. 05 ra1 pic x. 05 ra2 pic x. 05 ra3 pic x. 05 ra4 pic x. 03 pic x(8). * 01 rsn_len pic s9(9) comp. * 01 lcl_sock_desc. 03 pic s9(9) comp value 16. 03 pointer value reference lcl_sock_name. 03 pointer value reference lsn_len. * 01 lcl_sock_name. 03 addr_dom pic s9(4) comp. 03 port_number. 05 high_byte pic x. 05 low_byte pic x. 03 host_addr. 05 la1 pic x. 05 la2 pic x. 05 la3 pic x. 05 la4 pic x. 03 pic x(8). * 01 lsn_len pic s9(9) comp. * 01 and_bits pic 9(9) comp. * 01 out_socket pic x(256). 01 out_socket_len pic s9(4) comp. * procedure division. kick_off section. 00. call "sys$assign" using by descriptor "BG:" by reference lookup_chan by value 0, 0, 0 giving sys_status. if sys_status = ss$_nosuchdev display "TCP/IP not available" go to fini. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. call "fetch_bg". perform until sys_status not = ss$_normal perform dump_socket call "fetch_bg" end-perform. if sys_status not = ss$_nomoredev call "lib$stop" using by value sys_status. call "sys$dassgn" using by value lookup_chan giving sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. * fini. stop run. * dump_socket section. 00. call "sys$getdviw" using by value 0, 0 by descriptor out_devnam(1:out_devnam_len) by reference dvi_item_list, dvi_iosb by value 0, 0, 0 giving sys_status. if sys_status = ss$_normal move dvi_status to sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. call "mth$jiand" using dev_sts, ucb$m_template giving and_bits. if and_bits = ucb$m_template or dev_unit = zeros go to fini. call "sys$assign" using by descriptor out_devnam(1:out_devnam_len) by reference bg_chan by value 0, 0, 0 giving sys_status. if sys_status = ss$_nosuchdev go to fini. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. call "sys$qiow" using by value 0, bg_chan, io$_sensemode by reference iosb by value 0, 0, 0, 0 by reference lcl_sock_desc, rem_sock_desc, omitted, ioctl_list giving sys_status if sys_status = ss$_normal move cond_val to sys_status. evaluate sys_status when ss$_normal continue when ss$_nolinks move low-values to rem_sock_name when ss$_badparam go to fini when other call "lib$stop" using by value sys_status end-evaluate. call "sys$qiow" using by value 0, bg_chan, io$_sensemode by reference iosb by value 0, 0, 0, 0, 0, 0, 0 by reference sockopt_list giving sys_status if sys_status = ss$_normal move cond_val to sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. move zeros to maxseg, nodelay. if socket_type = ucx$c_stream call "sys$qiow" using by value 0, bg_chan, io$_sensemode by reference iosb by value 0, 0, 0, 0, 0, 0, 0 by reference tcpopt_list giving sys_status if sys_status = ss$_normal move cond_val to sys_status end-if if sys_status not = ss$_normal call "lib$stop" using by value sys_status. call "sys$fao" using by descriptor dvifao_ctrl by reference dvifao_out_len by descriptor dvifao_out, out_devnam(1:out_devnam_len), socket_type_name(socket_type) by value dev_pid, dev_ownuic, dev_refcnt, dev_opcnt, dev_bufsiz giving sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. display dvifao_out(1:dvifao_out_len). call "format_host_port" using lcl_sock_name, "Local :", out_socket, out_socket_len. display out_socket(1:out_socket_len). if rem_sock_name not = low-values call "format_host_port" using rem_sock_name, "Remote:", out_socket, out_socket_len display out_socket(1:out_socket_len). call "sys$fao" using by descriptor buffao_ctrl by reference buffao_out_len by descriptor buffao_out by value sndbuf, rcvbuf, maxseg, unread_cnt, at_oob giving sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. display buffao_out(1:buffao_out_len) no advancing. if keepalive not = zeros display "Keepalive " no advancing. if reuseaddr not = zeros display "Reuseaddr " no advancing. if oobinline not = zeros display "OOBinline " no advancing. if nodelay not = zeros display "NoDelay " no advancing. display "". display "". * fini. if bg_chan not = zeros call "sys$dassgn" using by value bg_chan giving sys_status if sys_status not = ss$_normal call "lib$stop" using by value sys_status end-if move zeros to bg_chan. * identification division. program-id. fetch_bg is common. data division. working-storage section. 01 scan_ctx pic s9(18) comp. procedure division. 00. call "sys$device_scan" using by descriptor out_devnam by reference out_devnam_len by descriptor "_BG*" by value 0 by reference scan_ctx giving sys_status. * exit program. * end program fetch_bg. end program socket_scan. identification division. program-id. format_host_port. data division. working-storage section. 01 io$_acpcontrol pic s9(9) comp value external io$_acpcontrol. 01 acp_cmd pic s9(9) comp value external acp_cmd. 01 ss$_endoffile pic s9(9) comp value external ss$_endoffile. 01 ss$_bufferovf pic s9(9) comp value external ss$_bufferovf. 01 ss$_normal pic s9(9) comp value external ss$_normal. 01 sys_status pic s9(9) comp. * 01 lookup_chan pic s9(4) comp external. * 01 iosb. 03 cond_val pic s9(4) comp. 03 pic x(6). * 01 port_swap. 03 low_byte pic x. 03 high_byte pic x. 03 pic 9(4) comp. 01 port_swap_bin redefines port_swap pic 9(9) comp. * 01 node_name pic x(64). 01 node_name_len pic s9(4) comp. 01 socketfao_ctrl pic x(35) value "!_!AS !@UB.!@UB.!@UB.!@UB:!ZL (!AS)". * linkage section. 01 socket_name. 03 addr_dom pic s9(4) comp. 03 port_number. 05 high_byte pic x. 05 low_byte pic x. 03 host_addr. 05 la1 pic x. 05 la2 pic x. 05 la3 pic x. 05 la4 pic x. 03 pic x(8). 01 socket_source pic x(7). 01 out_socket pic x(256). 01 out_socket_len pic s9(4) comp. * procedure division using socket_name, socket_source, out_socket, out_socket_len. 00. move corr port_number to port_swap. if host_addr = low-values move zeros to node_name_len else call "sys$qiow" using by value 0, lookup_chan, io$_acpcontrol by reference iosb by value 0, 0 by descriptor acp_cmd, host_addr by reference node_name_len by descriptor node_name by value 0, 0 giving sys_status if sys_status = ss$_normal move cond_val to sys_status end-if evaluate sys_status when ss$_bufferovf when ss$_normal continue when ss$_endoffile move "Unknown Node" to node_name move 12 to node_name_len when other call "lib$stop" using by value sys_status end-evaluate if node_name_len > 64 move 64 to node_name_len. * call "sys$fao" using by descriptor socketfao_ctrl by reference out_socket_len by descriptor out_socket, socket_source by reference la1, la2, la3, la4 by value port_swap_bin by descriptor node_name(1:node_name_len) giving sys_status. if sys_status not = ss$_normal call "lib$stop" using by value sys_status. * exit program. * end program format_host_port. $! $cob/lis socket_scan.cob $create socket_scan_def.mar .ident "V1.0" .library /sys$library:lib.mlb/ ;+ ; $library/create/macro inet.mlb sys$library:ucx$inetdef ;- .library /inet/ $inetsymdef GLOBAL $siocdef GLOBAL $inetacpfsymdef GLOBAL $inetacpsymdef GLOBAL $ineterrdef GLOBAL $psldef GLOBAL $ucbdef GLOBAL acp_cmd == .end $! $mac/lis socket_scan_def.mar $link socket_scan,socket_scan_def $set proc/priv=share $run socket_scan $exit