home *** CD-ROM | disk | FTP | other *** search
/ The World of Computer Software / World_Of_Computer_Software-02-385-Vol-1of3.iso / p / pcrte224.zip / SOURCE.ZIP / DLOG.INC < prev    next >
Text File  |  1992-06-09  |  8KB  |  321 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_INET_in_AX_BX  name, string
  31. ;;   DLOG_CLOSE name
  32. ;;
  33. ;;*****************************************************************************
  34.  
  35. ;;*****************************************************************************
  36. ;; definition of DLOG packet structure
  37.  
  38.  
  39. dlog_data STRUC
  40.     dlog_handle     DW ?
  41.     dlog_ip_addr    DD ?
  42.     dlog_buffer     db 32 dup (0)
  43.     dlog_file       db 'pcroute.log', 0
  44. dlog_data ENDS
  45.  
  46.  
  47. ;;******************************************************************************
  48. ;;  DLOG_DECLARE name, facility, udp
  49. ;;       DLOG_DECLARE delcares a new loging object called 'name'. 
  50. ;;
  51. DLOG_DECLARE   MACRO  name
  52.     .errb <name>
  53.  
  54.     .DATA
  55.     global dlog_&name&_data:dlog_data
  56.  
  57.     .CODE
  58.     global dlog_&name&_define:near
  59.     global dlog_&name&_print_hex_in_AX_CX_DX_const_ALL:near
  60.     global dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL:near
  61.  
  62.     global log_dec_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES:near
  63.     global log_hex_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES:near
  64. ENDM
  65.  
  66.  
  67. ;;******************************************************************************
  68. ;;   DLOG_DEFINE name
  69. ;;       DLOG_DEFINE sets aside the memory and acutally does the 
  70. ;;       initialization for the routeing objects 'name'
  71. ;;
  72. DLOG_DEFINE   MACRO   name
  73.     call dlog_&name&_define
  74. ENDM
  75.  
  76. DLOG_REAL_DEFINE MACRO name
  77.     local around
  78.     .errb <name>
  79.  
  80.     .DATA
  81.     dlog_&name&_data    dlog_data <>
  82.  
  83.     .CODE
  84.     jmp around
  85.                 ;; 'external' routines
  86.         dlog_&name&_print_hex_in_AX_CX_DX_const_ALL:
  87.            DLOG_REAL_PRINT_HEX_in_AX_CX_DX_const_ALL name
  88.             RET
  89.         dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL:
  90.            DLOG_REAL_PRINT_INET_in_AX_BX_CX_DX_const_ALL name
  91.             RET
  92.  
  93.     around:
  94.     dlog_&name&_define:
  95.  
  96.     mov DX, offset dlog_&name&_data.dlog_file       ;; create the file
  97.     mov CX, 0
  98.     mov AH, 3CH
  99.     int 21H
  100.  
  101.         ;; we assume that this worked, since we have no way of
  102.         ;; recovering from this error
  103.  
  104.     mov word ptr dlog_&name&_data.dlog_handle, AX
  105.     RET
  106. ENDM
  107.  
  108.  
  109. ;;**************************************************************************
  110. ;; DLOG_CLOSE closes the log file, insuring that everything was written
  111. ;; out.  Obviously, no PRINTS can be issued after this
  112. ;;
  113. DLOG_CLOSE  MACRO name
  114.  
  115.     mov BX, dlog_&name&_data.dlog_handle        ;; close the file
  116.     mov AH, 3EH
  117.     int 21H
  118. ENDM
  119.  
  120.  
  121. ;;**************************************************************************
  122. ;; DLOG_PRINT logs the message 'string' to the the log file
  123. ;;    Note that this module violates convention and saves ALL registers
  124. ;;
  125. DLOG_PRINT  MACRO name, string
  126.    local mystring, endstring
  127.    .errb <string>
  128.  
  129.     .DATA
  130. mystring    db '&string', 13, 10
  131. endstring   db 0
  132.  
  133.    .CODE
  134.     push AX
  135.     push BX
  136.     push CX
  137.     push DX
  138.  
  139.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  140.     mov AH, 40H                 
  141.     mov CX, endstring - mystring
  142.     mov DX, offset mystring
  143.     int 21H
  144.  
  145.     pop DX
  146.     pop CX
  147.     pop BX
  148.     pop AX
  149. ENDM
  150.  
  151.  
  152. ;;**************************************************************************
  153. ;; DLOG_PRINT_REG_HEX logs the message 'string' to the log file
  154. ;;    reg is then printed after the string in Hexidecimal notation
  155. ;;    Note that this module violates convention and saves ALL registers
  156. ;;
  157. DLOG_PRINT_REG_HEX  MACRO name, string, reg
  158.    local mystring, endstring
  159.    .errb <string>
  160.  
  161.     .DATA
  162. mystring    db '&string'
  163. endstring   db 0
  164.  
  165.    .CODE
  166.     push CX
  167.     push DX
  168.     push AX
  169.  
  170.     mov AX, reg
  171.     mov CX, endstring - mystring
  172.     mov DX, offset mystring
  173.     call dlog_&name&_print_hex_in_AX_CX_DX_const_ALL
  174.  
  175.     pop AX
  176.     pop DX
  177.     pop CX
  178. ENDM
  179.  
  180.  
  181. ;;**************************************************************************
  182. ;; DLOG_PRINT_INET logs the message 'string' to the log file
  183. ;;    AX:BX is then printed in internet 'dot' notation
  184. ;;    Note that this module violates convention and saves ALL registers
  185. ;;
  186. DLOG_PRINT_INET_in_AX_BX  MACRO name, string
  187.    local mystring, endstring
  188.    .errb <string>
  189.  
  190.     .DATA
  191.     mystring    db '&string'
  192.     endstring   db 0
  193.  
  194.    .CODE
  195.     push CX
  196.     push DX
  197.  
  198.     mov CX, endstring - mystring
  199.     mov DX, offset mystring
  200.     call dlog_&name&_print_inet_in_AX_BX_CX_DX_const_ALL
  201.  
  202.     pop DX
  203.     pop CX
  204. ENDM
  205.  
  206.  
  207. ;;**************************************************************************
  208. ;; Does the real work in doing printing a register in hex
  209. ;;
  210. DLOG_REAL_PRINT_HEX_in_AX_CX_DX_const_ALL MACRO name
  211.    local terminate
  212.    .errb <name>
  213.  
  214.     .DATA
  215. terminate   db 13, 10
  216.  
  217.    .CODE
  218.     push AX
  219.     push BX
  220.     push CX
  221.     push DX
  222.     push BP
  223.     push SI
  224.     push DI
  225.     push ES
  226.  
  227.     mov BP, AX          ;; save AX
  228.  
  229.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  230.     mov AH, 40H                 
  231.     int 21H
  232.  
  233.     mov AX, BP          ;; restore AX
  234.  
  235.     mov CX, DS
  236.     mov ES, CX
  237.     mov DI, offset dlog_&name&_data.dlog_buffer 
  238.     call log_hex_ascii_in_AX_DI_ES_out_DI_const_BX_DX_BP_ES
  239.  
  240.     sub DI, offset dlog_&name&_data.dlog_buffer 
  241.     mov CX, DI                                  ;; the length
  242.     mov AH, 40H                                 ;; write the number
  243.     mov DX, offset dlog_&name&_data.dlog_buffer 
  244.     int 21H
  245.  
  246.     mov CX, 2
  247.     mov DX, offset terminate
  248.     mov AH, 40H                 
  249.     int 21H
  250.  
  251.     pop ES
  252.     pop DI
  253.     pop SI
  254.     pop BP
  255.     pop DX
  256.     pop CX
  257.     pop BX
  258.     pop AX
  259. ENDM
  260.  
  261.  
  262. ;;**************************************************************************
  263. ;; Does the real work in doing printing an internet dot notation
  264. ;;
  265. DLOG_REAL_PRINT_INET_in_AX_BX_CX_DX_const_ALL MACRO name
  266.    local terminate
  267.     .errb <name>
  268.  
  269.     .DATA
  270. terminate   db 13, 10
  271.  
  272.     .CODE
  273.     push AX
  274.     push BX
  275.     push CX
  276.     push DX
  277.     push BP
  278.     push SI
  279.     push DI
  280.     push ES
  281.  
  282.     mov word ptr dlog_&name&_data.dlog_ip_addr, AX
  283.     mov word ptr dlog_&name&_data.dlog_ip_addr+2, BX
  284.  
  285.     mov BX, dlog_&name&_data.dlog_handle        ;; write the file
  286.     mov AH, 40H                 
  287.     int 21H
  288.  
  289.     mov AX, DS
  290.     mov ES, AX
  291.  
  292.     mov DI, offset dlog_&name&_data.dlog_buffer 
  293.     mov CX, 15          ;; maximum size of IP addr
  294.     mov AL, ' '
  295.     rep
  296.     stosb
  297.  
  298.     mov SI, offset dlog_&name&_data.dlog_ip_addr
  299.     IP_ASCII_in_SI_DI_ES_out_DI_const_BX_BP_ES 
  300.  
  301.     mov AH, 40H                                 ;; write the number
  302.     mov DX, offset dlog_&name&_data.dlog_buffer 
  303.     mov CX, 15          ;; size of IP address 
  304.     int 21H
  305.  
  306.     mov CX, 2
  307.     mov DX, offset terminate
  308.     mov AH, 40H                 
  309.     int 21H
  310.  
  311.     pop ES
  312.     pop DI
  313.     pop SI
  314.     pop BP
  315.     pop DX
  316.     pop CX
  317.     pop BX
  318.     pop AX
  319. ENDM
  320.  
  321.