From 4498d576d5803efb3e8c786113ed3f4d76e01143 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Thu, 19 Aug 2010 17:58:53 +0000 Subject: [PATCH] * text client - tell the user the actual hostname and IP address of the Citadel server to which we connected. --- citadel/include/citadel_ipc.h | 41 +++++++++++++++++------------------ citadel/textclient/citadel.c | 5 +++++ citadel/utillib/citadel_ipc.c | 24 +++++++++++++++++++- 3 files changed, 48 insertions(+), 22 deletions(-) diff --git a/citadel/include/citadel_ipc.h b/citadel/include/citadel_ipc.h index e03fa340b..4e60f6091 100644 --- a/citadel/include/citadel_ipc.h +++ b/citadel/include/citadel_ipc.h @@ -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 */ diff --git a/citadel/textclient/citadel.c b/citadel/textclient/citadel.c index b1abf2947..407b47ae9 100644 --- a/citadel/textclient/citadel.c +++ b/citadel/textclient/citadel.c @@ -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 diff --git a/citadel/utillib/citadel_ipc.c b/citadel/utillib/citadel_ipc.c index 769ffd31a..785c45199 100644 --- a/citadel/utillib/citadel_ipc.c +++ b/citadel/utillib/citadel_ipc.c @@ -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; -- 2.39.2