?
Solved

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

Posted on 2005-03-13
10
Medium Priority
?
5,464 Views
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?
0
Comment
Question by:plimpias
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
10 Comments
 
LVL 55

Accepted Solution

by:
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.

0
 
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.
0
 
LVL 3

Assisted Solution

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

http://www.opengroup.org/onlinepubs/007908799/xns/syssocket.h.html
http://shoe.bocks.com/net/socket-h.html
http://sprg.ssl.berkeley.edu/~fastops/ITOS/portable/sys$2fsocket.h.html
http://www.die.net/doc/linux/include/sys/socket.h
http://www.bgnett.no/~giva/watt-doc/a01425.html

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....
0
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
LVL 3

Expert Comment

by:Kipski
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....
0
 
LVL 86

Assisted Solution

by:jkr
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>
#else
#include <windows.h>
#include <winsock.h>
#pragma comment(lib,"ws2_32.lib")
#endif

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

Assisted Solution

by:itsmeandnobodyelse
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
0
 
LVL 1

Assisted Solution

by:MadAboutYou
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.
0
 
LVL 55

Expert Comment

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

Featured Post

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

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…
Introduction Knockoutjs (Knockout) is a JavaScript framework (Model View ViewModel or MVVM framework).   The main ideology behind Knockout is to control from JavaScript how a page looks whilst creating an engaging user experience in the least …
The viewer will be introduced to the technique of using vectors in C++. The video will cover how to define a vector, store values in the vector and retrieve data from the values stored in the vector.
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
Suggested Courses

800 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