|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Error E2209 Server.cpp 6: Unable to open include file 'unistd.h'
Error E2209 Server.cpp 10: Unable to open include file 'sys/socket.h' Error E2209 Server.cpp 11: Unable to open include file 'netinet/in.h' Error E2209 Server.cpp 12: Unable to open include file 'arpa/inet.h' Error E2209 Server.cpp 13: Unable to open include file 'sys/wait.h' can any one send me these header files regards |
|
#2
|
|||
|
|||
|
can you show us some code?...what u are working on
|
|
#3
|
|||
|
|||
|
i m trying to compile Server.cpp of Beej's Network Programming Guide.
|
|
#4
|
|||
|
|||
|
/*
** server.c - a stream socket server demo */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <errno.h> #include <string.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/wait.h> #include <signal.h> #define MYPORT 3490 // the port users will be connecting to #define BACKLOG 10 // how many pending connections queue will hold struct sockaddr { unsigned short sa_family; // address family, AF_xxx char sa_data[14]; // 14 bytes of protocol address }; struct sockaddr_in { short int sin_family; // Address family unsigned short int sin_port; // Port number struct in_addr sin_addr; // Internet address unsigned char sin_zero[8]; // Same size as struct sockaddr }; void sigchld_handler(int s) { while(wait(NULL) > 0); } int main(void) { int sockfd, new_fd; // listen on sock_fd, new connection on new_fd struct sockaddr_in my_addr; // my address information struct sockaddr_in their_addr; // connector’s address information int sin_size; struct sigaction sa; int yes=1; if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { perror("setsockopt"); exit(1); } 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 = INADDR_ANY; // automatically fill with my IP memset(&(my_addr.sin_zero), ’\0’, 8); // zero the rest of the struct if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))== -1) { perror("bind"); exit(1); } if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } sa.sa_handler = sigchld_handler; // reap all dead processes sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) == -1) { perror("sigaction"); exit(1); } while(1) { // main accept() loop sin_size = sizeof(struct sockaddr_in); if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) { perror("accept"); continue; } printf("server: got connection from %s\n", inet_ntoa(their_addr.sin_addr)); if (!fork()) { // this is the child process close(sockfd); // child doesn’t need the listener if (send(new_fd, "Hello, world!\n", 14, 0) == -1) perror("send"); close(new_fd); exit(0); } close(new_fd); // parent doesn’t need this } return 0; } |
|
#5
|
|||
|
|||
|
it means your compiler is missing header files...i just compiled it and i got 1 error....
c:\program files\microsoft visual studio\myprojects\hello\hello.cpp(3) : fatal error C1083: Cannot open include file: 'unistd.h': No such file or directory Error executing cl.exe. Hello.exe - 1 error(s), 0 warning(s) im not sure where u can find header files....or find a different compiler Last edited by bes : June 29th, 2003 at 02:57 AM. |
|
#6
|
|||
|
|||
|
i m using C++ Borland 5.5 compiler
|
|
#7
|
|||
|
|||
|
im using Visual C++6.0 on debug level 4
|
|
#8
|
||||
|
||||
|
That's cuz they're include files for *NIX systems, such as Linux or FreeBSD. Guess you didn't read the start of Beej's guide too well. You'd probably want to read these sections, especially the second one:
http://www.ecst.csuchico.edu/~beej/...ntro.html#AEN52 http://www.ecst.csuchico.edu/~beej/...ro.html#windows |
|
#9
|
||||
|
||||
|
[sound of palm of my hand slapping my forehead]
Guys, the code was written for UNIX/Linux. You're using Windows. This is why you should always indicate what OS you're using and why most first replies you get ask you for the OS. In particular, these lines are very specific to Unix/Linux: #include <unistd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> #include <arpa/inet.h> #include <sys/wait.h> #include <signal.h> Two features in that program and that are very much tied to UNIX/Linux and which Windows does not support is forking new processes and handling signals. You might be able to emulate signal handling with Windows Messages, but creating processes in Windows appears to be very different from forking and I have no idea what kind of interprocess communication (IPC) Windows supports. But the sockets part is directly translatable to Windows. Most of the include files (except for signal.h and wait.h) are replaced by winsock.h. The rest of the procedure, including how to create a console app in Visual C++6, is described in the PDF file, "Transitioning from UNIX to Windows Socket Programming" by Paul O'Steen at http://cs.baylor.edu/~donahoo/pract...dowsSockets.pdf . It and some working winsock code are available through the website for the book, "The Pocket Guide to TCP/IP Sockets: C Version", at http://cs.baylor.edu/~donahoo/PocketSocket/ . You might also want to refer to the Winsock Programmer's FAQ at http://tangentsoft.net/wskfaq/ for more information about winsockand the differences between winsock programming and UNIX sockets programming. The bottom line is that sockets programming in Windows requires using Winsock. Fortunately Winsock supports most (if not all) sockets functions, so most UNIX sockets code can be ported to Windows/Winsock with just a few changes (as described in O'Steen's PDF file). The only real problem is when the UNIX code contains features that are very UNIX-specific, like forking, pipes, signals, etc. If the UNIX code uses multithreading, then you should be able to replace it with Win32 multithreading, but the functions are different so you will need to rewrite that part of the program. Last edited by dwise1_aol : June 29th, 2003 at 11:27 AM. |
|
#10
|
|||
|
|||
|
now tell me the problem here
code ---------------------------------------------------------------------------------------------- #include <stdio.h> #include <stdlib.h> #include <errno.h> #include <signal.h> #include <winsock.h> #define MYPORT 3490 #define BACKLOG 10 void sigchld_handler(int s) { while(wait(NULL) > 0); } int main(void) { int sockfd, new_fd; struct sockaddr_in my_addr; struct sockaddr_in their_addr; int sin_size; struct sigaction sa; int yes=1; WSADATA wsaData; if (WSAStartup(MAKEWORD(3, 0), &wsaData) != 0) { fprintf(stderr, "WSAStartup failed.\n"); exit(1); } if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) { perror("socket"); exit(1); } if (setsockopt(sockfd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int)) == -1) { perror("setsockopt"); exit(1); } my_addr.sin_family = AF_INET; my_addr.sin_port = htons(MYPORT); my_addr.sin_addr.s_addr = INADDR_ANY; memset(&(my_addr.sin_zero), '\0', 8); if (bind(sockfd, (struct sockaddr *)&my_addr, sizeof(struct sockaddr))== -1) { perror("bind"); exit(1); } if (listen(sockfd, BACKLOG) == -1) { perror("listen"); exit(1); } sa.sa_handler = sigchld_handler; // reap all dead processes sigemptyset(&sa.sa_mask); sa.sa_flags = SA_RESTART; if (sigaction(SIGCHLD, &sa, NULL) == -1) { perror("sigaction"); exit(1); } while(1) { sin_size = sizeof(struct sockaddr_in); if ((new_fd = accept(sockfd, (struct sockaddr *)&their_addr, &sin_size)) == -1) { perror("accept"); continue; } printf("server: got connection from %s\n", inet_ntoa(their_addr.sin_addr)); if (!fork()) { close(sockfd); if (send(new_fd, "Hello, world!\n", 14, 0) == -1) perror("send"); close(new_fd); exit(0); } close(new_fd); // parent doesn’t need this } return 0; } --------------------------------------------------------------------------------------------------- errors are C:\Borland\BCC55\Bin>bcc32.exe Server.c Borland C++ 5.5.1 for Win32 Copyright (c) 1993, 2000 Borland Server.c: Warning W8065 Server.c 12: Call to function 'wait' with no prototype in function sigchld_handler Warning W8057 Server.c 13: Parameter 's' is never used in function sigchld_handler Error E2450 Server.c 35: Undefined structure 'sigaction' in function main Error E2449 Server.c 35: Size of 'sa' is unknown or zero in function main Error E2450 Server.c 35: Undefined structure 'sigaction' in function main Error E2450 Server.c 35: Undefined structure 'sigaction' in function main Error E2449 Server.c 35: Size of 'sa' is unknown or zero in function main Error E2451 Server.c 76: Undefined symbol 'sa_handler' in function main Error E2451 Server.c 77: Undefined symbol 'sa_mask' in function main Warning W8065 Server.c 77: Call to function 'sigemptyset' with no prototype in function main Error E2451 Server.c 78: Undefined symbol 'sa_flags' in function main Error E2451 Server.c 78: Undefined symbol 'SA_RESTART' in function main Error E2451 Server.c 80: Undefined symbol 'SIGCHLD' in function main Warning W8065 Server.c 80: Call to function 'sigaction' with no prototype in function main Warning W8065 Server.c 99: Call to function 'fork' with no prototype in function main *** 10 errors in Compile *** plz guide me |
|
#11
|
||||
|
||||
|
This is still at least a mix of unix/linux code.
Windows does not support fork, at least as far as I know. |
|
#12
|
||||
|
||||
|
No, Windows does not support fork. Nor does it support signals. Those are both UNIX/Linux-specific.
However, you can do multithreading in Windows 95 and up (I'm not sure which version of NT started supporting it), AKA "Win32". Win32 features are also available in Win32 console applications, AKA "DOS" (not to be confused with the earlier "DOS Classic"). For the second time, the web site for the book, "The Pocket Guide to TCP/IP Sockets: C Version", at http://cs.baylor.edu/~donahoo/PocketSocket/ also has working Winsock adaptations of the book's example source code. That includes a multithreaded TCP server, TCPEchoServer-ThreadWS. You should download the Winzip archive of the source code, since each project consists of multiple source files. The page they are on, http://cs.baylor.edu/~donahoo/PocketSocket/winsock.html , even points out which of the book's UNIX programs could not be converted to Winsock because Windows does not support forking or signals. BTW, if your server will only serve one client at a time, then there should be no need for multithreading (I didn't mention forking processes since that is not an option). Or you could handle multiple sockets by using the select() function. The above-mentioned book site also has a server that uses select(), TCPEchoServer-SelectWS. Last edited by dwise1_aol : July 1st, 2003 at 10:00 AM. |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > C Programming > header files |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|