ld returned 1 exit status这个错误怎么解
#include<sys/types.h>//#include<sys/socket.h>
//#include<netinet/in.h>
//#include<netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <WinSock2.h>
#define PORTNUMBER 333
#pragma comment(lib,"ws2_32.lib")
#define QueueLen 6
int visits = 0;
int main(int argc, char * argv[])
{
WORD version;
version = MAKEWORD(1, 1);
WSADATA wsa;
if(0 != WSAStartup(version, &wsa)){ //初始化socket()
printf("WSAStartup error!\n");
exit(0);
}
// struct hostent * ptrh;
struct sockaddr_in servaddr;
struct sockaddr_in clientaddr;
int listenfd;
int clientfd;
int port;
int alen;
char buf[1000];
memset(&servaddr, 0, sizeof(servaddr)); //初始化servaddr为0
servaddr.sin_family = AF_INET;//主机地址标识的数据结构,使用TCP/IP协议
servaddr.sin_addr.s_addr = INADDR_ANY;//32位的IP地址,网络字节顺序
if(argc > 1){
port = atoi(argv[1]);
} else {
port = PORTNUMBER;
}
if(port > 0){
servaddr.sin_port = htons((unsigned short) port); //把端口转换成网络序
} else {
fprintf(stderr, "bad port number%d\n", argv[1]);
exit(0);
}
listenfd = socket(AF_INET, SOCK_STREAM, IPPROTO_IP ); //注册一个socket description
DWORD error = GetLastError();
if(listenfd < 0){
fprintf(stderr, "socket createion failed!\n");
exit(0);
}
if(bind(listenfd, (struct sockaddr *) & servaddr, sizeof(servaddr)) < 0){//绑定到端口
fprintf(stderr, "bind failed!\n");
exit(0);
}
if(listen(listenfd, QueueLen) < 0){//开始监听端口
fprintf(stderr, "listen failed!\n");
exit(0);
}
while(1){//主循环
alen = sizeof(clientaddr);
if((clientfd = accept(listenfd, (struct sockaddr*)&clientaddr, &alen)) < 0){//接受客户端的连接
fprintf(stderr, "accept failed!\n");
exit(0);
}
printf("连接成功!!!!");
visits++;
sprintf(buf, "This server has been connected %d time\n", visits);//把需要发送的数据放到缓冲区里面
send(clientfd, buf, strlen(buf), 0);//发送数据到客户端
closesocket(clientfd);
}
return 0;
}