[Dev-C++] About headers like socket.h
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Alain P. <ala...@ge...> - 2003-10-28 15:29:31
|
Hi all,
I'm new to dev-cpp, and I need to accept a TCP connection. As I did under
Linux, I will use the bind and accepts functions. But to do that, I need to
include the <sys/socket.h> header file. I did it (see below), but there is
no socket.h file in the include directory of dev-cpp (result : accept_con.c
sys\socket.h: No such file or directory). Here are my questions :
Is there every required headers with Dev-cpp to do network programming ?
Is there every necessary libraries ?
Do I have to download something more to use sockets ?
Best regards, and thank you for any help.
Alain Paschoud
**** Code example below ****
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#define MYPORT 3490
int accept_con()
{
int sockfd;
struct sockaddr_in my_addr;
sockfd = socket(AF_INET, SOCK_STREAM, 0); // do some error checking!
my_addr.sin_family = AF_INET; // host byte order
my_addr.sin_port = htons(MYPORT); // short, network byte order
my_addr.sin_addr.s_addr = htons(INADDR_ANY);
memset(&(my_addr.sin_zero), '\0', 8); // zero the rest of the struct
// don't forget your error checking for bind():
bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr));
/* Accept connection */
accept(sockfd, (struct sockaddr *) &my_addr, sizeof(struct
sockaddr));
}
|