Expand|Select|Wrap|Line Numbers
- #include <stdio.h>
- #include <string.h>
- #include <unistd.h>
- #include <sys/types.h>
- #include <Winsock2.h>
- #include <stdlib.h>
- #define PORTNUM 2343
- int main(int argc, char *argv[])
- {
- char msg[] = "Hello World !\n";
- struct sockaddr_in dest; /* socket info about the machine connecting to us */
- struct sockaddr_in serv; /* socket info about our server */
- int mysocket; /* socket used to listen for incoming connections */
- int socksize = sizeof(struct sockaddr_in);
- memset(&serv, 0, sizeof(serv)); /* zero the struct before filling the fields */
- serv.sin_family = AF_INET; /* set the type of connection to TCP/IP */
- serv.sin_addr.s_addr = INADDR_ANY; /* set our address to any interface */
- serv.sin_port = htons(PORTNUM); /* set the server port number */
- mysocket = socket(AF_INET, SOCK_STREAM, 0);
- /* bind serv information to mysocket */
- bind(mysocket, (struct sockaddr *)&serv, sizeof(struct sockaddr));
- /* start listening, allowing a queue of up to 1 pending connection */
- listen(mysocket, 1);
- int consocket = accept(mysocket, (struct sockaddr *)&dest, &socksize);
- while(consocket)
- {
- printf("Incoming connection from %s - sending welcome\n", inet_ntoa(dest.sin_addr));
- send(consocket, msg, strlen(msg), 0);
- }
- close(consocket);
- close(mysocket);
- return EXIT_SUCCESS;
- }
When i try to compile i get the following error:
[Linker error] undefined reference to `htons@4'
[Linker error] undefined reference to `socket@12'
[Linker error] undefined reference to `bind@12'
[Linker error] undefined reference to `listen@8'
[Linker error] undefined reference to `accept@12'
How do i get rid of this error.
Any help will be appreciated . Thanks in advance.
I have installed dev c++ on my windows machine, and have tried to compile the code.