MASM: call structure pointer twice?

I was building x86 again using MASM and ran into a small roadblock. Looking to reinvent the wheel of pure pleasure.

    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 is that h_addr_list is char ** and h_name is char *. Thrown error:

error A2006: undefined symbol : h_addr_list

      

Definition for host architecture:

    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;

      

+3


source to share


1 answer


I strongly suspect that you are using MASM32 and have the following line:

include \masm32\include\windows.inc

      

windows.inc contains a HOSTENT structure:

hostent STRUCT
  h_name      DWORD      ?
  h_alias     DWORD      ?
  h_addr      WORD       ?
  h_len       WORD       ?
  h_list      DWORD      ?
hostent ENDS

      



Compare this 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 will notice that it h_addr_list

is defined in windows.inc as h_list

. You can either change windows.inc and rename h_list

, or change the code to link h_list

instead h_addr_list

. I would do the latter as it would match your code with others using MASM32.

It should also be clear that some of the other fields are also named differently.

+1


source







All Articles