Nios® V/II Embedded Design Suite (EDS)
Support for Embedded Development Tools, Processors (SoCs and Nios® V/II processor), Embedded Development Suites (EDSs), Boot and Configuration, Operating Systems, C and C++
12600 Discussions

can't connect:no route to host.

Altera_Forum
Honored Contributor II
1,296 Views

Hi,now I am meeting a problem. 

I ported the uClinux to the DE2 board.I used two DE2 boards to communicate with each other.One board is used as a server with its ip 192.168.135.6,the other is used as a client with its ip 192.168.135.10.My pc's ip is 192.168.135.9. 

I can ping my pc with either DE2 board, and I can also ping each board with my pc.But I can't ping the DE2 board with the other. 

so what is the problem? 

 

I wrote a server.c and client.c .when I run server.c in the DE2 as the server, 

I run the client.c in the DE2 as the client,and it displays"can't connect:no route to host." 

 

I don't know why.I hope someone can help me . 

below is the server.c and the client.c .they are simple. 

 

/////server.c# include <sys/types.h># include <sys/socket.h># include <sys/ioctl.h># include <sys/time.h># include <netinet/in.h># include <arpa/inet.h># include <netdb.h># include <stdio.h># include <signal.h># include <unistd.h> # define FD_SETSIZE 1024 

int main () 

int cd,sd; 

struct sockaddr_in sin,cin; 

char buf[1024]; 

int i,n; 

fd_set rdfds,tsfds; 

int res,fd,nread; 

 

if((sd=socket(AF_INET,SOCK_STREAM,0))==-1) 

perror("can&#39;t creat socket!"); 

exit(1);  

}  

 

sin.sin_family=AF_INET; 

sin.sin_addr.s_addr=htonl(INADDR_ANY); 

sin.sin_port=htons(1989); 

 

if(bind(sd,(struct sockaddr*)&sin,sizeof(sin))==-1) 

perror("bind error!"); 

exit(1);  

 

if(listen(sd,20)==-1) 

perror("listen error!"); 

exit(1); 

 

FD_ZERO(&rdfds); 

FD_SET(sd,&rdfds); 

 

printf("waiting for connections from clients!\n"); 

 

while(1) 

tsfds=rdfds; 

res=select(FD_SETSIZE,&tsfds,0,0,0); 

if(res<1) 

perror("can&#39;t select!"); 

exit(1); 

 

for(fd=0;fd<FD_SETSIZE;fd++) 

if(FD_ISSET(fd,&tsfds)) 

if(fd==sd) //if it is listen descriptor; 

if((cd=accept(sd,(struct sockaddr*)&cin,sizeof(cin)))==-1) 

perror("accept error!"); 

exit(1); 

}  

FD_SET(cd,&rdfds); 

printf("add client on fd%d",cd); 

}  

else 

ioctl(fd,FIONREAD,&nread); 

if(nread==0) //if client left 

close(fd); 

FD_CLR(fd,&rdfds); 

printf("remove client on %d",fd); 

else //data transfer 

if((n=recv(cd,buf,sizeof(buf),0))<0) 

perror("receive error!"); 

exit(1); 

printf("received from the client:%s\n",buf); 

for(i=0;i<=n;i++) 

buf=toupper(buf); 

if((n=send(cd,buf,sizeof(buf),0))<0) 

perror("send error!"); 

exit(1); 

 

 

 

 

 

 

 

///////////////////////client.c# include <sys/types.h># include <sys/socket.h># include <sys/ioctl.h># include <sys/time.h># include <netinet/in.h># include <arpa/inet.h># include <netdb.h># include <stdio.h># include <signal.h># include <unistd.h>  

 

int main() 

int sd; 

struct sockaddr_in cin; 

char buf[1024]; 

int n; 

 

if((sd=socket(AF_INET,SOCK_STREAM,0))==-1) 

perror("can&#39;t creat socket!"); 

exit(1);  

}  

 

cin.sin_family=AF_INET; 

cin.sin_addr.s_addr=inet_addr("192.168.135.6"); 

cin.sin_port=htons(1989); 

 

if(connect(sd,(void*)&cin,sizeof(cin))==-1) 

perror("can&#39;t connect!"); 

exit(1);  

 

printf("input a message:\n"); 

fgets(buf,sizeof(buf),stdin); 

 

if((n=send(sd,buf,sizeof(buf),0))==-1) 

perror("can&#39;t send message!"); 

exit(1);  

 

if((n=recv(sd,buf,sizeof(buf),0))==-1) 

perror("receive error!"); 

exit(1);  

printf("response from server:%s",buf); 

close(sd); 

 

}
0 Kudos
3 Replies
Altera_Forum
Honored Contributor II
296 Views

please check the ethernet hardware address, they can not use the same number. 

check with ifconfig, and try to change it with 

ifconfig eth0 hw ether 11:22:33:44:55:66  

replace the number with yours. 

 

in case the ifconfig can not work, check the source of your ether driver to setup hw addr.
0 Kudos
Altera_Forum
Honored Contributor II
296 Views

the ifconfig hw ether is not supported. 

please check kernel source arch/nios2nommu/kernel/setup.c after line 208. 

where it gets the hw addr.
0 Kudos
Altera_Forum
Honored Contributor II
296 Views

 

--- Quote Start ---  

originally posted by hippo@Sep 24 2006, 11:58 PM 

the ifconfig hw ether is not supported. 

please check kernel source  arch/nios2nommu/kernel/setup.c  after line 208. 

where it gets the hw addr. 

<div align='right'><{post_snapback}> (index.php?act=findpost&pid=18433) 

--- quote end ---  

 

--- Quote End ---  

 

 

Yes,I checked the hw and both are the same,so the can&#39;t ping each other. 

I modified the source code according to you,and now I solved the problem. 

I have been busy for the days ,so I can only say thank you by now. 

thank you very much ,hippo!
0 Kudos
Reply