交叉编译client程序出错,望高手赐教!
程序如下:#include <stdio.h>
#include <stdlib.h>
#include <errno.h>
#include <string.h>
#include <netdb.h>
#include <sys/types.h>
#include <netinet/in.h>
#include <sys/socket.h>
//#include <sys/wait.h>
#include <unistd.h>
#define PORT 3490
#define MAXDATASIZE 100
int main(int argc, char *argv[])
{
int sockfd;
int 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)
{
perror("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("recevied:%s",buf);
close(sockfd);
return 0;
}
产生错误如下:[root@localhost boot]# arm-linux-gcc -o client client.c
client.c: In function `main':
client.c:49: error: parse error before '{' token
client.c: At top level:
client.c:53: error: `numbytes' undeclared here (not in a function)
client.c:53: warning: data definition has no type or storage class
client.c:54: error: parse error before string constant
client.c:54: error: conflicting types for 'printf'
client.c:54: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
client.c:54: error: conflicting types for 'printf'
client.c:54: note: a parameter list with an ellipsis can't match an empty parameter name list declaration
client.c:54: warning: data definition has no type or storage class
client.c:55: warning: parameter names (without types) in function declaration
client.c:55: warning: data definition has no type or storage class
client.c:56: error: parse error before "return"
client.c:53: error: storage size of `buf' isn't known
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误不是写的很清楚吗?