Hi all

I need to do some socket programming, what librares do I need to include?
How do I invoke the routins?

best regards
Posted on 2003-07-04 17:20:09 by mistronr1
well, I'm not sure about HLA 1.50, but in previous versions there was no ws2 (winsock v2.x) hhf files included for the function calls, however all the data types, (SOCKET, WSADATA, sock_addr, etc) are defined within w.hhf. So what I did was to add the external procedure declarations of those winsock functions I needed, of course you could add them all, it's all a question spare time ;)

anyway, I included the functions I needed from ws2_32 by adding them to
w.hhf like this:

WSAStartup : procedure
(
wVersionRequested: dword;
lpWSAData: dword
);
@stdcall;
@returns("eax");
@external("__imp__WSAStartup@8");

WSACleanup : procedure;
@stdcall;
@returns("eax");
@external("__imp__WSACleanup@0");

createsocket : procedure
(
iAF: dword;
iType: dword;
iProtocol: dword
);
@stdcall;
@returns("eax");
@external("__imp__socket@12");

etc etc...

ok, as you can see it's not hard to create these external procedure declarations, all you need is a winsock manual that shows you how many call parameters there are for each function (which replaces X in __imp__functionname@X) and wheter or not the function returns anything (don't they always?).

the only problem I ran into when adding these was with the 'socket' function, since it collided with the SOCKET type (hla makes no distinction between upper/lower case names), so I renamed it into createsocket.

also, you will of course have to link ws2_32.lib, like 'hla myprog.hla ws2_32.lib', you find it in the masm/lib directory, copy it to your hlalib directory.

now, you may be confused since there is a wsock32.lib (winsock 1.x) there aswell, but from what I've heard, unless you are running on win95, you are alot better off with winsock 2.x (ws2_32.lib).

ok, I probably explained like crap, so I'm expecting you'll have the same if not even more questions now ;)

"never met an opcode I didn't like."
Posted on 2003-07-05 18:44:20 by BinarySoup
Hi BinarySoup

Thanks for all the help, are you willing to share your w.hhf file, plz plz....

take care & thanks again

Best regards
Posted on 2003-07-06 07:37:20 by mistronr1
ehh sure, but it's no point in sharing the entire file, since all I added was the few socket functions that I needed, you can cut and paste them in yourself before "end w;" at the end of the w.hhf.

here they are, you may very well need other functions, but then you will have to add them yourself ;) Also, note again that I had to change the name of the function 'socket' to 'createsocket' in order to avoid a clash, just so that you don't get confused when reading some source examples from the web. oh, and don't forget to link ws2_32.lib.

WSAStartup : procedure
(
wVersionRequested: dword;
lpWSAData: dword
);
@stdcall;
@returns("eax");
@external("__imp__WSAStartup@8");

WSACleanup : procedure;
@stdcall;
@returns("eax");
@external("__imp__WSACleanup@0");

createsocket : procedure
(
iAF: dword;
iType: dword;
iProtocol: dword
);
@stdcall;
@returns("eax");
@external("__imp__socket@12");

closesocket : procedure
(
s: dword
);
@stdcall;
@returns("eax");
@external("__imp__closesocket@4");

inet_addr : procedure
(
ip: dword
);
@stdcall;
@returns("eax");
@external("__imp__inet_addr@4");

htons : procedure
(
hostshort: dword
);
@stdcall;
@returns("eax");
@external("__imp__htons@4");

htonl : procedure
(
hostlong: dword
);
@stdcall;
@returns("eax");
@external("__imp__htonl@4");

ntohs : procedure
(
netlong: dword
);
@stdcall;
@returns("eax");
@external("__imp__ntohs@4");

ntohl : procedure
(
netlong: dword
);
@stdcall;
@returns("eax");
@external("__imp__ntohl@4");

inet_ntoa : procedure
(
netlong: dword
);
@stdcall;
@returns("eax");
@external("__imp__inet_ntoa@4");

connect : procedure
(
s: dword;
address: dword;
addresslen: dword
);
@stdcall;
@returns("eax");
@external("__imp__connect@12");

recv : procedure
(
s: dword;
buf: dword;
len: dword;
flags: dword
);
@stdcall;
@returns("eax");
@external("__imp__recv@16");

send : procedure
(
s: dword;
buf: dword;
len: dword;
flags: dword
);
@stdcall;
@returns("eax");
@external("__imp__send@16");
Posted on 2003-07-06 10:21:46 by BinarySoup
Thanx alot you made my day BinarySoup...

:alright: now it's time for some socket programming

Best regards all
Posted on 2003-07-06 12:30:25 by mistronr1
no problem, also, if you are new to socket programming, I know that Thomas (nice guy and programmer extraordinaire) threw together an excellent socket tutorial that I read a few months back, it went from the absolute basics up onto connecting etc, maybe there's a new chapter out now, anyway, I don't have the link but I know it's posted on this board somewhere.
Posted on 2003-07-06 23:54:20 by BinarySoup

Hi BinarySoup

Thanks for all the help, are you willing to share your w.hhf file, plz plz....

take care & thanks again

Best regards


Be sure to read Chapter Three of "Windows Programming in Assembly" on Webster. It discusses how to manually translate C header files into assembly so you can easily create your own definitions for API functions that are missing from the HLA header file set. Some day HLA's header files will be more complete, but for now they mainly provide API function definitions for kernel32, user32, gdi32, comctl, and comdlg. Many more to go...
Cheers,
Randy Hyde
Posted on 2003-07-08 16:06:32 by rhyde
Taking notes...:grin:
Posted on 2003-07-14 17:07:59 by LeRoi