I'm attempting to make a script that lets my game communicate with a wireless device via the Winsock API. I'm starting out with existing networking scripts such as those in Blizzard's RMXP Online System, which provide me with most of the Socket class. However, I want to use the getsockname function so I can get the address of the socket the script uses, and I'm having problems implementing it successfully (being inexperienced with integrating Windows API functions). Here is the Winsock getsockname function syntax:
This is what I have so far:
where Socket#fd is the pointer returned by Winsock::socket in Socket's constructor.
When I run the code, I get error 10014 (WSAEFAULT). Microsoft says this error is caused by sockaddr or namelen being invalid pointers, or due to namelen being too small.
I'm pretty sure it's something to do with how I'm calling the API, but I'm stumped as to what I need to do to fix it. Can anyone help me out?
Code:
int getsockname(
__in SOCKET s,
__out struct sockaddr *name,
__inout int *namelen
);
Code:
module Winsock
Win32API_getsockname = Win32API.new(DLL, "getsockname", "ppl", "l")
def self.getsockname(*args)
Win32API_getsockname.call(*args)
end
end
class Socket
def getsockname
sockaddr = "\0" * 256
SocketError.check if (Winsock.getsockname(@fd, sockaddr, 256) == -1)
sockaddr
end
end
When I run the code, I get error 10014 (WSAEFAULT). Microsoft says this error is caused by sockaddr or namelen being invalid pointers, or due to namelen being too small.
I'm pretty sure it's something to do with how I'm calling the API, but I'm stumped as to what I need to do to fix it. Can anyone help me out?