home *** CD-ROM | disk | FTP | other *** search
/ Network Support Encyclopedia 96-1 / novell-nsepro-1996-1-cd2.iso / download / netware / ipxasm.exe / IPXEX.ASM < prev    next >
Assembly Source File  |  1995-09-12  |  16KB  |  533 lines

  1. ;*** Copyright (c) 1992 Novell, Inc.  All Rights Reserved.
  2. ;***
  3. ;*** THIS WORK IS SUBJECT TO U.S. AND INTERNATIONAL COPYRIGHT LAWS AND
  4. ;*** TREATIES.  USE AND REDISTRIBUTION OF THIS WORK IS SUBJECT TO THE
  5. ;*** LICENSE AGREEMENT ACCOMPANYING THE SOFTWARE DEVELOPMENT KIT (SDK)
  6. ;*** THAT CONTAINS THIS WORK.
  7. ;***
  8. ;*** Pursuant to the SDK License Agreement, Novell hereby grants to
  9. ;*** Developer a royalty-free, non-exclusive license to include the
  10. ;*** sample code IPXEX.ASM and derivative binaries in its product.
  11. ;*** Novell grants to Developer worldwide distribution rights to market,
  12. ;*** distribute or sell the sample code IPXEX.ASM and derivative
  13. ;*** binaries as a component of Developer's product(s).  Novell shall
  14. ;*** have no obligations to Developer or Developer's customers with
  15. ;*** respect to this code.
  16. ;***
  17. ;*** DISCLAIMER:
  18. ;***
  19. ;***     Novell, Inc. makes no representations or warranties with respect
  20. ;*** to the contents or use of this code, and specifically disclaims any
  21. ;*** express or implied warranties of merchantability or fitness for any
  22. ;*** particular purpose.  Further, Novell, Inc. reserves the right to revise
  23. ;*** this publication and to make changes to its content, at any time,
  24. ;*** without obligation to notify any person or entity of such revisions or
  25. ;*** changes.
  26. ;***
  27. ;***     Further, Novell, Inc. makes no representations or warranties with
  28. ;*** respect to any software, and specifically disclaims any express or
  29. ;*** implied warranties of merchantability or fitness for any particular
  30. ;*** purpose.  Further, Novell, Inc. reserves the right to make changes to
  31. ;*** any and all parts of the software, at any time, without obligation to
  32. ;*** notify any person or entity of such changes.
  33. ;***
  34. ;***
  35. ;*** **********************************************************************
  36. ;***     IPXEX.C
  37. ;*** **********************************************************************
  38. ;***
  39. ;*** Description: This is sample code that demonstrates how to send and 
  40. ;***            receive an IPX packet using the Assembly Language Interface.
  41. ;***           IPXEX takes a server type from the command line, builds
  42. ;***           Get Nearest Server Query for that server type then sends
  43. ;***          the broadcast. It then receives the response (if one arrives 
  44. ;***          within one minute) and prints the name of the server from
  45. ;***          the response packet. 
  46. ;***
  47. ;***
  48. ;***
  49. ;*** Programmer:  Karl Bunnell
  50. ;*** Date:        09/12/95
  51. ;***
  52. ;*** Built with:  Borland TASM
  53.  
  54.  
  55.  
  56.     Ideal
  57.     Model    Tiny
  58.     P286
  59.     CodeSeg
  60.     Org    100h
  61.  
  62. Start:    jmp    INIT_CODE
  63.  
  64.  
  65. ;--------------------------------------------------------------------------
  66. ;** IPX Structures 
  67. ;
  68.  
  69. Struc    IPXHeaderStructure
  70.     IPXChecksum        dw    ?
  71.     IPXLength        dw    ?
  72.     IPXTransportControl    db    ?
  73.     IPXPacketType    db    ?
  74.     IPXDestinationNet    dw    2 dup (?)
  75.     IPXDestinationNode    dw    3 dup (?)
  76.     IPXDestinationSocket    dw    ?
  77.     IPXSourceNet        dw    2 dup (?)
  78.     IPXSourceNode    dw    3 dup (?)
  79.     IPXSourceSocket    dw    ?
  80. EndS    IPXHeaderStructure        
  81.  
  82.     
  83. Struc    ECB_Structure
  84.     Link            dd    ?
  85.     ESR_AddressOff        dw    ?
  86.     ESR_AddressSeg        dw    ?
  87.     In_Use_Flag        db    ?
  88.     CompletionCode        db    ?
  89.     ECB_Socket        dw    ?
  90.     IPXWorkspace        db    4 dup (?)
  91.     DriverWorkSpace        db    12 dup (?)
  92.     ImmediateAddress    db    6 dup (?)
  93.     FragmentCount        dw    ?
  94.     FragmentAddressOff1    dw    ?
  95.     FragmentAddressSeg1    dw    ?
  96.     FragmentLength1        dw    ?
  97.     FragmentAddressOff2    dw    ?
  98.     FragmentAddressSeg2    dw    ?
  99.     FragmentLength2        dw    ?
  100. EndS    ECB_Structure        
  101.  
  102. Struc    SAPIDPacket
  103.     ResponseType        dw    ?
  104.     ServerType        dw    ?
  105.     ServerName        db    48 dup (?)
  106.     NetWork            dw    2 dup (?)
  107.     Node            dw    3 dup (?)
  108.     Socket            dw    ?
  109.     IntermediateNetworks    dw    ?
  110. EndS    SAPIDPacket
  111.  
  112. Struc    SAPQueryPacket
  113.     QueryType        dw    ?
  114.     ServerType        dw    ?
  115. EndS    SAPQueryPacket        
  116.  
  117.  
  118.  
  119. CR           equ     13              ;carriage return
  120. LF           equ     10              ;line feed
  121. STDOUT       equ     1
  122. ONE_MIN         equ     044Ch
  123. USE_INFO         equ     0               ;Index for Usage INFO Screen
  124. IPX_NOT_LOADED   equ     1               ;Index for IPX not loaded Failure
  125. OPEN_SOCKET_FAIL equ     2         ;Index to Open Socket Failed
  126. LONGER_T_MIN     equ     3         ;Index to wait longer than minute
  127.  
  128. UseInfo         DB      CR,LF,"Usage:  IPXEX XXXX"
  129.                 DB      CR,LF,"   Where:"
  130.                 DB      CR,LF,"         XXXX is the Server type in Hex. "
  131.                 DB      CR,LF,42
  132. IPXNotLoaded    DB    CR,LF,"IPX is NOT loaded, Please Load IPX and try again!"
  133.                 DB      CR,LF,42
  134. OpenSocketFail  DB    CR,LF,"Attempt to open IPX Socket Failed!"
  135.         DB    CR,LF,"Socket may already be open or Socket Table is full!"
  136.                 DB      CR,LF,42
  137. LongerThanMin   DB    CR,LF,"Receive Wait Time Out! Waited One minute without a Response."
  138.                 DB      CR,LF,42
  139.  
  140. Transmit    DB    CR,LF,"Attempting to establish connection..."
  141.                 DB      CR,LF,42
  142. Receive        DB    CR,LF,"Waiting to receive initial SAP packet...Will wait 61 Sec."
  143.         DB    CR,LF,42
  144. Connected    DB    CR,LF,"Received SAP Response!"
  145.         DB    CR,LF,42
  146.  
  147. MsgStrTable     DW      UseInfo                 ;0 
  148.                 DW      IPXNotLoaded            ;1
  149.         DW    OpenSocketFail        ;2
  150.         DW    LongerThanMin        ;3
  151.  
  152. IPXH_T        IPXHeaderStructure    ?       ;packet header storage
  153. IPXH_R        IPXHeaderStructure       ?    ;Receive IPX header storage
  154.  
  155. ECB_TR        ECB_Structure        ?       ;Transmit ECB storage
  156. ECB_R        ECB_Structure        ?       ;Receive ECB Storage
  157. SAP_ID        SAPIDPacket        ?    ;buffer to receive SAP S Info
  158. SAP_QR        SAPQueryPacket        ?    ;Sap query storage
  159. IPXEntry    dd    ? 
  160. SAPServType    dw    ?
  161. Broadcast    db    0FFh,0FFh,0FFh,0FFh,0FFh,0FFh
  162. MySocket    dw    ?
  163. RecTryCount    dw    0
  164. TimeCompare    dw    0
  165. save        dw    0
  166. plf        dw    0
  167. Int28Flg    dw    -1
  168.  
  169. ;--------------------------------------------------------------------------         
  170. ;    This is where the Initialization code begins.
  171. ;    This code first checks to see if IPX is loaded, if not it exits.
  172. ;    If nothing is entered on the command line, it exits.
  173. ;    Otherwise it continues on
  174. ;--------------------------------------------------------------------------
  175.         
  176.         Assume ds:DGROUP
  177.  
  178.  
  179. INIT_CODE:    mov    ax, 7A00h       ; Check and see if IPX
  180.         int    2Fh            ; is loaded!
  181.         cmp    al, 0FFh        ; If FF is returned in AL
  182.         je    IPXLoadPass
  183.         mov    cx, IPX_NOT_LOADED
  184.         jmp    MsgPrint
  185.  
  186. IPXLoadPass:    mov    [WORD PTR IPXEntry], di    ; Get IPX entry address
  187.         mov    ax, es
  188.         mov    [WORD PTR IPXEntry+2], ax
  189.  
  190.            mov     bx, 080h        ;load pointer to char count
  191.             mov     dx, 081h        ;load pointer to command line buffer
  192.             xor     ch, ch          ;zero high half of count register
  193.                mov     cl, [bx]        ;load character count
  194.             mov     bx, dx          ;get address passed in DX
  195.             add     dx, cx          ;move DX to end of string
  196.             jmp     PreInst1  ;jump to condition test           
  197.                                             
  198. PreInst0:       mov     al, [bx]        ;get first character
  199.                 cmp     al, ' '         ;is it a space?
  200.                 je      PreInst00
  201.                 cmp     al, '/'         ;is it a slash?
  202.                 je      PreInst00
  203.                 cmp     al, '-'         ;is it a dash?
  204.                 je      PreInst00
  205.                 jmp     short PreInst01 ;none of the above, continue...
  206.     
  207. PreInst00:      inc     bx              ;skip whitespace and separators
  208.                 jmp     PreInst0
  209.  
  210. PreInst01:    mov     ah, [bx]
  211.                 inc     bx              ;get Server Type Number from
  212.                 mov     al, [bx]    ;command line and convert to HEX.
  213.                 call    AsciiToHexByte
  214.         mov    [BYTE SAPServType], al
  215.         inc    bx
  216.         mov     ah, [bx]
  217.                 inc     bx              ;get second char
  218.                 mov     al, [bx]
  219.                 call    AsciiToHexByte
  220.         mov    [BYTE SAPServType+1], al
  221.         mov    ah, [BYTE SAPServType]
  222.         mov    al, [BYTE SAPServType+1]
  223.  
  224.  
  225. ContIPXInit:    push    cs        ;set ds = cs
  226.         pop    ds
  227.         push    cs
  228.         pop    es        ;set es = cs
  229.  
  230.         mov    bx, 0        ;Open socket upon which to X and R.
  231.         mov    al, 0FFh    ;Leave sock open until close sock.
  232.         mov    dx, 0        ;Dynamically assigned socket.
  233.         call    [cs:IPXEntry]
  234.         cmp    al, 00h
  235.         je    IPXOpenSckPass
  236.         mov    cx, OPEN_SOCKET_FAIL
  237.         jmp    MsgPrint
  238.  
  239.  
  240.  
  241.  
  242.                 ;*** Set up the Receive ECB fields
  243.  
  244.         
  245.  
  246. IPXOpenSckPass:    
  247.         xor    ax, ax
  248.         mov    [ECB_R.ESR_AddressOff], ax
  249.         mov    [ECB_R.ESR_AddressSeg], ax
  250.         mov    [WORD MySocket], dx      ;Dynm. socket returned in dx
  251.         mov    [ECB_R.ECB_Socket], dx
  252.         mov    [ECB_R.FragmentCount], 2
  253.         mov    [WORD ECB_R.FragmentAddressOff1], offset IPXH_R
  254.         mov    ax, ds
  255.         mov    [WORD ECB_R.FragmentAddressSeg1], ax
  256.         mov    [ECB_R.FragmentLength1], 30
  257.         mov    [WORD ECB_R.FragmentAddressOff2], offset SAP_ID
  258.         mov    [WORD ECB_R.FragmentAddressSeg2], ax
  259.         mov    [ECB_R.FragmentLength2], 66
  260.  
  261.         push    cs
  262.         pop    es        ;set es = cs
  263.         
  264.         mov    bx, 04h        ;Start listening for SAP reply pack.
  265.         mov    si, offset ECB_R
  266.         call    [cs:IPXEntry]
  267.  
  268.         push    cs        ;set ds = cs
  269.         pop    ds
  270.  
  271.         push    cs
  272.         pop    es        ;set es = cs
  273.         
  274.  
  275.                 ; *** Fill in necessary fields for IPX header.
  276.  
  277.         mov    [IPXH_T.IPXPacketType], 4  ; Packet Type IPX
  278.         mov    si, offset IPXH_T.IPXDestinationNet
  279.         mov    bx, 09h        ;Get Internet Address call
  280.         call    [cs:IPXEntry]
  281.         
  282.         mov    si, offset Broadcast
  283.         mov    di, offset IPXH_T.IPXDestinationNode
  284.         mov    cx, 6        ; Set Dest. Node to FF FF FF FF FF FF
  285.         rep    movsb
  286.         
  287.         mov    [IPXH_T.IPXDestinationSocket], 5204h
  288.  
  289.                 ;*** Fill in SAP Query Packet fields
  290.  
  291.         mov    [WORD SAP_QR.QueryType], 0100h  ;Nearest Query
  292.         mov    dx, [SAPServType]
  293.         mov    [WORD SAP_QR.ServerType], dx
  294.  
  295.                 ;*** Fill in Transmit ECB fields
  296.  
  297.         mov    dx, [MySocket]
  298.         mov    [ECB_TR.ECB_Socket], dx
  299.         xor    ax, ax
  300.         mov    [ECB_TR.ESR_AddressOff], ax 
  301.         mov    [ECB_TR.ESR_AddressSeg], ax 
  302.         mov    si, offset Broadcast
  303.         mov    di, offset ECB_TR.ImmediateAddress
  304.         mov    cx, 6
  305.         rep    movsb
  306.         
  307.         mov    [ECB_TR.FragmentCount], 2
  308.         mov    [WORD ECB_TR.FragmentAddressOff1], offset IPXH_T
  309.         mov    ax, ds
  310.         mov    [WORD ECB_TR.FragmentAddressSeg1], ax
  311.         mov    [ECB_TR.FragmentLength1], 30
  312.         mov    [WORD ECB_TR.FragmentAddressOff2], offset SAP_QR
  313.         mov    [WORD ECB_TR.FragmentAddressSeg2], ax
  314.         mov    [ECB_TR.FragmentLength2], 4
  315.         
  316.         push    cs        ;Transmit Packet!
  317.         pop    es
  318.         mov    bx, 03h
  319.         mov    si, offset ECB_TR
  320.         call    [cs:IPXEntry]
  321.  
  322.         
  323.         mov    ax, offset Transmit
  324.         call    Print
  325.  
  326. QXmitWait:    mov    bx, 0Ah        ;IPX Relinquish control
  327.         call    [cs:IPXEntry]    ;Until Packet is Xmitted.
  328.         cmp    [ECB_TR.In_Use_Flag], 0
  329.         jne    QXmitWait    ;Loop until In Use Flag = 0
  330.  
  331.         mov    ax, offset Receive
  332.         call    Print
  333.  
  334. TimeSet:    mov    ah,0        ;Get Current Time
  335.         int    1ah
  336.         add    dx, ONE_MIN    ;Add one minute
  337.         mov    [TimeCompare], dx
  338.  
  339. QRecWait:    mov    bx, 0Ah        ;IPX Relinquish control
  340.         call    [cs:IPXEntry]    ;Until Packet is received.
  341.         int    1ah
  342.         cmp    [TimeCompare], dx
  343.         jbe    ExitRec
  344.         cmp    [ECB_R.In_Use_Flag], 0
  345.         jne    QRecWait    ;Loop until In Use Flag = 0
  346.  
  347.  
  348.  
  349.         mov    di, offset SAP_ID.ServerName
  350.         add    di, 48
  351.         mov    [BYTE di], 42
  352.  
  353. ;        mov    [SAP_ID.ServerName+47], 42   ;add * to end of server name
  354.         mov    ax, offset SAP_ID.ServerName
  355.         call    Print
  356.  
  357.         mov    ax, [SAPServType]
  358.         cmp    [SAP_ID.ServerType], ax
  359.  
  360.  
  361.  
  362.  
  363.         je    CleanUp
  364.         inc    [RecTryCount]
  365.         mov    [TimeCompare], 00h
  366.  
  367.         push    cs        
  368.         pop    es
  369.  
  370.         mov    bx, 04h        ;Start listening for SAP reply pack.
  371.         mov    si, offset ECB_R
  372.         call    [cs:IPXEntry]
  373.                  
  374.         push    cs        ;Send query packet again
  375.         pop    es
  376.  
  377.         mov    bx, 03h
  378.         mov    si, offset ECB_TR
  379.         call    [cs:IPXEntry]
  380.         
  381.         cmp    [RecTryCount], 20
  382.         jne    QXmitWait
  383.  
  384.         
  385. ExitRec:    mov    cx, LONGER_T_MIN
  386.         jmp    CleanUp                    
  387.         
  388.  
  389. Jumper2:    jmp    PreInst0
  390. PreInst1:      cmp    bx, dx
  391.         jl    Jumper2        ;Used to extend relative jump
  392.         mov    cx, USE_INFO
  393.         jmp     MsgPrint
  394.  
  395.  
  396. CleanUp:     
  397.         push    cs
  398.         pop    es
  399.         mov    bx, 06        ;Cancel IPX event for Xmit ECB
  400.         mov    si, offset ECB_TR
  401.         call    [cs:IPXEntry]
  402.  
  403.         mov    bx, 06        ;Cancel IPX event for Rec ECB
  404.         mov    si, offset ECB_R
  405.         call    [cs:IPXEntry]
  406.  
  407.  
  408.         mov    bx, 01h        ;Close Socket
  409.         mov    dx, [MySocket]
  410.         call    [cs:IPXEntry]
  411.  
  412.         jmp    EndItHere
  413.  
  414.                                 ;*** Print Message 
  415.  
  416. MsgPrint:       mov     bx, cx                  ;get index value
  417.                 shl     bx, 1                   ;mulitply by 2 to index words
  418.                 mov     ax, [MsgStrTable+bx]    ;get address of error msg
  419.                 call    Print
  420.  
  421.  
  422. EndItHere:    mov    ah, 04Ch    ;Return mem. used back to DOS 
  423.         mov    al, 01h        ;And terminate program.
  424.         int    21h
  425.  
  426.         
  427.  
  428.  
  429.  
  430. ;------------------------------------------------------------------------- 
  431. ;                                                                           
  432. ;               Prints Character strings. Stings must end with '*'.
  433. ;                                           
  434. ;                                                                      
  435. ;------------------------------------------------------------------------- 
  436. Proc Print     
  437.              push     ax
  438.              push     di
  439.              push     bx
  440.         push    cs
  441.         pop    ds
  442.              mov    [save], ax       ;save address of message
  443.              mov    [plf], 0        ;clear print loop flag
  444. LP:          mov      ax, [save]       ;get message address
  445.              mov    di, ax
  446.              cmp    [BYTE PTR di],42   ;check for a  '*'
  447.              jne    PRNT           ;jump if not equal to '*'
  448.              mov     [plf],1           ;set print loop flag
  449.              jmp    LPE           ;go to check loop flag
  450. PRNT:         mov    al, [BYTE PTR di]  ;get character to print
  451.              mov      bh, 0
  452.              mov      ah, 0eh
  453.              int    10H
  454.              inc    [save]           ;increment pointer
  455. LPE:         cmp     [BYTE PTR plf], 1  ;check for end of loop
  456.              jne     LP           ;loop if flag is clear
  457.              pop     bx
  458.              pop     di
  459.              pop     ax
  460.              ret               
  461.  
  462. Endp        Print
  463.  
  464. ;------------------------------------------------------------------------
  465. ;       StringLength
  466. ;
  467. ;       Should be called with DS:DX pointing to start of string.
  468. ;       Destroys AX, BX.  Does NOT destroy DS:DX.
  469. ;
  470. ;       Returns number of bytes in string in CX.
  471. ;------------------------------------------------------------------------
  472. Proc            StringLength
  473.                 xor     bx, bx          ;zero BX
  474.                 mov     si, dx          ;get starting address
  475.                 jmp     short StrLen1   ;jump to compare function
  476. StrLen0:        inc     bx              ;increment pointer
  477. StrLen1:        mov     al, [si+bx]     ;get character at si[bx]
  478.                 or      al, al          ;test character
  479.                 jnz     StrLen0         ;get next character
  480.                 mov     cx, bx          ;return count in CX
  481.                 ret                     ;return to caller
  482. EndP            StringLength
  483.  
  484.  
  485. ;------------------------------------------------------------------------
  486. ;       AsciiToHexByte
  487. ;
  488. ;       Takes Ascii hex characters in AH / AL and converts it to a byte
  489. ;       in AL register.
  490. ;------------------------------------------------------------------------
  491. Proc            AsciiToHexByte
  492.  
  493.                 mov     cx, 2
  494. ATH0:           xchg    al, ah          ;switch high and low characters
  495.                 cmp     al, '9'
  496.                 ja      ATH1
  497.                 sub     al, '0'
  498.                 jmp     short ATH2
  499.  
  500. ATH1:           and     al, 0DFh        ;convert to upper case - strip bit 6
  501.                 sub     al, 'A'-10
  502.  
  503. ATH2:           dec     cx
  504.                 jcxz    ATH3            ;jump out on second pass
  505.                 push    cx              ;save pass count
  506.                 mov     cl, 4           ;shift into upper nibble
  507.                 shl     al, cl
  508.                 pop     cx
  509.                 cmp     cx, 0
  510.                 ja      ATH0
  511.  
  512. ATH3:           and     ah, 0F0h         ;mask high nibble
  513.                 or      al, ah          ;put them together
  514.  
  515.                 ret
  516. EndP            AsciiToHexByte
  517.  
  518. ;------------------------------------------------------------------------
  519. ;    Close the Socket
  520. ;------------------------------------------------------------------------
  521.  
  522. Proc        CloseMySocket
  523.  
  524.         mov    bx, 01h        ;Close Socket
  525.         mov    dx, [MySocket]
  526.         call    [cs:IPXEntry]
  527.          ret
  528.  
  529. EndP        CloseMySocket
  530.  
  531.  
  532.         End    Start
  533.