Assembly code snippets
Details
Title | IPADDR & PORTNR macros |
---|---|
Author | Thomas |
Submitted by: | Thomas |
Date added: | 2002-02-17 19:04:17 |
Date modified: | 2002-02-17 19:04:17 |
Comments
These two macros return an IP address or port number in network byte order. It directly returns the value (DWORD for IP, WORD for port) with EXITM, no actual code is generated.Usage examples:
mov eax, IPADDR(127,0,0,1) ; ip address localhost (127.0.0.1).
mov somstruct.someval, PORTNR(80) ; http port 80.
Snippet
; Returns IP address as DWORD in network byte order
; Usage: IPADDR(192,168,0,1)
; by Exagone [Thomas Bleeker]
IPADDR MACRO IPP1:REQ,IPP2:REQ,IPP3:REQ,IPP4:REQ
LOCAL @val
@val = IPP1 + (IPP2 SHL 8) + (IPP3 SHL 16) + (IPP4 SHL 24)
EXITM <&@val>
ENDM
; Returns port number as WORD in network byte order
; Usage: PORTNR(1234)
; by Exagone [Thomas Bleeker]
PORTNR MACRO PORTNUMBER:REQ
LOCAL @val
@val = (PORTNUMBER SHR 8) + ((PORTNUMBER AND 0FFh) SHL 8)
EXITM <&@val>
ENDM
; Usage: IPADDR(192,168,0,1)
; by Exagone [Thomas Bleeker]
IPADDR MACRO IPP1:REQ,IPP2:REQ,IPP3:REQ,IPP4:REQ
LOCAL @val
@val = IPP1 + (IPP2 SHL 8) + (IPP3 SHL 16) + (IPP4 SHL 24)
EXITM <&@val>
ENDM
; Returns port number as WORD in network byte order
; Usage: PORTNR(1234)
; by Exagone [Thomas Bleeker]
PORTNR MACRO PORTNUMBER:REQ
LOCAL @val
@val = (PORTNUMBER SHR 8) + ((PORTNUMBER AND 0FFh) SHL 8)
EXITM <&@val>
ENDM