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

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 304
  • Last Modified:

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!
 

0
MetalManiac
Asked:
MetalManiac
  • 5
  • 3
  • 2
  • +3
1 Solution
 
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

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

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 5
  • 3
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now