From 29818ed78e32998641adcf5f23d3b854355918b5 Mon Sep 17 00:00:00 2001 From: Sebastian Hammer Date: Mon, 30 Oct 1995 12:41:06 +0000 Subject: [PATCH] Added hostname lookup for server. --- CHANGELOG | 2 ++ client/client.c | 15 +++++++++------ comstack/tcpip.c | 30 +++++++++++++++++++++++++++++- comstack/xmosi.c | 12 +++++++++++- include/comstack.h | 7 ++++++- server/statserv.c | 13 ++++++++----- 6 files changed, 65 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 442c53e..232d1cc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -15,6 +15,8 @@ Added Diagnostic Format. Added simple Close handling to frontend server (no hooks for resource reporting yet), and demonstration client. +Added cs_addrstr() command to COMSTACK to retrieve peer hostname/address. + --- 1.0b3 1995/08/24 Fixed bug in the frontend-server. The numberOfRecordsReturned field was diff --git a/client/client.c b/client/client.c index f1f3c58..b92f15e 100644 --- a/client/client.c +++ b/client/client.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: client.c,v $ - * Revision 1.23 1995-10-18 16:12:30 quinn + * Revision 1.24 1995-10-30 12:41:13 quinn + * Added hostname lookup for server. + * + * Revision 1.23 1995/10/18 16:12:30 quinn * Better diagnostics. * * Revision 1.22 1995/10/11 14:49:12 quinn @@ -668,13 +671,13 @@ void process_close(Z_Close *req) { "finished", "shutdown", - "systemProblem", - "costLimit", + "system problem", + "cost limit reached", "resources", - "securityViolation", + "security violation", "protocolError", - "lackOfActivity", - "peerAbort", + "lack of activity", + "peer abort", "unspecified" }; diff --git a/comstack/tcpip.c b/comstack/tcpip.c index 3fdb3e2..4e2ab4f 100644 --- a/comstack/tcpip.c +++ b/comstack/tcpip.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: tcpip.c,v $ - * Revision 1.6 1995-09-29 17:12:00 quinn + * Revision 1.7 1995-10-30 12:41:16 quinn + * Added hostname lookup for server. + * + * Revision 1.6 1995/09/29 17:12:00 quinn * Smallish * * Revision 1.5 1995/09/29 17:01:48 quinn @@ -111,6 +114,7 @@ int tcpip_rcvconnect(COMSTACK h); int tcpip_bind(COMSTACK h, void *address, int mode); int tcpip_listen(COMSTACK h, char *addrp, int *addrlen); COMSTACK tcpip_accept(COMSTACK h); +char *tcpip_addrstr(COMSTACK h); int completeBER(unsigned char *buf, int len); @@ -187,6 +191,7 @@ COMSTACK tcpip_type(int blocking, int protocol) p->f_bind = tcpip_bind; p->f_listen = tcpip_listen; p->f_accept = tcpip_accept; + p->f_addrstr = tcpip_addrstr; p->state = CS_UNBND; p->event = CS_NONE; @@ -503,3 +508,26 @@ int tcpip_close(COMSTACK h) free(h); return 0; } + +char *tcpip_addrstr(COMSTACK h) +{ + struct sockaddr_in addr; + static char buf[64]; + char *r; + int len; + struct hostent *host; + + len = sizeof(addr); + if (getpeername(h->iofile, (struct sockaddr*) &addr, &len) < 0) + { + h->cerrno = CSYSERR; + return 0; + } + if ((host = gethostbyaddr((char*)&addr.sin_addr, sizeof(addr.sin_addr), + AF_INET))) + r = (char*) host->h_name; + else + r = inet_ntoa(addr.sin_addr); + sprintf(buf, "tcp:%s", r); + return buf; +} diff --git a/comstack/xmosi.c b/comstack/xmosi.c index bed1dd1..3f6a9c2 100644 --- a/comstack/xmosi.c +++ b/comstack/xmosi.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: xmosi.c,v $ - * Revision 1.6 1995-09-29 17:12:00 quinn + * Revision 1.7 1995-10-30 12:41:17 quinn + * Added hostname lookup for server. + * + * Revision 1.6 1995/09/29 17:12:00 quinn * Smallish * * Revision 1.5 1995/09/28 10:24:32 quinn @@ -103,6 +106,7 @@ int mosi_rcvconnect(COMSTACK h); int mosi_bind(COMSTACK h, void *address, int mode); int mosi_listen(COMSTACK h, char *addrp, int *addrlen); COMSTACK mosi_accept(COMSTACK h); +char *mosi_addrstr(COMSTACK h); typedef struct mosi_state { @@ -171,6 +175,7 @@ COMSTACK mosi_type(int blocking, int protocol) r->f_bind = mosi_bind; r->f_listen = mosi_listen; r->f_accept = mosi_accept; + r->f_addrstr = mosi_addrstr; if (!blocking) flags |= O_NONBLOCK; @@ -470,3 +475,8 @@ int mosi_close(COMSTACK h) free(h); return 0; } + +char *mosi_addrstr(COMSTACK h) +{ + return "osi:[UNIMPLEMENTED"; +} diff --git a/include/comstack.h b/include/comstack.h index e14b8ea..eabbdf1 100644 --- a/include/comstack.h +++ b/include/comstack.h @@ -24,7 +24,10 @@ * OF THIS SOFTWARE. * * $Log: comstack.h,v $ - * Revision 1.11 1995-09-29 17:12:01 quinn + * Revision 1.12 1995-10-30 12:41:27 quinn + * Added hostname lookup for server. + * + * Revision 1.11 1995/09/29 17:12:01 quinn * Smallish * * Revision 1.10 1995/09/29 17:01:48 quinn @@ -145,6 +148,7 @@ struct comstack int (*f_listen)(COMSTACK handle, char *addrp, int *addrlen); COMSTACK (*f_accept)(COMSTACK handle); int (*f_close)(COMSTACK handle); + char *(*f_addrstr)(COMSTACK handle); }; #define cs_put(handle, buf, size) ((*(handle)->f_put)(handle, buf, size)) @@ -163,6 +167,7 @@ struct comstack #define cs_getstate(handle) ((handle)->getstate) #define cs_errno(handle) ((handle)->cerrno) #define cs_getproto(handle) ((handle)->protocol) +#define cs_addrstr(handle) ((*(handle)->f_addrstr)(handle)) const char *cs_strerror(COMSTACK h); const char *cs_errmsg(int n); diff --git a/server/statserv.c b/server/statserv.c index a692eb2..fe72e45 100644 --- a/server/statserv.c +++ b/server/statserv.c @@ -4,7 +4,10 @@ * Sebastian Hammer, Adam Dickmeiss * * $Log: statserv.c,v $ - * Revision 1.28 1995-09-29 17:12:30 quinn + * Revision 1.29 1995-10-30 12:41:29 quinn + * Added hostname lookup for server. + * + * Revision 1.28 1995/09/29 17:12:30 quinn * Smallish * * Revision 1.27 1995/09/27 15:03:02 quinn @@ -131,14 +134,12 @@ static statserv_options_block control_block = { "", /* diagnostic output to stderr */ "tcp:@:9999", /* default listener port */ PROTO_Z3950, /* default application protocol */ - 2*60, /* idle timeout (minutes) */ + 60, /* idle timeout (minutes) */ 1024*1024, /* maximum PDU size (approx.) to allow */ "default-config", /* configuration name to pass to backend */ "" /* set user id */ }; -#define DEFAULT_LISTENER "tcp:localhost:9999" - /* * handle incoming connect requests. * The dynamic mode is a bit tricky mostly because we want to avoid @@ -216,6 +217,7 @@ static void listener(IOCHAN h, int event) { COMSTACK new_line; IOCHAN new_chan; + char *a; if (!(new_line = cs_accept(line))) { @@ -254,7 +256,8 @@ static void listener(IOCHAN h, int event) } iochan_setdata(new_chan, newas); iochan_settimeout(new_chan, control_block.idle_timeout * 60); - logf(LOG_LOG, "accepted connection"); + a = cs_addrstr(new_line); + logf(LOG_LOG, "Accepted connection from %s", a ? a : "[Unknown]"); } else { -- 1.7.10.4