1

I extracted a program from a stackoverflow answer and tried to compile it, using the MSVC++ V6 IDE, but the compiler complained that I don't have any of the following .h include files:

 #include <sys/socket.h>
 #include <netinet/in.h>
 #include <arpa/inet.h>
 #include <net/if.h>
 #include <ifaddrs.h>
 #include <errno.h>

How do get these missing include files?

Community
  • 1
  • 1
CC_Fingers
  • 29
  • 4
  • Most probably, because of not using `gcc` to run your program. I'm not a fan of MSVC and Windows based development, but you can compile the program by installing `Mingw-w64` on Windows using this [link](https://mingw-w64.org/doku.php/download). – hmofrad Jan 02 '17 at 08:06
  • duplicate of: – user3629249 Jan 03 '17 at 18:51

2 Answers2

2

The header files which you mentioned above are related to linux based distribution. These are used for socket programming on linux. You can easily run this code on a linux based distro.

Learner
  • 67
  • 7
0

The missing header files are unix/linux headers.

The Windows socket API is slightly different from the Berkely socket API (sockets in Linux). In Windows, most declarations needed are available through a single include file, either the old winsock.h or the newer winsock2.h.

You will need to do some further modifications to port your code. There are good guides on porting socket applications to Winsock on MSDN.

Klas Lindbäck
  • 33,105
  • 5
  • 57
  • 82
  • When I put together a "C"/CPP program, I will usually put in a standard set of default includes. Such as: #include #include #include #include #include #include #include And maybe following: #include #include #include – CC_Fingers Jul 24 '22 at 21:28