MASM:取消引用struct指针两次?

时间:2015-08-08 22:22:28

标签: sockets x86 undefined masm

我一直在使用MASM再次涉足x86程序集,并遇到了一个小障碍。期待从纯粹的享受中重新发明轮子。

    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 

问题似乎是h_addr_list是char **,而h_name是char *。引发的错误是:

error A2006: undefined symbol : h_addr_list

hostent结构的定义是:

    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;

1 个答案:

答案 0 :(得分:1)

我强烈怀疑您使用的是 MASM32 并且有这样一行:

include \masm32\include\windows.inc

windows.inc 包含HOSTENT结构:

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

将其与:

进行比较
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;

您会注意到h_addr_list windows.inc 中定义为h_list。您可以修改 windows.inc 并重命名h_list,也可以修改代码以引用h_list而不是h_addr_list。我会做后者,因为它会使你的代码与其他人使用 MASM32 保持兼容。

还应该清楚的是,其他一些字段的命名也有所不同。