当前位置: 技术问答>linux和unix
connect:address family not supported by protocol该如何解决?
来源: 互联网 发布时间:2016-01-02
本文导语: Linux(arm9中)下的tcp传输问题:连接不上服务端,错误信息是 connect:address family not supported by protocol 部分代码如下: ..... ... .. struct hostent * server_host_name; struct sockaddr_in h_addr; int sockfd; int port=9999; char *hostname="888.888.888...
Linux(arm9中)下的tcp传输问题:连接不上服务端,错误信息是
connect:address family not supported by protocol
部分代码如下:
.....
...
..
struct hostent * server_host_name;
struct sockaddr_in h_addr;
int sockfd;
int port=9999;
char *hostname="888.888.888.888";
bzero(&(h_addr),sizeof(h_addr));
server_host_name=gethostbyname(hostname);
h_addr.sin_family=PF_INET;
h_addr.sin_port=htons(port);
h_addr.sin_addr.s_addr=INADDR_ANY;
h_addr.sin_addr.s_addr=
((struct in_addr *)(server_host_name->h_addr))->s_addr;
if((sockfd=socket(PF_INET,SOCK_STREAM,0))==-1){
perror("socket");
exit(1);
}
if(connect(sockfd,(struct sockaddr *)&h_addr,
sizeof(struct sockaddr))==-1){
perror("connect");
exit(1);
}
close(sockfd);
connect:address family not supported by protocol
部分代码如下:
.....
...
..
struct hostent * server_host_name;
struct sockaddr_in h_addr;
int sockfd;
int port=9999;
char *hostname="888.888.888.888";
bzero(&(h_addr),sizeof(h_addr));
server_host_name=gethostbyname(hostname);
h_addr.sin_family=PF_INET;
h_addr.sin_port=htons(port);
h_addr.sin_addr.s_addr=INADDR_ANY;
h_addr.sin_addr.s_addr=
((struct in_addr *)(server_host_name->h_addr))->s_addr;
if((sockfd=socket(PF_INET,SOCK_STREAM,0))==-1){
perror("socket");
exit(1);
}
if(connect(sockfd,(struct sockaddr *)&h_addr,
sizeof(struct sockaddr))==-1){
perror("connect");
exit(1);
}
close(sockfd);
|
不清楚啊,观望中