致命错误:netinet/in.h:没有那个文件或目录 [英] fatal error: netinet/in.h: No such file or directory
问题描述
[套接字编程] [UDP 服务器]
[SOCKET PROGRAMMING] [UDP SERVER]
我正在尝试使用 UDP 服务器进行消息加密和解密.代码在这里:https://www.geeksforgeeks.org/message-encryption-decryption-using-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
如何解决这个问题?
推荐答案
对于 Windows 上的套接字内容,您需要 #include
并且您还需要与 -lws2_32
.
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();
其余最基本的网络功能与 *nix 平台上的相同,除了 close()
不适用于套接字,因此您需要执行 closesocket()
代替.
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.
这篇关于致命错误:netinet/in.h:没有那个文件或目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!