Forum

> > Off Topic > LuaJIT running WinSock API
Forums overviewOff Topic overviewLog in to reply

English LuaJIT running WinSock API

1 reply
To the start Previous 1 Next To the start

old LuaJIT running WinSock API

Starkkz
Moderator Off Offline

Quote
Hello, so I'm trying to build a sockets module for LuaJIT using the WinSock API with FFI. But I'm having problems with the function getsockname.

bnet.lua
http://pastebin.com/dBQF49RH

socket_wrapper.lua
http://pastebin.com/8WacRqCc

I'm supposed to have setup the Windows Sockets API properly, so I'd discard that option as a problem.
1
2
3
local ws = ffi.new("WSADATA")
sock.WSAStartup(0x101, ws)
ffi.C.atexit(sock.WSACleanup)

Every time I run the code, it gets stuck on the error given on getsockname (line 441 from bnet.lua), the given error results WSAEFAULT, I could discard that the problem is the "namelen" field because it's using the original size of the object SAddress (line 440 from bnet.lua). Considering that there were no errors when I had setup the socket and bound it, I assume that the problem has something to do with the object casted (line 438 and 439 from bnet.lua) which leaves me without ideas of what could be the actual problem. I tried to print these objects to see if they're null pointers, but they're not.

Has anyone worked with WinSock API before, or at least knows how to use LuaJIT's FFI module? I really appreciate your help if you do, I don't know anyone else who could solve this.

old Re: LuaJIT running WinSock API

MikuAuahDark
User Off Offline

Quote
(at bnet.lua) replace line 440 with this
1
local SizePtr = ffi.new("int[1]");
then add
1
SizePtr[0]=ffi.sizeof(SAddress);
after line 440

Well, afterwards it gives me this error
1
2
3
4
5
6
7
8
9
unable to convert argument 1 from cdata<struct in_addr> to cdata<uint64_t>
stack traceback:
        [C]: in function 'ntohl'
        .\socket_wrapper.lua:314: in function 'ntohl_'
        .\bnet.lua:456: in function 'CreateTCPServer'
        .\bnet.lua:508: in main chunk
        [C]: in function 'require'
        stdin:1: in main chunk
        [C]: ?

I'm using Lua 5.1.4 with FFI library
To the start Previous 1 Next To the start
Log in to replyOff Topic overviewForums overview