fatal error: netinet/in.h: No such file or directory

回眸只為那壹抹淺笑 提交于 2020-12-13 07:04:43

问题


[SOCKET PROGRAMMING] [UDP SERVER]

I am trying to do Message encryption and decryption using UDP server. Code is here: https://www.geeksforgeeks.org/message-encryption-decryption-using-udp-server/ But I am getting the following error:

fatal error: netinet/in.h: No such file or directory

How to resolve this issue?


回答1:


For the socket stuff on Windows you need #include <winsock2.h> and you will also need to link with -lws2_32.

In the beginning of your program you will also need to initialize the library like this:

static WSADATA wsaData;
int wsaerr = WSAStartup(MAKEWORD(2, 0), &wsaData);
if (wsaerr)
  exit(1);

and clean before exiting like this:

WSACleanup();

For the rest most basic networking functions are the same as on *nix platforms, except for close() which doesn't work on sockets, so you will need to do closesocket() instead.



来源:https://stackoverflow.com/questions/62170418/fatal-error-netinet-in-h-no-such-file-or-directory

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!