Hey,
Almost done porting my httpd from linux to windows (well, the code is already ported, just got to get the damn thing to work

).
Problem im having, im using winsock, with the unix-style function (socket,accept), not the WSA* ones. But when i run the program, it crashes.
So, i put it into a debugger, and run it. And it ends up that when it calls socket, where it jumps to, doesnt seem to be real code, looks more like data than anything else. And if i read the data there, it actually shows: KERNEL32.DLL, ws2_32.dll, and then some more data, then the functions i use in my program.. So does this mean my program is actually jumping to my .idata section rather than the actual function?
PS: Ive tried using both wsock32.dll and ws2_32.dll (the latter is the one they tell you to use on msdn, the other i found lying around in my system folder so tried it out in case it was something wrong with the dll).
Oh, and the code, in case you can see anything i did wrong:
format PE console
use32
include 'F:\windows\system32\include\win32a.inc'
macro tcpsend msg,msglen
{common
pushd 0 msglen msg [peer]
call send
}
section '.code' code readable executable
pushd 2 1 2
call socket
mov [sockfd], eax
pushd 16 bindparams [peer]
call bind
pushd 10 [sockfd]
call listen
acceptie:
pushd sixteen peeraddr [sockfd]
call accept
mov dword [peer], eax
pushd 0 bufferlen buffer [peer]
call recv
mov ebx, buffer
cmp dword [ebx], 'GET '
jne endpeer
xor ecx, ecx
.1:
inc ebx
cmp byte [ebx], '/'
je @f
jmp .1
.2:
@@:
inc ebx
cmp byte [ebx], ' '
je @f
cmp byte [ebx], '%'
je .hex
mov al, [ebx]
mov [buffer+ecx], al
inc ecx
jmp @b
@@:
mov byte [buffer+ecx], 0
push ecx
jmp @f
.hex:
inc ebx
mov dx, [ebx]
mov word [fd], dx
mov word [fd+2], 0
mov edi, fd
push ebx
mov ebx, 16
call StrToInt
pop ebx
mov [buffer+ecx], al
inc ebx
inc ecx
jmp .2
;stat
statf:
@@:
pushd 0 buffer
call GetFileSize
cmp eax, 0
je @f
tcpsend h404,h404.len
jmp endpeer
@@:
mov [fdlen], eax
open:
@@:
pushd 0 0 0 0 1 0 buffer
call CreateFile
mov [fd], eax
mov eax, [fdlen]
mov ebx, 10
mov edi, inuse
call IntToStr
sub edi, inuse
mov dword [inuse+edi-1], 0x0a0d0a0d
add edi, h200.len+3
mov [transbuffers+4], edi
pushd 0 transbuffers 0 0 0 [fd] [peer]
call TransmitFile
pushd [fd]
call CloseHandle
endpeer:
exit:
pushd [peer]
call CloseHandle
jmp acceptie
IntToStr:
; eax = number, ebx = base, edi = buffer
push ecx edx
xor ecx,ecx
.new:
xor edx,edx
div ebx
push edx
inc ecx
test eax,eax
jnz .new
.loop:
pop eax
add al,30h
cmp al,'9'
jng .ok
add al,7
.ok:
stosb
loop .loop
mov al,0
stosb
pop edx ecx
ret
StrToInt:
; edi = buffer, ebx = base
push edx edi
xor eax,eax
xor edx,edx
.loop:
mov dl,byte [edi]
test dl,dl
jz .end
imul eax,ebx
sub dl,'0'
cmp dl,9
jle .ok
sub dl,7
.ok:
add eax,edx
inc edi
jmp .loop
.end:
pop edi edx
ret
section '.data' data readable writeable
h404 db 'HTTP/1.1 404 Not Found',13,10,13,10,'<HTML><HEAD><TITLE>404 Not Found</TITLE></HEAD><BODY><H1>File Not Found</H1></BODY></HTML>',10,13
.len = $ - h404
h200 db 'HTTP/1.1 200 OK',13,10,'Content-Length: '
.len = $ - h200
inuse db 'Port already in use, exiting..',10
.len = $ - inuse
bindparams dw 2, 80
dd 0, 0, 0
transbuffers dd h200,0,0,0
peeraddr rb 16
sixteen dd 16
sockfd rd 1
peer rd 1
fd rd 1
fdlen rd 1
buffer rb 512
bufferlen = $ - buffer
section '.idata' import data readable writeable
library kernel32,'KERNEL32.DLL',\
wsock32,'ws2_32.dll',\
mswsock,'mswsock.dll'
import mswsock,\
TransmitFile,'TransmitFile'
include 'F:\windows\system32\include\apia\kernel32.inc'
include 'F:\windows\system32\include\apia\wsock32.inc'
[edit]Forgot the section '.code', added that in, didnt help though[/edit]
Thanks,
gunblade