Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


Cannot open include file: 'sys/socket.h'

Posted on 2005-03-13
Medium Priority
Last Modified: 2013-11-18
I am trying to compile a program that i downloaded from a site. The error i keep getting is Cannot open include file: 'sys/socket.h'. I can't find this file anywhere on the system. I am trying to use Microsoft Developer Studio. I was searching google and i found that someon mentioned that WINSOCK2.H is the same thing and that i just need to rename the entry in the code. Is this correct information? Another file that says is missing is Could not find the file netinet/tcp.h. I there another utility that I can purchase that has these files in it already? So i don't have to go searching for files?
Question by:plimpias
LVL 55

Accepted Solution

Jaime Olivares earned 300 total points
ID: 13530836
If you are trying to compile a MFC application, just create a new project with the AppWizard, it will ask you if you want Sockets support, and will generate proper include files (#include "afxsock.h") and libraries.

LVL 55

Expert Comment

by:Jaime Olivares
ID: 13530846
I you are not generating MFC applications, you can #include "winsock2.h" file, and you will have to link ws2_32.lib library.

Assisted Solution

Kipski earned 300 total points
ID: 13530849
Here is some information for you:


You can copy the source from one of these and create the file yourself....

See how you get on.....

*Note I dont know about renaming WINSOCK2.H...  Sounds doubious to me....  If you are going to try it, i suggest you copy WINSOCK2.H and rename the copy to play it safe....
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.


Expert Comment

ID: 13530857
Yes, changing the name of the file you are including would be better than renaming the file...  Other STL components will be looking for WINSOCK2.H....
LVL 86

Assisted Solution

jkr earned 300 total points
ID: 13531529
I've always used

#ifndef WIN32
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <windows.h>
#include <winsock.h>
#pragma comment(lib,"ws2_32.lib")

for programs that should work on both MS and non-MS platforms.
LVL 39

Assisted Solution

itsmeandnobodyelse earned 300 total points
ID: 13532831
I used the same includes as jkr with one exception winsock2.h instead of winsock.h.

The corresponding library in Windows is wsock32.lib and usually I add it to the object/library modules in the Linker Settings.

Regards, Alex

Assisted Solution

MadAboutYou earned 300 total points
ID: 13536894
Keep in mind too, that when M$ did their implementation of sockets they did not provide the full set of functionality, or at least not the "transparency" that U*X does for sockets (where a file descriptor is a file descriptor, whether a socket, file, pipe, or device).

Hence you will likely need to modify other pieces of the code to work on MSW -- to handle the SOCKET handle different from the 'int' file descriptor.   If I'm remembering correctly, then things like write() and read() don't work on a SOCKET and you must use send() and recv() ... and close() isn't sufficient, you must do, um, something else.

Good luck.
LVL 55

Expert Comment

by:Jaime Olivares
ID: 13901756
No asker feedback info.... Any resolution should consider no points refund...

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Shoutout to Emily Plummer (http://www.experts-exchange.com/members/eplummer26.html) for giving me this article! She did most of it, I just finished it up and posted it for her :)    Introduction In a previous article (http://www.experts-exchang…
I found this questions asking how to do this in many different forums, so I will describe here how to implement a solution using PHP and AJAX. The logical flow for the problem should be: Write an event handler for the first drop down box to get …
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.
Suggested Courses

581 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question