6
votes

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;
}
2

2 Answers

2
votes

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.

0
votes

I know this is an old question, but I would suspect a problem with ax25port - should be something like YOURCALL-0 where YOURCALL matches the HWaddr of an existing ax25 port ( try /sbin/ifconfig | fgrep AX.25