我正在尝试使用masm32创建一个“套接字”,但是接受()有问题,当代码尝试执行accept()并且我不知道什么是错误时,ollydbg向我显示访问冲突有人可以告诉我如何解决它,好吗?
.686
.model flat, stdcall
option casemap:none
extrn ExitProcess@4:PROC
extrn WSAStartup@8:PROC
extrn socket@12:PROC
extrn bind@12:PROC
extrn listen@8:PROC
extrn accept@12:PROC
WSADATA STRUCT 8
wVersion WORD ?
wHighVersion WORD ?
iMaxSocket WORD ?
iMaxUdpDg WORD ?
lpVendorInfo DWORD ?
szDescription SBYTE 257 dup (?)
szSystemStatus SBYTE 129 dup (?)
WSADATA ENDS
sockaddr STRUCT
sa_family WORD ?
sa_port WORD ?
sa_addr DWORD ?
BYTE 8 dup (?)
sockaddr ENDS
.const
address sockaddr<2, 0B922h, 00000000h>
sbuff BYTE 50 dup (0)
.data?
wsadata WSADATA <>
Socket DWORD ?
.code
Start proc
push ebp
mov ebp, esp
lea edx, wsadata
push edx
push 2h
call WSAStartup@8
push 0h
push 1h
push 2h
call socket@12
mov Socket, eax
push 16h
lea ecx, address
push ecx
push Socket
call bind@12
push 1h
push Socket
call listen@8
push 16h
lea ecx, address
push ecx
push Socket
call accept@12
mov eax, 0
call ExitProcess@4
mov esp, ebp
pop ebp
Start endp
END
问候
答案 0 :(得分:0)
访问的第三个参数是指向长度的指针,而不是长度本身。
顺便说一下:结构是16(十进制),而不是16h字节长。
因此,您的代码应如下所示:
.data?
wsadata WSADATA <>
Socket DWORD ?
addrlen DWORD 10h <- This one is new!
.code
...
push 10h <- Instead of 16h
...
call bind@12
...
lea ecx, addrlen
push ecx
lea ecx, address
push ecx
push Socket
call accept@12