* text client - tell the user the actual hostname and IP address of the Citadel serve...
authorArt Cancro <ajc@citadel.org>
Thu, 19 Aug 2010 17:58:53 +0000 (17:58 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 19 Aug 2010 17:58:53 +0000 (17:58 +0000)
citadel/include/citadel_ipc.h
citadel/textclient/citadel.c
citadel/utillib/citadel_ipc.c

index e03fa340b2cf41e2e477509b8f5f8d68f35254ed..4e60f60916ac33cfa41a9a29c7bfe2af8850d433 100644 (file)
@@ -57,36 +57,35 @@ struct CtdlServInfo {
        char svn_revision[256];
 };
 
-/* This class is responsible for the server connection */
+/*
+ * This class is responsible for the server connection
+ */
 typedef struct _CtdlIPC {
-       /* The server info for this connection */
-       struct CtdlServInfo ServInfo;
+       struct CtdlServInfo ServInfo;   /* The server info for this connection */
 
 #if defined(HAVE_OPENSSL)
-       /* NULL if not encrypted, non-NULL otherwise */
-       SSL *ssl;
+       SSL *ssl;                       /* NULL if not encrypted, non-NULL otherwise */
 #endif
+
 #if defined(HAVE_PTHREAD_H)
-       /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
-       pthread_mutex_t mutex;
+       pthread_mutex_t mutex;          /* Fast mutex, call CtdlIPC_lock() or CtdlIPC_unlock() to use */
 #endif
-       /* -1 if not connected, >= 0 otherwise */
-       int sock;
-       /* 1 if server is local, 0 otherwise or if not connected */
-       int isLocal;
-       /* 1 if a download is open on the server, 0 otherwise */
-       int downloading;
-       /* 1 if an upload is open on the server, 0 otherwise */
-       int uploading;
-       /* Time the last command was sent to the server */
-       time_t last_command_sent;
-       /* Our buffer for linebuffered read. */
-       char *Buf;
+
+       int sock;                       /* Socket for connection to server, or -1 if not connected */
+       int isLocal;                    /* 1 if server is local, 0 otherwise or if not connected */
+       int downloading;                /* 1 if a download is open on the server, 0 otherwise */
+       int uploading;                  /* 1 if an upload is open on the server, 0 otherwise */
+       time_t last_command_sent;       /* Time the last command was sent to the server */
+
+       char *Buf;                      /* Our buffer for linebuffered read. */
        size_t BufSize;
        size_t BufUsed;
        char *BufPtr;
-       /* Callback for update on whether the IPC is locked */
-       void (*network_status_cb)(int state);
+
+       void (*network_status_cb)(int state);   /* Callback for update on whether the IPC is locked */
+       char ip_hostname[256];          /* host name of server to which we are connected (if network) */
+       char ip_address[64];            /* IP address of server to which we are connected (if network) */
+
 } CtdlIPC;
 
 /* C constructor */
index b1abf294794d19638ebf0b99088580df4b5a808d..407b47ae9469bfeb27f5a9b56ea8264d2d84bac0 100644 (file)
@@ -1576,6 +1576,11 @@ int main(int argc, char **argv)
                error_printf("Can't connect: %s\n", strerror(errno));
                logoff(NULL, 3);
        }
+
+       if (!(ipc->isLocal)) {
+               sln_printf("Connected to %s [%s].\n", ipc->ip_hostname, ipc->ip_address);
+       }
+
 #if defined(HAVE_CURSES_H) && !defined(DISABLE_CURSES)
        CtdlIPC_SetNetworkStatusCallback(ipc, wait_indicator);
 #endif
index 769ffd31a2a991fc26131159408214d8599fcfb6..785c45199a27676646cc6c7ff64e0d76ff50e604 100644 (file)
@@ -2184,7 +2184,7 @@ int CtdlIPCMessageBaseCheck(CtdlIPC *ipc, char **mret, char *cret)
 
 
 /* ************************************************************************** */
-/*             Stuff below this line is not for public consumption            */
+/*          Stuff below this line is not for public consumption            */
 /* ************************************************************************** */
 
 
@@ -3266,6 +3266,8 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
                }
                if (hostbuf != NULL) strcpy(hostbuf, cithost);
                if (portbuf != NULL) strcpy(portbuf, sockpath);
+               strcpy(ipc->ip_hostname, "");
+               strcpy(ipc->ip_address, "");
                return ipc;
        }
 
@@ -3274,6 +3276,26 @@ CtdlIPC* CtdlIPC_new(int argc, char **argv, char *hostbuf, char *portbuf)
                ifree(ipc);
                return 0;
        }
+
+
+       /* Learn the actual network identity of the host to which we are connected */
+
+       struct sockaddr_in6 clientaddr;
+       unsigned int addrlen = sizeof(clientaddr);
+
+       ipc->ip_hostname[0] = 0;
+       ipc->ip_address[0] = 0;
+
+       getpeername(ipc->sock, (struct sockaddr *)&clientaddr, &addrlen);
+       getnameinfo((struct sockaddr *)&clientaddr, addrlen,
+               ipc->ip_hostname, sizeof ipc->ip_hostname, NULL, 0, 0
+       );
+       getnameinfo((struct sockaddr *)&clientaddr, addrlen,
+               ipc->ip_address, sizeof ipc->ip_address, NULL, 0, NI_NUMERICHOST
+       );
+
+       /* stuff other things elsewhere */
+
        if (hostbuf != NULL) strcpy(hostbuf, cithost);
        if (portbuf != NULL) strcpy(portbuf, citport);
        return ipc;