这个代码编译通不过,请看看

zhuliangsu 2003-09-11 02:59:22
#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
#include <sys/wait.h>

#define PORT 3490
#define MAXDATASIZE 100

int main(int argc, char *argv[])
{
int sockfd, numbytes;
char buf[MAXDATASIZE];
struct hostent *he;
struct sockaddr_in their_addr;

if (argc != 2)
{
fprintf(stderr,"usage: client hostname\n");
exit(1);
}
if ((he=gethostbyname(argv[1])) == NULL)
{
herror("gethostbyname");
exit(1);
}

if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1)
{
perror("socket");
exit(1);
}

their_addr.sin_family = AF_INET;
their_addr.sin_port = htons(PORT);
their_addr.sin_addr = *((struct in_addr *)he->h_addr);
bzero(&(their_addr.sin_zero),;

if (connect(sockfd, (struct sockaddr *)&their_addr,sizeof(struct sockaddr)) == -1)
{
perror("connect");
exit(1);
}
if ((numbytes=recv(sockfd, buf, MAXDATASIZE, 0)) == -1)
{
perror("recv");
exit(1);
}

buf[numbytes] = '\0';
printf("Received: %s",buf);
close(sockfd);

return 0;
}
...全文
30 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
iuyon 2003-09-12
  • 打赏
  • 举报
回复
bzero(&(their_addr.sin_zero),sizeof(their_addr.sin_zero));
zhuliangsu 2003-09-12
  • 打赏
  • 举报
回复
bzero(&(their_addr.sin_zero),;
^^^^^^^^^^^
bzero(&(their_addr.sin_zero));

两处应该怎么改
ari 2003-09-11
  • 打赏
  • 举报
回复
bzero(&(their_addr.sin_zero),;
^^^^^^^^^^^
bzero(&(their_addr.sin_zero));

cc .. -lsocket
fierygnu 2003-09-11
  • 打赏
  • 举报
回复
少了#include <netdb.h>。
另外两处应该是笔误,自己改吧。

23,114

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧