连接错误:[否到主机的路由" [英] connect Error: "No route to host"

查看:118
本文介绍了连接错误:[否到主机的路由"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在写基于AX.25协议的服务器/客户端的C程序。
服务器创建套接字,成功绑定和监听来连接。
在不同的线程运行,但在客户端连接失败,没有到主机的路由

服务器code

 的#include< SYS / socket.h中>
#包括LT&; netax25 / ax25.h>
#包括LT&; netax25 / axlib.h>
#包括LT&; netax25 / axconfig.h>#包括LT&;&stdio.h中GT;
#包括LT&; ARPA / inet.h>#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&unistd.h中GT;#包括LT&;&signal.h中GT;
#包括LT&;&syslog.h GT;#包括LT&; SYS / types.h中>
#包括LT&;的Linux / socket.h中>
#包括LT&;&stdlib.h中GT;#包括LT&; SYS / un.h>#包括LT&;&string.h中GT;
#包括LT&;&errno.h中GT;INT主(INT ARGC,字符** argv的,字符** envp){
    INT ax25_socket = -1;
    无符号字符缓冲区[512];    结构full_sockaddr_ax25地址,axconnect;      字符*端口=3; // SM0端口号:3
      字符*通话=OH2BNS-8; // SM0呼号
      bzero((字符*)及地址,的sizeof(结构full_sockaddr_ax25));        addr.fsa_ax25.sax25_family = AF_AX25;
        addr.fsa_ax25.sax25_ndigis = 1;
        如果(ax25_config_load_ports()== 0){
                    的printf(问题与axports文件);
                    //返回-1;
            }        字符* ax25port =(字符*)ax25_config_get_addr(端口);        ax25_aton_entry(打电话,addr.fsa_ax25.sax25_call.ax25_call);
        ax25_aton_entry(ax25port,addr.fsa_digipeater [0] .ax25_call);
        ax25_socket =插座(AF_AX25,SOCK_SEQPACKET,0);
            如果(ax25_socket< -1)
              的printf(错误创建套接字);            如果(绑定(ax25_socket,(结构sockaddr *)及地址,的sizeof(结构full_sockaddr_ax25))小于0){             PERROR(bind--);
             返回-1;
            }
            如果(听(ax25_socket,2)!= 0)
            {
                的printf(不能监听套接字\\ n!);
                        关闭(ax25_socket);
                        返回0;
            }
                看跌期权(听);
            // bzero((字符*)及axconnect,的sizeof(结构full_sockaddr_ax25));
                INT LEN = sizeof的(结构full_sockaddr_ax25);
            INT temp_sock_desc =接受(ax25_socket,(结构sockaddr *)及axconnect,和放大器; LEN);
                如果(temp_sock_desc == -1)
                {
                    的printf(不能接受客户端\\ n!);
                    关闭(ax25_socket);
                    返回0;
                }
            返回0;
}

客户端code

 的#include< SYS / socket.h中>
#包括LT&; netax25 / ax25.h>
#包括LT&; netax25 / axlib.h>
#包括LT&; netax25 / axconfig.h>#包括LT&;&stdio.h中GT;
#包括LT&; ARPA / inet.h>#包括LT&;&stdio.h中GT;
#包括LT&;&string.h中GT;
#包括LT&;&unistd.h中GT;#包括LT&;&signal.h中GT;
#包括LT&;&syslog.h GT;#包括LT&; SYS / types.h中>
#包括LT&;的Linux / socket.h中>
#包括LT&;&stdlib.h中GT;#包括LT&; SYS / un.h>#包括LT&;&string.h中GT;
#包括LT&;&errno.h中GT;
INT主(INT ARGC,CHAR *的argv [])
{
    INT ax25_socket = -1;
    无符号字符缓冲区[512];    结构full_sockaddr_ax25 axconnect;    字符*端口=3; // SM0端口号:3
    字符*通话=OH2BNS-8; // SM0呼号    bzero((字符*)及axconnect,的sizeof(结构full_sockaddr_ax25));    axconnect.fsa_ax25.sax25_family = AF_AX25;
    axconnect.fsa_ax25.sax25_ndigis = 1;         如果(ax25_config_load_ports()== 0){
                的printf(问题与axports文件);
                   //返回-1;
                        }                 字符* ax25port =(字符*)ax25_config_get_addr(端口);                 ax25_aton_entry(打电话,axconnect.fsa_ax25.sax25_call.ax25_call);
                 ax25_aton_entry(ax25port,axconnect.fsa_digipeater [0] .ax25_call);                    ax25_socket =插座(AF_AX25,SOCK_SEQPACKET,0);
                                  如果(ax25_socket< -1)
                                       的printf(错误创建套接字);                            如果(连接(ax25_socket,(结构sockaddr *)及!axconnect,sizeof的(结构full_sockaddr_ax25))= 0){
                                        PERROR( - );
                                            开关(错误){
                                                案例ECONNREFUSED:
                                                    的printf(***拒绝连接\\ r);
                                                    打破;
                                                案例ENETUNREACH:
                                                    的printf(***没有已知路由\\ r);
                                                    打破;
                                                案例EINTR:
                                                    的printf(***连接超时\\ r);
                                                    打破;
                                                默认:
                                                    的printf(错误:无法连接到AX.25呼号\\ r);
                                                    打破;
                                            }                                            关闭(ax25_socket);
                                    }
                        的printf(保持通话!\\ r);
                        INT N =写(ax25_socket,消息!!!!,18);
                                如果(N = -1)
                                    {
                                            PERROR(写 - );
                                    }
                返回0;
}


解决方案

简单地说,没有到主机的路由,将意味着存在于客户端的路由表中的服务器IP地址的路由。你能ping服务器的IP地址是什么?最有可能你不应该能够和ping应该说,服务器不可用。如果是这样,那么这个错误无关,与你的程序,你可能遇到了连接问题。

您可以找到路线-n的输出为您的服务器的条目。如果没有,那么你应该检查是否有更大的preFIX服务器的子网。如果这还不算present,那么你应该确认你有一个默认路由设置。

要进一步确认,我会做以下两项测试。首先,如果您尝试运行在同一个盒子的客户机/服务器会发生什么?第二,如果你尝试运行(在同一个子网present)客户端/上两盒服务器和同一LAN上会发生什么?如果您没有看到这个问题,你的应用程序工作得很好,那么这应该确认您正在运行到一个连接问题。

i'm writing a server/client c program based on AX.25 protocol. The server creating the socket, binding Successfully and listening for coming connections. the client running in a different thread but fails on connect with " No route to host"

Server code

#include <sys/socket.h>
#include <netax25/ax25.h>
#include <netax25/axlib.h>
#include <netax25/axconfig.h>

#include <stdio.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <signal.h>
#include <syslog.h>

#include <sys/types.h>
#include <linux/socket.h>
#include <stdlib.h>

#include <sys/un.h>

#include <string.h>
#include <errno.h>



int main(int argc,char **argv,char **envp) {


    int ax25_socket = -1;
    unsigned char buffer[512];

    struct full_sockaddr_ax25 addr, axconnect ;

      char *port ="3";// sm0 port number:3
      char *call = "OH2BNS-8";// sm0 callsign


      bzero((char *) &addr, sizeof(struct full_sockaddr_ax25));

        addr.fsa_ax25.sax25_family = AF_AX25;
        addr.fsa_ax25.sax25_ndigis = 1;


        if (ax25_config_load_ports() == 0) {
                    printf( "Problem with axports file");
                    //return -1;
            }

        char* ax25port = (char*) ax25_config_get_addr(port);

        ax25_aton_entry( call, addr.fsa_ax25.sax25_call.ax25_call);
        ax25_aton_entry( ax25port, addr.fsa_digipeater[0].ax25_call);


        ax25_socket = socket(AF_AX25, SOCK_SEQPACKET, 0);
            if (ax25_socket < -1)
              printf( "error in create socket");

            if (bind(ax25_socket, (struct sockaddr *)&addr, sizeof(struct full_sockaddr_ax25)) < 0) {

             perror("bind--");
             return -1;
            }


            if(listen(ax25_socket,2) != 0)
            {
                printf("cannot listen on socket!\n");
                        close(ax25_socket);
                        return 0;
            }
                puts("listening");
            //bzero((char *) &axconnect, sizeof(struct full_sockaddr_ax25));
                int len =sizeof(struct full_sockaddr_ax25);
            int temp_sock_desc = accept(ax25_socket, (struct sockaddr*)&axconnect, &len);
                if (temp_sock_desc == -1)
                {
                    printf("cannot accept client!\n");
                    close(ax25_socket);
                    return 0;
                }




            return 0;
}

Client code

#include <sys/socket.h>
#include <netax25/ax25.h>
#include <netax25/axlib.h>
#include <netax25/axconfig.h>

#include <stdio.h>
#include <arpa/inet.h>

#include <stdio.h>
#include <string.h>
#include <unistd.h>

#include <signal.h>
#include <syslog.h>

#include <sys/types.h>
#include <linux/socket.h>
#include <stdlib.h>

#include <sys/un.h>

#include <string.h>
#include <errno.h>


int main(int argc, char *argv[])
{
    int ax25_socket = -1;
    unsigned char buffer[512];

    struct full_sockaddr_ax25 axconnect ;

    char *port ="3";// sm0 port number:3
    char *call ="OH2BNS-8";// sm0 callsign

    bzero((char *) &axconnect, sizeof(struct full_sockaddr_ax25));

    axconnect.fsa_ax25.sax25_family = AF_AX25;
    axconnect.fsa_ax25.sax25_ndigis = 1;

         if (ax25_config_load_ports() == 0) {
                printf( "Problem with axports file");
                   //return -1;
                        }



                 char* ax25port = (char*) ax25_config_get_addr(port);

                 ax25_aton_entry( call, axconnect.fsa_ax25.sax25_call.ax25_call);
                 ax25_aton_entry( ax25port, axconnect.fsa_digipeater[0].ax25_call);

                    ax25_socket = socket(AF_AX25, SOCK_SEQPACKET, 0);
                                  if (ax25_socket < -1)
                                       printf( "error in create socket");



                            if (connect(ax25_socket, (struct sockaddr *)&axconnect, sizeof(struct full_sockaddr_ax25)) != 0) {
                                        perror("--");
                                            switch (errno) {
                                                case ECONNREFUSED:
                                                    printf("*** Connection refused\r");
                                                    break;
                                                case ENETUNREACH:
                                                    printf("*** No known route\r");
                                                    break;
                                                case EINTR:
                                                    printf("*** Connection timed out\r");
                                                    break;
                                                default:
                                                    printf("ERROR: cannot connect to AX.25 callsign\r");
                                                    break;
                                            }

                                            close(ax25_socket);
                                    }
                        printf("Connected!!\r");
                        int n = write(ax25_socket,"Message!!!!",18);
                                if(n = -1)
                                    {
                                            perror("write--");
                                    }


                return 0;
}

解决方案

Simply put, a " No route to host"" would mean that there is no route for the server IP address in the client's routing table. Are you able to ping the server's IP address? Most likely you should not be able to and ping should say that the server is not reachable. If so, then this error has nothing to do with your program, you are probably running into a connectivity issue.

Can you find the entry for your server in the output of "route -n". If there is none, then you should check for a bigger prefix for the subnet of the server. If that also is not present, then you should confirm that you have a default route setup.

To further confirm, I would do the following two tests. First, what happens if you try to run the client/server on the same box? Second, what happens if you try to run the client/server on two boxes (present in the same subnet) and on the same LAN? If you do not see this issue and your application works just fine, then this should confirm that you are running into a connectivity issue.

这篇关于连接错误:[否到主机的路由&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆