WinSock2

closed account (S6k9GNh0)
Every single experienced WinAPI user is always snobby. I can't stand it. If I ask a question they act like I'm retarded. For instance, earlier I asked if I my alternate BSD Sockets API, will work with WinSock2. They replied with, "It doesn't matter, just use WinSock instead." Just about pissed off, I did my own research and found little supporting compatibility with BSD Sockets API.

THE QUESTION: If I were to make a program using BSD Sock API style functions, would I be able to simply include the WinSock2 header for a smooth connection on a Windows platform?

I'm a bit new to networking so bear with the terms and possibly the nub1n3ss.
Last edited on
I'm also new when it comes to socket programming so take everything I say with a grain of salt, I however rather than starting with BSD based sockets I immediately started using the Winsock(Despite a few guides warning me that this was a bad idea). There are a few key differences, the first being that you have to link the Winsock2 library file in the projects linker settings, then you have to load the DLL's needed for... it to work correctly I guess, no idea why it doesn't automaticly load them, like I said I'm really new at this.

The command to load the dll is, WSAStartup(http://msdn.microsoft.com/en-us/library/ms742213(VS.85).aspx), to my understanding that has to be called before you can do anything relating to sockets. Next is that there are a few commands that won't run on WinSock(To my understanding, I tried to use them but they didn't work) and you have to use the windows equivalent.

The first one is the inet_pton and inet_ntop instead you use WSAStringToAddress(http://msdn.microsoft.com/en-us/library/ms742214(VS.85).aspx) and WSAAddressToString(http://msdn.microsoft.com/en-us/library/ms741516(VS.85).aspx).

There may be a few other functions that are not included in the WinSock library but I don't know of them. Once you are finished with your socket functions you have to call WSACleanup(http://msdn.microsoft.com/en-us/library/ms741549(VS.85).aspx) before ending the program.

Could I ask where you learned how to work with sockets? I am using a online tutorial but I can't get any of my code to work right, nor do I understand the code.
Last edited on
closed account (S6k9GNh0)
Well, I haven't learned. I understand how the work from examples in code and simple summaries. They aren't the most complex of API's to deal with so it seems. I just can't seem to understand Microsoft strange variation away from a nice uniform API which would allow convenience for everyone. It seems that the Windows port of my program will not have networking until I get around to making the defines and includes.
The short answer is yes. You need to Initialise the winsock library before use and deinitialise it when you're done.

Some things to bear in mind:
1. You should use winsock2 (ws2_32.dll/lib)
2. As Winsock is a seperate library, your socket descriptors will be really high numbers, not normal low values as a kernel based implementation. But despite that, the select stuff works.
3. BPF is not built in, but you can get that functionality in libpcap (that ships with Wireshark).
4. The header files may differ, but the functions are the same.
Last edited on
closed account (S6k9GNh0)
Thank you for helping clear the subject up.
Topic archived. No new replies allowed.