-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathzshow_gwmon_log.prog.abap
799 lines (675 loc) · 22.8 KB
/
zshow_gwmon_log.prog.abap
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
*&---------------------------------------------------------------------*
*& Report ZSHOW_GWMON_LOG
*& Show settings, log and trace files of the RFC gateway
*&---------------------------------------------------------------------*
*& Author: Frank Buchholz, SAP CoE Security Services
*& Source: https://github.com/SAP-samples/security-services-tools
*&
*& 31.01.2023 Validate NI addresses and show network buffer
*& 27.01.2023 Initial version
*&
*& Limitation: Only daily logfiles are supported
*&---------------------------------------------------------------------*
REPORT zshow_gwmon_log
MESSAGE-ID gw
LINE-SIZE 255.
CONSTANTS: c_program_version(30) TYPE c VALUE '31.01.2023 FBT'.
SELECTION-SCREEN BEGIN OF BLOCK sel WITH FRAME TITLE text001.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_par AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN COMMENT 3(30) p_par FOR FIELD show_par.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_sec AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN COMMENT 3(30) p_sec FOR FIELD show_sec.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_reg AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN COMMENT 3(30) p_reg FOR FIELD show_reg.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_prx AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN COMMENT 3(30) p_prx FOR FIELD show_prx.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_buf AS CHECKBOX DEFAULT ' '.
SELECTION-SCREEN COMMENT 3(30) p_buf FOR FIELD show_buf.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_log AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(30) p_log FOR FIELD show_log.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
PARAMETERS show_trc AS CHECKBOX DEFAULT 'X'.
SELECTION-SCREEN COMMENT 3(30) p_trc FOR FIELD show_trc.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK sel.
SELECTION-SCREEN BEGIN OF BLOCK rng WITH FRAME TITLE text002.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) p_from FOR FIELD fromdate.
PARAMETERS fromdate TYPE sy-datum.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN BEGIN OF LINE.
SELECTION-SCREEN COMMENT 1(31) p_to FOR FIELD todate.
PARAMETERS todate TYPE sy-datum.
SELECTION-SCREEN END OF LINE.
SELECTION-SCREEN END OF BLOCK rng.
SELECTION-SCREEN COMMENT /1(60) ss_vers.
INITIALIZATION.
text001 = 'Choose output'(000).
p_par = 'Show profile parameters'(001).
p_sec = 'Show secinfo'(002).
p_reg = 'Show reginfo'(003).
p_prx = 'Show prxinfo'(004).
p_buf = 'Show network buffer'(027).
p_log = 'Show log files'(005).
p_trc = 'Show trace files'(006).
text002 = 'Date range to select log and trace entries'(007).
p_from = 'From date'(008).
p_to = 'To date'(009).
CONCATENATE 'Program version:'(VER) c_program_version INTO ss_vers
SEPARATED BY space.
fromdate = sy-datum - 7.
todate = sy-datum.
START-OF-SELECTION.
" Class CL_GW_MON
" FLUSH_LOGFILE Write Data to Log File
" GET_ACL_FILE_DETAILS Displays information about ACL file
" GET_ADM Make Data from GW Administration Available
" GET_CONN_ATTR Display Information About a Specific Connection
" GET_CONN_PARTNER Display Information About a Specific Connection Partner
" GET_CONN_TABLE Display Gateway Connection Table
" GET_CONN_TABLE_DETAILS Display an Entry from the Connection Table
" GET_CONV_INFO Display Information About a Specific Conversation
" GET_CVID_TABLE_DETAILS Display CVID Table
" GET_EXT_TABLE List of External Programs
" GET_GLOBAL Gets the value
" GET_NIBUFFER_DETAILS Displays the NI buffer
" GET_OWN_IPADR Displays your own IP address
" GET_PROGRAM_DETAILS Displays program details
" GET_REGISTRATION_INFO Informationen About Regsitrations
" GET_REGLOAD_TABLE Displays the Reload table
" GET_REG_TABLE List of Registered RFC Server Programs
" GET_RELINFO Displays information about the release
" GET_REMGW_TABLE List of Remote Gateways
" GET_REMGW_TABLE_DETAILS Displays the remote system table
" GET_RFC_ERRORTEXT Gets the RFC error text
" GET_SERVER_NAME Returns name of active server
" GET_STATISTIC_DETAILS Displays statistical information
" GET_SYS_TABLE Displays Gateway System Table
" GET_SYS_TABLE_DETAILS Displays System Table
" GET_SYS_TABLE_INTERNAL Displays System Table
" GET_TEST Getter for Variable mv_test
" GET_TRACE Getter for Variable mv_trace
" GET_TRUSTED_IPADR Displays the trusted IP address
" GET_TRUST_INFO Gets list of IP addresses and port numbers
" READ_STATISTIC Read Gateway Statistics
" READ_TRACE_FILE Read Trace File
DATA subrc TYPE syst-subrc.
DATA line TYPE gw_line.
DATA lo_gwmon TYPE REF TO cl_gw_mon.
CREATE OBJECT lo_gwmon.
IF lo_gwmon->auth_check( ) NE 0.
MESSAGE e032.
ENDIF.
DATA sim_mode TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/sim_mode' ##NO_TEXT
IMPORTING ev_value = sim_mode ).
DATA acl_mode TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/acl_mode' ##NO_TEXT
IMPORTING ev_value = acl_mode ).
DATA reg_no_conn_info TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/reg_no_conn_info' ##NO_TEXT
IMPORTING ev_value = reg_no_conn_info ).
DATA sec_info TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/sec_info' ##NO_TEXT
IMPORTING ev_value = sec_info ).
DATA reg_info TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/reg_info' ##NO_TEXT
IMPORTING ev_value = reg_info ).
DATA prxy_info TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/prxy_info' ##NO_TEXT
IMPORTING ev_value = prxy_info ).
DATA log_settings TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/logging' ##NO_TEXT
IMPORTING ev_value = log_settings ).
DATA file_pattern TYPE string.
PERFORM read_log_settings
USING
log_settings
CHANGING
file_pattern.
" Get current log file name
DATA: current_log_file TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'gw/logging_name' ##NO_TEXT
IMPORTING ev_value = current_log_file ).
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'Overview'(010), AT sy-linsz space.
FORMAT RESET.
WRITE: / 'System'(011) COLOR COL_NORMAL, 30 sy-sysid,
/ 'Current date'(012) COLOR COL_NORMAL, 30 sy-datum DD/MM/YYYY, sy-uzeit,
/ 'Selected date range'(013) COLOR COL_NORMAL, 30 fromdate DD/MM/YYYY, '-', todate DD/MM/YYYY.
IF show_par = 'X'.
SKIP.
WRITE: / 'gw/sim_mode'(014) COLOR COL_NORMAL, 30 sim_mode.
WRITE: / 'gw/reg_no_conn_info'(015) COLOR COL_NORMAL, 30 reg_no_conn_info.
WRITE: / 'gw/acl_mode'(016) COLOR COL_NORMAL, 30 acl_mode.
WRITE: / 'gw/sec_info'(017) COLOR COL_NORMAL, 30 sec_info.
WRITE: / 'gw/reg_info'(018) COLOR COL_NORMAL, 30 reg_info.
WRITE: / 'gw/prxy_info'(019) COLOR COL_NORMAL, 30 prxy_info.
WRITE: / 'Log settings'(020) COLOR COL_NORMAL, 30 log_settings.
WRITE: / 'Log file pattern'(021) COLOR COL_NORMAL, 30 file_pattern.
WRITE: / 'Current log file'(022) COLOR COL_NORMAL, 30 current_log_file.
ENDIF.
ULINE.
IF show_sec = 'X'.
" Get secinfo
DATA secinfo TYPE tgw_buffer.
subrc = lo_gwmon->get_sec_info( IMPORTING et_list = secinfo ).
" Show secinfo
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'secinfo'(023), sec_info, AT sy-linsz space.
FORMAT RESET.
LOOP AT secinfo INTO line.
WRITE: / line.
PERFORM convert_adress USING 'USER-HOST' line.
PERFORM convert_adress USING 'HOST' line.
ENDLOOP.
ULINE.
ENDIF.
IF show_reg = 'X'.
" Get reginfo
DATA reginfo TYPE tgw_buffer.
subrc = lo_gwmon->get_reg_info( IMPORTING et_list = reginfo ).
" Show reginfo
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'reginfo'(024), reg_info, AT sy-linsz space.
FORMAT RESET.
LOOP AT reginfo INTO line.
WRITE: / line.
PERFORM convert_adress USING 'USER-HOST' line.
PERFORM convert_adress USING 'HOST' line.
ENDLOOP.
ULINE.
ENDIF.
IF show_prx = 'X'.
" Get prxyinfo
DATA prxyinfo TYPE tgw_buffer.
subrc = lo_gwmon->get_proxy_info( IMPORTING et_list = prxyinfo ).
" Show proxyinfo
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'prxyinfo'(025), prxy_info, AT sy-linsz space.
FORMAT RESET.
LOOP AT prxyinfo INTO line.
WRITE: / line.
PERFORM convert_adress USING 'USER-HOST' line.
PERFORM convert_adress USING 'HOST' line.
ENDLOOP.
ULINE.
ENDIF.
" Host buffer
IF show_buf = 'X'.
PERFORM rsnitest.
ENDIF.
" Log files
IF show_log = 'X'.
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'Logging'(026), AT sy-linsz space.
FORMAT RESET.
DATA date TYPE sy-datum.
DATA file TYPE string.
" Swap dates to prevent endless loop
IF fromdate > todate.
date = fromdate.
fromdate = todate.
todate = date.
ENDIF.
"PERFORM read_directory. " not used yet
" First file
date = fromdate.
DO.
IF date = sy-datum.
lo_gwmon->flush_logfile( ).
ENDIF.
file = file_pattern.
REPLACE '%y' IN file WITH date(4). " year
REPLACE '%m' IN file WITH date+4(2). " month
REPLACE '%d' IN file WITH date+6(2). " day
"REPLACE '%h' IN file WITH '\d\d'. " hour
"REPLACE '%t' IN file WITH '\d\d'. " minute
"REPLACE '%s' IN file WITH '\d\d'. " second
PERFORM show_file USING file.
" Next file
date = date + 1.
IF date > todate.
EXIT.
ENDIF.
ENDDO.
ULINE.
ENDIF.
" Trace files
IF show_trc = 'X'.
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'Trace'(027), AT sy-linsz space.
FORMAT RESET.
PERFORM show_file USING 'dev_rd.old' ##NO_TEXT.
PERFORM show_file USING 'dev_rd' ##NO_TEXT.
ENDIF.
FORM show_file
USING file.
DATA: line(255) TYPE c.
OPEN DATASET file IN TEXT MODE FOR INPUT ENCODING DEFAULT.
IF sy-subrc <> 0.
"MESSAGE s108 WITH file.
RETURN.
ENDIF.
FORMAT COLOR COL_NORMAL.
WRITE: / 'File'(028), 30 file, AT sy-linsz space.
FORMAT RESET.
DATA hide(1).
DO.
READ DATASET file INTO line.
IF sy-subrc <> 0. EXIT. ENDIF.
IF file = 'dev_rd' OR file = 'dev_rd.old' ##NO_TEXT.
" Highlight timestamp in dev_rd: Wed Jan 18 05:21:13:794 2023
DATA: monthtext(3), day(2), month(2), year(4).
FIND REGEX '^\w\w\w (\w\w\w) (\d{1,2}) \d\d:\d\d:\d\d:\d\d\d (\d\d\d\d)' ##NO_TEXT
IN line SUBMATCHES monthtext day year.
IF sy-subrc = 0.
CASE monthtext.
WHEN 'Jan'. month = '01' ##NO_TEXT.
WHEN 'Feb'. month = '02' ##NO_TEXT.
WHEN 'Mar'. month = '03' ##NO_TEXT.
WHEN 'Apr'. month = '04' ##NO_TEXT.
WHEN 'May'. month = '05' ##NO_TEXT.
WHEN 'Jun'. month = '06' ##NO_TEXT.
WHEN 'Jul'. month = '07' ##NO_TEXT.
WHEN 'Aug'. month = '08' ##NO_TEXT.
WHEN 'Sep'. month = '09' ##NO_TEXT.
WHEN 'Oct'. month = '10' ##NO_TEXT.
WHEN 'Nov'. month = '11' ##NO_TEXT.
WHEN 'Dec'. month = '12' ##NO_TEXT.
ENDCASE.
DATA log_date TYPE sy-datum.
log_date(4) = year.
log_date+4(2) = month.
log_date+6(2) = day.
IF log_date >= fromdate AND log_date <= todate.
hide = ' '.
ELSE.
hide = 'X'.
ENDIF.
IF hide = ' '.
WRITE / line COLOR COL_TOTAL.
ENDIF.
ELSE.
IF hide = ' '.
" Highlight errors
FIND REGEX '^\*\*\* ERROR' IN line ##NO_TEXT.
IF sy-subrc = 0.
WRITE / line COLOR COL_NEGATIVE INVERSE ON.
ELSE.
WRITE / line.
ENDIF.
ENDIF.
ENDIF.
ELSE. " other files
WRITE / line.
ENDIF.
ENDDO.
CLOSE DATASET file.
ENDFORM.
FORM read_log_settings
USING
log_settings
CHANGING
file_pattern.
"Details about log setting according to program RGWMON_LOGGING FORM get_actual_state
DATA:
BEGIN OF itab OCCURS 5,
line(64) TYPE c,
END OF itab,
id(64) TYPE c,
val(64) TYPE c,
len TYPE i,
idx TYPE i,
comp(1) TYPE c.
SPLIT log_settings AT ' ' INTO TABLE itab.
LOOP AT itab.
SPLIT itab-line AT '=' INTO id val.
CASE id.
WHEN 'ACTION'.
len = strlen( val ).
DO len TIMES.
idx = sy-index - 1.
comp = val+idx.
CASE comp.
WHEN 'T'. "gw_log_tcpip = 'X'.
WHEN 'C'. "gw_log_rfc = 'X'.
WHEN 'O'. "gw_log_rfc2 = 'X'.
WHEN 'E'. "gw_log_ext = 'X'.
WHEN 'R'. "gw_log_reg = 'X'.
WHEN 'S'. "gw_log_sec = 'X'.
WHEN 's'. "gw_log_secd = 'X'.
WHEN 'Z'. "gw_log_norule = 'X'.
WHEN 'M'. "gw_log_mon = 'X'.
WHEN 'P'. "gw_log_param = 'X'.
WHEN 'X'. "gw_log_start = 'X'.
WHEN 'V'. "gw_log_cvid = 'X'.
ENDCASE.
ENDDO.
WHEN 'SWITCHTF'.
DATA: switchft(12) TYPE c,
switchft_int(12) TYPE c.
switchft_int = val.
CASE switchft_int.
WHEN 'hour'.
"switchft = text-005.
WHEN 'day'.
"switchft = text-006.
WHEN 'week'.
"switchft = text-007.
WHEN 'month'.
"switchft = text-008.
WHEN 'year'.
"switchft = text-009.
WHEN OTHERS.
"switchft = text-004.
ENDCASE.
WHEN 'MAXSIZEKB'.
"maxsizekb = val.
WHEN 'FILEWRAP'.
IF val = 'on'.
"filewrapt = 'X'.
ENDIF.
WHEN 'LOGFILE'.
file_pattern = val.
WHEN OTHERS.
* ignore
ENDCASE.
ENDLOOP.
ENDFORM.
FORM read_directory. " not used yet
DATA dir_home TYPE string.
subrc = lo_gwmon->get_parameter( EXPORTING iv_name = 'DIR_HOME' ##NO_TEXT
IMPORTING ev_value = dir_home ).
DATA dir_name TYPE salfile-longname.
"DATA FROMLINE TYPE I.
"DATA NRLINES TYPE I.
DATA file_tbl TYPE STANDARD TABLE OF salfldir.
DATA file_entry TYPE salfldir.
dir_name = dir_home.
CALL FUNCTION 'RZL_READ_DIR_LOCAL'
EXPORTING
name = dir_name
* FROMLINE = 0
* NRLINES = 1000
TABLES
file_tbl = file_tbl
EXCEPTIONS
argument_error = 1
not_found = 2
no_admin_authority = 3
OTHERS = 4.
IF sy-subrc <> 0.
* Implement suitable error handling here
ENDIF.
SORT file_tbl BY name.
DATA regex TYPE string.
regex = |^| & |{ file_pattern }|.
REPLACE '%y' IN regex WITH '\d\d\d\d'. " year
REPLACE '%m' IN regex WITH '\d\d'. " month
REPLACE '%d' IN regex WITH '\d\d'. " day
REPLACE '%h' IN regex WITH '\d\d'. " hour
REPLACE '%t' IN regex WITH '\d\d'. " minute
REPLACE '%s' IN regex WITH '\d\d'. " second
DATA size TYPE i.
LOOP AT file_tbl INTO file_entry.
FIND REGEX regex IN file_entry-name.
IF sy-subrc = 0.
size = file_entry-size.
WRITE: / file_entry-name, size.
ENDIF.
ENDLOOP.
ENDFORM.
FORM rsnitest. " based on report RSNITEST
DATA:
it_addrlist TYPE TABLE OF nis_nodeaddr_list,
wa_addrlist TYPE nis_nodeaddr_list,
it_hostlist TYPE TABLE OF nis_hostbuf_list,
wa_hostlist TYPE nis_hostbuf_list,
it_servlist TYPE TABLE OF nis_servbuf_list,
wa_servlist TYPE nis_servbuf_list.
FORMAT RESET.
FORMAT COLOR COL_HEADING.
WRITE: / 'Network buffer'(028), AT sy-linsz space.
FORMAT RESET.
*-----------------------------------------------------------------------
* LOCAL ADDRESS LIST
*-----------------------------------------------------------------------
CALL FUNCTION 'NI_GET_ADDR_LIST'
TABLES
addrlist = it_addrlist
EXCEPTIONS
einval = 1
OTHERS = 2.
IF sy-subrc <> 0.
WRITE: 'Error in function NI_GET_ADDR_LIST'(029) COLOR COL_NEGATIVE.
ENDIF.
IF it_addrlist IS NOT INITIAL.
FORMAT COLOR COL_NORMAL.
WRITE: / 'Local address list'(030), AT sy-linsz space.
FORMAT RESET.
LOOP AT it_addrlist INTO wa_addrlist.
NEW-LINE.
WRITE:
wa_addrlist-nodeaddr.
IF wa_addrlist-protocol = 0.
WRITE 'unknown'.
ELSEIF wa_addrlist-protocol = 1.
WRITE 'UDS'.
ELSEIF wa_addrlist-protocol = 2.
WRITE 'IPv4'.
ELSEIF wa_addrlist-protocol = 4.
WRITE 'IPv6'.
ENDIF.
IF wa_addrlist-addrtype = 0.
" undefined
ELSEIF wa_addrlist-addrtype = 1.
WRITE: '/', 'any'.
ELSEIF wa_addrlist-addrtype = 2.
WRITE: '/', 'loopback'.
ELSEIF wa_addrlist-addrtype = 4.
WRITE: '/', 'multicast'.
ELSEIF wa_addrlist-addrtype = 8.
WRITE: '/', 'link local'.
ELSEIF wa_addrlist-addrtype = 16.
WRITE: '/', 'site local'.
ENDIF.
ENDLOOP.
ENDIF.
*-----------------------------------------------------------------------
* HOST BUFFER
*-----------------------------------------------------------------------
CALL FUNCTION 'NI_GET_BUFFER_LIST'
TABLES
hostlist = it_hostlist
* SERVLIST =
EXCEPTIONS
einval = 1
eintern = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: 'Error in function NI_GET_BUFFER_LIST'(031) COLOR COL_NEGATIVE.
ENDIF.
IF it_hostlist IS NOT INITIAL.
FORMAT COLOR COL_NORMAL.
WRITE: / 'Host buffer'(032), AT sy-linsz space.
FORMAT RESET.
LOOP AT it_hostlist INTO wa_hostlist.
NEW-LINE.
WRITE:
wa_hostlist-id.
IF wa_hostlist-status = 1.
WRITE 'valid '.
ELSEIF wa_hostlist-status = 0.
WRITE 'unknown'.
ELSE.
WRITE 'invalid status'.
ENDIF.
WRITE:
wa_hostlist-typ,
wa_hostlist-ipv4addr.
IF NOT wa_hostlist-ipv6addr = '~'.
WRITE wa_hostlist-ipv6addr.
ENDIF.
WRITE:
wa_hostlist-hostname.
ENDLOOP.
ENDIF.
*-----------------------------------------------------------------------
* SERV BUFFER
*-----------------------------------------------------------------------
CALL FUNCTION 'NI_GET_BUFFER_LIST'
TABLES
* hostlist =
servlist = it_servlist
EXCEPTIONS
einval = 1
eintern = 2
OTHERS = 3.
IF sy-subrc <> 0.
WRITE: 'Error in function NI_GET_BUFFER_LIST'(031) COLOR COL_NEGATIVE.
ENDIF.
IF it_servlist IS NOT INITIAL.
FORMAT COLOR COL_NORMAL.
WRITE: / 'Service buffer'(034), AT sy-linsz space.
FORMAT RESET.
LOOP AT it_servlist INTO wa_servlist.
NEW-LINE.
WRITE:
wa_servlist-id.
IF wa_servlist-status = 1.
WRITE 'valid '.
ELSEIF wa_servlist-status = 0.
WRITE 'unknown'.
ELSE.
WRITE 'invalid status'.
ENDIF.
IF wa_servlist-servno = 0.
WRITE ' - '.
ELSE.
WRITE wa_servlist-servno.
ENDIF.
WRITE:
wa_servlist-servname.
ENDLOOP.
ENDIF.
ENDFORM.
FORM convert_adress
USING
token " USER_HOST or HOST
line. " Line from secifo, reginfo, prxyinfo
" Convert NI adresses using functions NI_ADDR_TO_NAME (or NI_ADDR_TO_FQ_NAME?) respective NI_NAME_TO_ADDR
" Other useful function might be NI_PORT_TO_NAME, NI_NAME_TO_PORT
DATA value TYPE string.
DATA result TYPE string.
DATA nodeaddr TYPE ni_nodeaddr.
DATA hostname TYPE ni_hostname. " 63 char
* DATA hostname_long TYPE ni_hostname_long. " 256 char
DATA protocol TYPE ni_proto_fam. " 0 Undefined Protocol Family
" 1 Local Protocol (UDS)
" 2 Internet Protocol Version 4 (IPv4)
" 4 Internet Protocol Version 6 (IPv6)
DATA addrtype TYPE ni_addr_type. " 0 Undefined Address Type
" 1 Any Address
" 2 Loopback Address
" 4 Multicast Address
" 8 Link Local Address
" 16 Site Local Address
DATA local TYPE ni_addr_local.
" Convert IP address to hostname
FIND REGEX ` ` && token && `=([0-9.:/*]*)` ##NO_TEXT
IN line SUBMATCHES value.
IF sy-subrc = 0 AND value IS NOT INITIAL.
IF value NA '*/'. " ignore entries with submask like /24 or .*)
nodeaddr = value.
CALL FUNCTION 'NI_ADDR_TO_NAME' " or NI_ADDR_TO_FQ_NAME
EXPORTING
nodeaddr = nodeaddr
IMPORTING
hostname = hostname
* hostname_long = hostname_long
protocol = protocol
addrtype = addrtype
local = local
EXCEPTIONS
ehost_unknown = 1
einval = 2
etoo_small = 3
OTHERS = 4.
IF sy-subrc = 0.
result = hostname.
ELSEIF sy-subrc = 1.
WRITE: '#', `unknown` && ` ` && token COLOR COL_NEGATIVE.
ELSE.
WRITE: '#', 'Error in NI_ADDR_TO_NAME' COLOR COL_NEGATIVE.
ENDIF.
ENDIF.
ELSE.
" Convert hostname to IP address
FIND REGEX ` ` && token && `=([^ ]*) ` ##NO_TEXT
IN line SUBMATCHES value.
IF sy-subrc = 0 AND value IS NOT INITIAL.
IF value NE 'local' AND value NE 'internal' AND value NA '*'. " Ignore some values and an submask
hostname = value.
* hostname_long = value.
CALL FUNCTION 'NI_NAME_TO_ADDR'
EXPORTING
hostname = hostname
* hostname_long = hostname_long
* PROTOCOL_RESTRICTION = 0
IMPORTING
nodeaddr = nodeaddr
protocol = protocol
addrtype = addrtype
local = local
EXCEPTIONS
ehost_unknown = 1
einval = 2
OTHERS = 3.
IF sy-subrc = 0.
result = nodeaddr.
ELSEIF sy-subrc = 1.
WRITE: '#', `unknown` && ` ` && token COLOR COL_NEGATIVE.
ELSE.
WRITE: '#', 'Error in NI_NAME_TO_ADDR' COLOR COL_NEGATIVE.
ENDIF.
ENDIF.
ENDIF.
ENDIF.
" Show result as comment and
IF result IS NOT INITIAL.
WRITE: '#', token && `=` && result COLOR COL_POSITIVE.
CASE protocol.
WHEN 1. WRITE 'UDS'.
"WHEN 2. WRITE 'IPv4'.
WHEN 4. WRITE 'IPv6'.
ENDCASE.
CASE addrtype.
WHEN 1. WRITE 'Any'.
WHEN 2. WRITE 'Loopback'.
WHEN 4. WRITE 'Multicase'.
WHEN 8. WRITE 'Link local'.
ENDCASE.
IF local IS NOT INITIAL.
WRITE 'local'.
ENDIF.
ENDIF.
ENDFORM.