- 论坛徽章:
- 0
|
我的服务器测试程序要实现客户端connect以后,send一串字符告诉客户端已连接,但是我编译以后,提示
undefined symbol :socket,bind,listen,accept,inet_ntoa,send
first referenced in file:serv.o
i386ld fatal:Symbol referencing errors.No output written to a.out
好像是说标识符未定义,搞不懂是什么原因,请各位高手指教,谢谢!
源程序(serv.c)
#define SERVER_PORT 3333
#define MAX_CONNECT 10
#include <stdio.h>;
#include <unistd.h>;
#include <netdb.h>;
#include <errno.h>;
#include <sys/ioctl.h>;
#include <signal.h>;
#include <sys/types.h>;
#include <sys/socket.h>;
#include <sys/netinet/in.h>;
main()
{
int sHandle, cHandle, sin_size;
struct sockaddr_in sAddress;
struct sockaddr_in cAddress;
if ((sHandle = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
printf("Socket error" ;
exit(1);
}
sAddress.sin_family = AF_INET;
sAddress.sin_port = SERVER_PORT;
sAddress.sin_addr.s_addr = INADDR_ANY;
memset(sAddress.sin_zero, 0, ;
if (bind(sHandle, (struct sockaddr *)&sAddress, sizeof(struct sockaddr)) == -1)
{
printf("Bind error" ;
exit(1);
}
if (listen(sHandle, MAX_CONNECT) == -1)
{
printf("Listen error" ;
exit(1);
}
while (1)
{
sin_size = sizeof(struct sockaddr_in);
if ((cHandle = accept(sHandle, (struct sockaddr *)&cAddress, &sin_size)) == -1)
{
printf("Accept error" ;
continue;
}
printf("Received a connection from %s\n", inet_ntoa(cAddress.sin_addr));
if (!fork())
{
if (send(cHandle, "Hello,you are connected!\n", 26, 0) == -1)
{
printf("Send error" ;
close(cHandle);
exit(0);
}
}
close(cHandle);
}
} |
|