#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
#include <time.h>
#include <sys/wait.h>
#include <signal.h>
#include <GeoIP.h>
#include "mysql.h"
#define port 8787
struct linger l = { 1, 0 };
int threadCount = 0;
int sockserver = 0;
int sockclient = 0;
int dw_temp;
int acceptPid;
struct sockaddr_in sockaddrserver;
struct sockaddr_in sockaddrclient;
int size;
int yes = 1;
int pid;
struct sigaction sa;
void child();
int main(void)
{
sockserver = socket(AF_INET, SOCK_STREAM, 0);
if (setsockopt(sockserver,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(int))==-1) return 0;
sockaddrserver.sin_family = AF_INET;
sockaddrserver.sin_port = htons(port);
sockaddrserver.sin_addr.s_addr = INADDR_ANY;
memset(&(sockaddrserver.sin_zero), '\0', 8);
if (!sockserver)
{
printf("Error to init socket\n");
return 0;
}
if (bind(sockserver, (struct sockaddr*)&sockaddrserver, sizeof(struct sockaddr))==-1)
{
printf("Error to bind");
return 0;
}
listen(sockserver,SOMAXCONN);
size = sizeof(struct sockaddr);
for (dw_temp=0;dw_temp<20;dw_temp++)
{
acceptPid = fork();
if (!acceptPid)
{
child();
exit(0);
}
}
}
void child()
{
while (1)
{
sockclient = accept(sockserver,(struct sockaddr*)&sockaddrclient,&size);
if (sockclient<=0) continue;
}
}