请写一个 linux下 监听socket 让后发thread的c程序

来源:百度知道 编辑:UC知道 时间:2024/05/30 18:51:19
请写一个 linux下 监听socket 让后发thread的c程序

#include <sys/stat.h>
#include <fcntl.h>
#include <errno.h>
#include <netdb.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#define SIZE 10240
char *site="166.111.107.7";
void printusage()
{
printf("please enter the domain port filename \n \n");
}
int sendfile(const char *ip, char *file, int port){
char buf[SIZE];
int s,k;
struct hostent *hp;
struct sockaddr_in addr;
hp=gethostbyname(ip);
if (hp==NULL)
{
perror( "hostent error" );
return -2;
}
if((s=socket(AF_INET,SOCK_STREAM,0))<0){
perror( "socket error" );
return( -1 );
}
memset(&addr,0,sizeof(struct sockaddr_in));
a