• C

Easy Question... Where do you get header files from?

I'm new to c, and I've been trying to compile some sample programs, and I can't seem to find where header files such as:

#include sys/types.h
#include sys/socket.h
#include netdb.h
#include netinet/in.h

These seem to be the basic for networking programs, but where do I get them from? I am using MS Visual C++

Thanks!
 

MetalManiacAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

akshayxxCommented:
it seems the source code that u r trying to compile is meant for UNIX and other similar systems..
for networking programs on windows .. there different include headers and linking libraries...
OR u'll have to get hold of something like cygwin/mingw32
0
akshayxxCommented:
btw on linux and other UNIces these headers are usually placed in the directory
/usr/include

0
MetalManiacAuthor Commented:
Will cygwin or mingw32 have these headers, and if so, will they work in visual c++?  Or will i have to compile with those programs?
0
Become an IT Security Management Expert

In today’s fast-paced, digitally transformed world of business, the need to protect network data and ensure cloud privacy has never been greater. With a B.S. in Network Operations and Security, you can get the credentials it takes to become an IT security management expert.

MetalManiacAuthor Commented:
Will cygwin or mingw32 have these headers, and if so, will they work in visual c++?  Or will i have to compile with those programs?
0
akshayxxCommented:
i have doubt they will work with visual c++ as it is ..
but cygwin etc come with gcc/g++ .. which is another C/c++ compiler , till that do ,, and why do u want to go with the given source code ... why dont u have a look at winsock examples..?
0
r_a_j_e_s_hCommented:
Hi,
   u should use winsock header for MS Visual C++ . u should add the ws2_32.lib library in project(menu)-settings-link . try the following code .


if u have any doubt contact me at r_a_j_e_s_h_a@yahoo.co.in

bye

rajesh


Sample:--
(this is a rough code. i didn't test it .)


#include<windows.h>
#include<winsock.h>
#include<stdio.h>

void main()
{
     WSADATA WSAData;  
     struct sockaddr_in  serv;
     char senddata[1000],aa[20];
     LPTSTR lpszSystemInfo1,lpszSystemInfo2;  

     WSAStartup (MAKEWORD(1,1), &WSAData);
     sockfd=socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
     
     serv.sin_family=AF_INET;
     serv.sin_port=htons(3333);
     serv.sin_addr.s_addr=inet_addr("127.0.0.1");


     ret=connect(sockfd,(struct sockaddr*)&serv,sizeof(serv));

     ret=send(sockfd,senddata,lstrlen(senddata) + 1,0);

}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GetchCommented:
<sys/socket.h> and some others is for unix socket programming in C for windows socket programming in C/C++ use winsock.h winsock2.h
0
Mayank SAssociate Director - Product EngineeringCommented:
>> #include sys/types.h

Excuse my ignorance (if it is so), but is there any compiler which will allow you to specify the name of a header-file in the #include directive without <> or "" as <stdio.h> or "MyFile.h" ??

Mayank.
0
akshayxxCommented:
>>Excuse my ignorance (if it is so),

hehe :)
0
Mayank SAssociate Director - Product EngineeringCommented:
:-)

No compiler would allow: #include sys/types.h

without the angular-braces or quotes, would it :-)

Mayank.
0
akshayxxCommented:
>>No compiler would allow: #include sys/types.h

u always have option to write your own compiler ..
:-)
0
Mayank SAssociate Director - Product EngineeringCommented:
Please.... the Compiler Design lab is history now, and I don't wanna think about it again :-))

0
jmcgOwnerCommented:
Nothing has happened on this question in more than 9 months. It's time for cleanup!

My recommendation, which I will post in the Cleanup topic area, is to
accept answer by r_a_j_e_s_h.

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.