Zehn 10
Zehn 10

Reputation: 35

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

[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?

Upvotes: 2

Views: 23961

Answers (1)

Brecht Sanders
Brecht Sanders

Reputation: 7287

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.

Upvotes: 3

Related Questions