home *** CD-ROM | disk | FTP | other *** search
/ PC Press: Internet / PC_PRESS.ISO / software / dos / misc / inar-100.exe / SRC / PCROUTE / DLOG.INC < prev    next >
Encoding:
Text File  |  1995-05-21  |  9.6 KB  |  410 lines

  1. ;;************************************************************************* 
  2. ;;                     dlog.inc       dlog.inc
  3. ;;*************************************************************************
  4. ;;
  5. ;;  Copyright (C) 1989 Northwestern University, Vance Morrison
  6. ;;
  7. ;;
  8. ;; Permission to view, compile, and modify for LOCAL (intra-organization) 
  9. ;; USE ONLY is hereby granted, provided that this copyright and permission 
  10. ;; notice appear on all copies.  Any other use by permission only.
  11. ;;
  12. ;; Northwestern University makes no representations about the suitability 
  13. ;; of this software for any purpose.  It is provided "as is" without expressed 
  14. ;; or implied warranty.  See the copywrite notice file for complete details.
  15. ;;
  16. ;;*****************************************************************************
  17. ;;
  18. ;; dlog.inc a module that allows configuration info to be logged to the disk.
  19. ;; Do NOT use these routines while the router is routing since a write may
  20. ;; take as long as 1 second to service.
  21. ;;
  22. ;; This module does depend on utility routines found in log.inc
  23. ;;
  24. ;; Routines provided by this module
  25. ;;
  26. ;;   DLOG_DECLARE name
  27. ;;   DLOG_DEFINE name
  28. ;;   DLOG_PRINT  name, string
  29. ;;   DLOG_PRINT_REG_HEX  name, string, reg
  30. ;;   DLOG_PRINT_REG_DEC  name, string, reg
  31. ;;   DLOG_PRINT_INET_in_AX_BX  name, string
  32. ;;   DLOG_CLOSE name
  33. ;;
  34. ;;*****************************************************************************
  35.  
  36. ;;*****************************************************************************
  37. ;; definition of DLOG packet structure
  38.  
  39.  
  40. dlog_data STRUC
  41.     dlog_handle     DW ?
  42.     dlog_ip_addr    DD ?
  43.     dlog_buffer     db 32 dup (0)
  44.     dlog_file       db 'p', '0'+num_dls, '.log', 0
  45. dlog_data ENDS
  46.  
  47.  
  48. ;;******************************************************************************
  49. ;;  DLOG_DECLARE name
  50. ;;       DLOG_DECLARE delcares a new loging object called 'name'. 
  51. ;;
  52. DLOG_DECLARE   MACRO  name
  53.     .errb <name>
  54.  
  55.     .DATA
  56.     global dlog_&name&_data:dlog_data
  57.  
  58.     .CODE
  59.     global dlog_&name&_define:near
  60.     global dlog_&name&_print_hex_in_AX_CX_DX_const_ALL:near
  61.     global dlog_&name&_print_dec_in_AX_CX_DX_const_ALL:near
  62.     global dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL:near
  63.  
  64.     global log_dec_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES:near
  65.     global log_hex_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES:near
  66. ENDM
  67.  
  68.  
  69. ;;******************************************************************************
  70. ;;   DLOG_DEFINE name
  71. ;;       DLOG_DEFINE sets aside the memory and acutally does the 
  72. ;;       initialization for the routeing objects 'name'
  73. ;;
  74. DLOG_DEFINE   MACRO   name
  75.     call dlog_&name&_define
  76. ENDM
  77.  
  78. DLOG_REAL_DEFINE MACRO name
  79.     local around
  80.     .errb <name>
  81.  
  82.     .DATA
  83.     dlog_&name&_data    dlog_data <>
  84.  
  85.     .CODE
  86.     jmp around
  87.                 ;; 'external' routines
  88.         dlog_&name&_print_hex_in_AX_CX_DX_const_ALL:
  89.            DLOG_REAL_PRINT_HEX_in_AX_CX_DX_const_ALL name
  90.             RET
  91.         dlog_&name&_print_dec_in_AX_CX_DX_const_ALL:
  92.            DLOG_REAL_PRINT_DEC_in_AX_CX_DX_const_ALL name
  93.             RET
  94.         dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL:
  95.            DLOG_REAL_PRINT_INET_in_AX_BX_CX_DX_const_ALL name
  96.             RET
  97.  
  98.     around:
  99.     dlog_&name&_define:
  100.  
  101.     mov DX, offset dlog_&name&_data.dlog_file       ;; create the file
  102.     mov CX, 0
  103.     mov AH, 3CH
  104.     int 21H
  105.  
  106.         ;; we assume that this worked, since we have no way of
  107.         ;; recovering from this error
  108.  
  109.     mov word ptr dlog_&name&_data.dlog_handle, AX
  110.     RET
  111. ENDM
  112.  
  113.  
  114. ;;**************************************************************************
  115. ;; DLOG_CLOSE closes the log file, insuring that everything was written
  116. ;; out.  Obviously, no PRINTS can be issued after this
  117. ;;
  118. DLOG_CLOSE  MACRO name
  119.  
  120.     mov BX, dlog_&name&_data.dlog_handle        ;; close the file
  121.     mov AH, 3EH
  122.     int 21H
  123. ENDM
  124.  
  125.  
  126. ;;**************************************************************************
  127. ;; DLOG_PRINT logs the message 'string' to the the log file
  128. ;;    Note that this module violates convention and saves ALL registers
  129. ;;
  130. DLOG_PRINT  MACRO name, string
  131.    local mystring, endstring
  132.    .errb <string>
  133.  
  134.     .DATA
  135. mystring    db '&string', 13, 10
  136. endstring   db 0
  137.  
  138.    .CODE
  139.     push AX
  140.     push BX
  141.     push CX
  142.     push DX
  143.  
  144.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  145.     mov AH, 40H                 
  146.     mov CX, endstring - mystring
  147.     mov DX, offset mystring
  148.     int 21H
  149.  
  150.     pop DX
  151.     pop CX
  152.     pop BX
  153.     pop AX
  154. ENDM
  155.  
  156.  
  157. ;;**************************************************************************
  158. ;; DLOG_PRINT_REG_HEX logs the message 'string' to the log file
  159. ;;    reg is then printed after the string in Hexadecimal notation
  160. ;;    Note that this module violates convention and saves ALL registers
  161. ;;
  162. DLOG_PRINT_REG_HEX  MACRO name, string, reg
  163.    local mystring, endstring
  164.    .errb <string>
  165.  
  166.     .DATA
  167. mystring    db '&string'
  168. endstring   db 0
  169.  
  170.    .CODE
  171.     push CX
  172.     push DX
  173.     push AX
  174.  
  175.     mov AX, reg
  176.     mov CX, endstring - mystring
  177.     mov DX, offset mystring
  178.     call dlog_&name&_print_hex_in_AX_CX_DX_const_ALL
  179.  
  180.     pop AX
  181.     pop DX
  182.     pop CX
  183. ENDM
  184.  
  185.  
  186. ;;**************************************************************************
  187. ;; DLOG_PRINT_REG_DEC logs the message 'string' to the log file
  188. ;;    reg is then printed after the string in Decimal notation
  189. ;;    Note that this module violates convention and saves ALL registers
  190. ;;
  191. DLOG_PRINT_REG_DEC  MACRO name, string, reg
  192.    local mystring, endstring
  193.    .errb <string>
  194.  
  195.     .DATA
  196. mystring    db '&string'
  197. endstring   db 0
  198.  
  199.    .CODE
  200.     push CX
  201.     push DX
  202.     push AX
  203.  
  204.     mov AX, reg
  205.     mov CX, endstring - mystring
  206.     mov DX, offset mystring
  207.     call dlog_&name&_print_dec_in_AX_CX_DX_const_ALL
  208.  
  209.     pop AX
  210.     pop DX
  211.     pop CX
  212. ENDM
  213.  
  214.  
  215. ;;**************************************************************************
  216. ;; DLOG_PRINT_INET logs the message 'string' to the log file
  217. ;;    AX:BX is then printed in internet 'dot' notation
  218. ;;    Note that this module violates convention and saves ALL registers
  219. ;;
  220. DLOG_PRINT_INET_in_AX_BX  MACRO name, string
  221.    local mystring, endstring
  222.    .errb <string>
  223.  
  224.     .DATA
  225.     mystring    db '&string'
  226.     endstring   db 0
  227.  
  228.    .CODE
  229.     push CX
  230.     push DX
  231.  
  232.     mov CX, endstring - mystring
  233.     mov DX, offset mystring
  234.     call dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL
  235.  
  236.     pop DX
  237.     pop CX
  238. ENDM
  239.  
  240.  
  241. ;;**************************************************************************
  242. ;; Does the real work in doing printing a register in hex
  243. ;;
  244. DLOG_REAL_PRINT_HEX_in_AX_CX_DX_const_ALL MACRO name
  245.    local terminate
  246.    .errb <name>
  247.  
  248.     .DATA
  249. terminate   db 13, 10
  250.  
  251.    .CODE
  252.     push AX
  253.     push BX
  254.     push CX
  255.     push DX
  256.     push BP
  257.     push SI
  258.     push DI
  259.     push ES
  260.  
  261.     mov BP, AX          ;; save AX
  262.  
  263.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  264.     mov AH, 40H                 
  265.     int 21H
  266.  
  267.     mov AX, BP          ;; restore AX
  268.  
  269.     mov CX, DS
  270.     mov ES, CX
  271.     mov DI, offset dlog_&name&_data.dlog_buffer 
  272.     call log_hex_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES
  273.  
  274.     sub DI, offset dlog_&name&_data.dlog_buffer 
  275.     mov CX, DI                                  ;; the length
  276.     mov AH, 40H                                 ;; write the number
  277.     mov DX, offset dlog_&name&_data.dlog_buffer 
  278.     int 21H
  279.  
  280.     mov CX, 2
  281.     mov DX, offset terminate
  282.     mov AH, 40H                 
  283.     int 21H
  284.  
  285.     pop ES
  286.     pop DI
  287.     pop SI
  288.     pop BP
  289.     pop DX
  290.     pop CX
  291.     pop BX
  292.     pop AX
  293. ENDM
  294.  
  295.  
  296. ;;**************************************************************************
  297. ;; Does the real work in doing printing a register in decimal
  298. ;;
  299. DLOG_REAL_PRINT_DEC_in_AX_CX_DX_const_ALL MACRO name
  300.    local terminate
  301.    .errb <name>
  302.  
  303.     .DATA
  304. terminate   db 13, 10
  305.  
  306.    .CODE
  307.     push AX
  308.     push BX
  309.     push CX
  310.     push DX
  311.     push BP
  312.     push SI
  313.     push DI
  314.     push ES
  315.  
  316.     mov BP, AX          ;; save AX
  317.  
  318.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  319.     mov AH, 40H                 
  320.     int 21H
  321.  
  322.     mov AX, BP          ;; restore AX
  323.  
  324.     mov CX, DS
  325.     mov ES, CX
  326.     mov DI, offset dlog_&name&_data.dlog_buffer 
  327.     call log_dec_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES
  328.  
  329.     sub DI, offset dlog_&name&_data.dlog_buffer 
  330.     mov CX, DI                                  ;; the length
  331.     mov AH, 40H                                 ;; write the number
  332.     mov DX, offset dlog_&name&_data.dlog_buffer 
  333.     int 21H
  334.  
  335.     mov CX, 2
  336.     mov DX, offset terminate
  337.     mov AH, 40H                 
  338.     int 21H
  339.  
  340.     pop ES
  341.     pop DI
  342.     pop SI
  343.     pop BP
  344.     pop DX
  345.     pop CX
  346.     pop BX
  347.     pop AX
  348. ENDM
  349.  
  350.  
  351. ;;**************************************************************************
  352. ;; Does the real work in doing printing an internet dot notation
  353. ;;
  354. DLOG_REAL_PRINT_INET_in_AX_BX_CX_DX_const_ALL MACRO name
  355.    local terminate
  356.     .errb <name>
  357.  
  358.     .DATA
  359. terminate   db 13, 10
  360.  
  361.     .CODE
  362.     push AX
  363.     push BX
  364.     push CX
  365.     push DX
  366.     push BP
  367.     push SI
  368.     push DI
  369.     push ES
  370.  
  371.     mov word ptr dlog_&name&_data.dlog_ip_addr, AX
  372.     mov word ptr dlog_&name&_data.dlog_ip_addr+2, BX
  373.  
  374.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  375.     mov AH, 40H                 
  376.     int 21H
  377.  
  378.     mov AX, DS
  379.     mov ES, AX
  380.  
  381.     mov DI, offset dlog_&name&_data.dlog_buffer 
  382.     mov CX, 15          ;; maximum size of IP addr
  383.     mov AL, ' '
  384.     rep
  385.     stosb
  386.  
  387.     mov SI, offset dlog_&name&_data.dlog_ip_addr
  388.     IP_ASCII_in_SI_DI_ES_out_DI_const_BX_BP_ES 
  389.  
  390.     mov AH, 40H                                 ;; write the number
  391.     mov DX, offset dlog_&name&_data.dlog_buffer 
  392.     mov CX, 15          ;; size of IP address 
  393.     int 21H
  394.  
  395.     mov CX, 2
  396.     mov DX, offset terminate
  397.     mov AH, 40H                 
  398.     int 21H
  399.  
  400.     pop ES
  401.     pop DI
  402.     pop SI
  403.     pop BP
  404.     pop DX
  405.     pop CX
  406.     pop BX
  407.     pop AX
  408. ENDM
  409.  
  410.