Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

connect Error: "No route to host"

Tags:

c

linux

sockets

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;
}
like image 401
user2772956 Avatar asked Sep 26 '13 23:09

user2772956


People also ask

How do I fix No route to host connection in Linux?

Open the applet or go through your system settings. Select your connection and find the “IPv4” tab. Switch the connection to “Manual” and manually enter in the IP address of your computer and the IP of your router as the gateway. Then, in the DNS field below, enter your router's IP or the IP of another DNS server.

How do I fix port 22 without hosting?

If you still get no route to host , then double check your ssh server's LAN and WAN IP addresses. Some ISPs block port 22. Try using a different port. Remember to change the listening port on the router, not on the server.

Can not connect to the host?

This error indicates that your web server did not accept our TCP connection request, and hence the HTTP Request could not be performed.

What does host not found mean?

Your host appears online, but when you try to connect you get the following error: Host Not Found. The host may have been switched off or lost its connection to the Internet since you last refreshed your computer list.


1 Answers

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.

like image 190
Manoj Pandey Avatar answered Sep 24 '22 18:09

Manoj Pandey