Sockets in MinGW

后端 未结 7 1296
猫巷女王i
猫巷女王i 2020-12-30 23:26

I was just trying to build netcat in MSYS using MinGW and realized that MinGW never really ported all of the BSD socket stuff to Windows (eg sys/socket.h). I know you can u

7条回答
  •  情话喂你
    2020-12-30 23:57

    These comments from another answer served as the answer I needed to get a piece of simple bsd socket code to compile with mingw on windows.

    Replace all of those includes with #include as that would be the equivalent header for winsock, then see what happens.

    You will also need to link against ws2_32 and use WSAStartup/WSACleanup. Which might get you up and running.

    EDIT: I also ended up having to replace close with shutdown / closesocket and write with send. The code compiled fine but didn't actually work without those additional changes.

提交回复
热议问题