Here are some very simple macros that can be very usefull. The IPADDR macro takes an IP address in comma (!) seperated form like 192,168,0,1 and returns a DWORD with that IP address in network byte order.
PORTNR does the same but for ports (16-bits). They work like the CTXT macro, for example:



mov eax, IPADDR(127,0,0,1)
mov cx, PORTNR(80)




; Returns IP address as DWORD in network byte order
; Usage: IPADDR(192,168,0,1)
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)
PORTNR MACRO PORTNUMBER:REQ
LOCAL @val
@val = (PORTNUMBER SHR 8) + ((PORTNUMBER AND 0FFh) SHL 8)
EXITM <&@val>
ENDM


Thomas
Posted on 2001-12-09 09:38:00 by Thomas
Thomas,

Thank you for these macros! i'll put them to use
in a program i'm starting today.

farrier
Posted on 2001-12-10 01:47:46 by farrier
mov ax,27015
ror ax,8

works for me
Posted on 2002-01-28 20:44:19 by MaX^
MaX^: That takes two instructions while my macro just outputs a constant which can be placed anywhere directly: in a register, in a structure member, as invoke parameter, etc.

Thomas
Posted on 2002-01-29 01:15:11 by Thomas