I've been dabbling in x86 assembly again using MASM, and ran into a small roadblock. Looking to reinvent the wheel out of pure enjoyment.
ASSUME eax:PTR hostent
mov ebx, [eax].h_addr_list ;this doesn't compile -- but IDE recognizes hostent.h_addr_list
;I think I need to dereference the pointer twice, but I have no clue how to do that with MASM.
;It sounds silly, yes, but doing the traditional mov eax, [eax] won't solve my compiler error
mov ecx, [eax].h_name ;this compiles just fine
;mov ebx, (hostent PTR [eax]).h_addr_list ;didn't work either.
ASSUME eax:nothing
The problem seems to be that h_addr_list is a char **, while h_name is a char *. The error thrown is:
error A2006: undefined symbol : h_addr_list
The definition for the hostent structure is:
typedef struct hostent {
char FAR *h_name; //note the char FAR *
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list; //note the char FAR FAR **
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
I strongly suspect you are using MASM32 and have a line like this:
include \masm32\include\windows.inc
windows.inc contains the HOSTENT structure:
hostent STRUCT
h_name DWORD ?
h_alias DWORD ?
h_addr WORD ?
h_len WORD ?
h_list DWORD ?
hostent ENDS
Compare that to:
typedef struct hostent {
char FAR *h_name; //note the char FAR *
char FAR FAR **h_aliases;
short h_addrtype;
short h_length;
char FAR FAR **h_addr_list; //note the char FAR FAR **
} HOSTENT, *PHOSTENT, FAR *LPHOSTENT;
You'll notice that h_addr_list is defined in windows.inc as h_list. You could either modify windows.inc and rename h_list or you can modify your code to reference h_list instead of h_addr_list. I would do the latter as it would keep your code compatible with others using MASM32.
It should also be clear that some of the other fields are named a bit differently as well.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With