/* -*-c-*-
*
- * $Id: identify.c,v 1.2 1999/07/03 13:56:59 mdw Exp $
+ * $Id: identify.c,v 1.4 1999/07/27 18:30:53 mdw Exp $
*
* Identifies and logs the client of a connection
*
- * (c) 1999 Mark Wooding
+ * (c) 1999 Straylight/Edgeware
*/
/*----- Licensing notice --------------------------------------------------*
/*----- Revision history --------------------------------------------------*
*
* $Log: identify.c,v $
+ * Revision 1.4 1999/07/27 18:30:53 mdw
+ * Various minor portability fixes.
+ *
+ * Revision 1.3 1999/07/26 23:26:21 mdw
+ * Minor modifications for new design.
+ *
* Revision 1.2 1999/07/03 13:56:59 mdw
* Log connections to syslog or stderr as appropriate.
*
typedef struct id {
id_req q; /* Copy of client's request block */
- void (*func)(void */*p*/); /* Function to call when done */
- void *p; /* Argument to pass to function */
time_t when; /* When the connection occurred */
conn c; /* Connection selector */
unsigned state; /* Current state of the world */
static void id_done(id *i)
{
- char buf[64];
- struct tm *tm;
-
/* --- Close down the various dependent bits --- */
if (!(i->state & S_HOST))
/* --- Report the final result --- */
- tm = localtime(&i->when);
- strftime(buf, sizeof(buf), "%Y-%m-%d %H:%M:%S", tm);
- if (flags & FW_SYSLOG) {
- syslog(LOG_NOTICE, "%s %s %s from %s@%s [%s]\n",
- buf, i->q.desc, i->q.act,
- i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
- } else {
- fprintf(stderr, "%s %s %s from %s@%s [%s]\n",
- buf, i->q.desc, i->q.act,
- i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
- }
+ fw_log(i->when, "[%s] %s from %s@%s [%s]",
+ i->q.desc, i->q.act,
+ i->user, i->host, inet_ntoa(i->q.rsin.sin_addr));
/* --- Dispose of the block --- */
- i->func(i->p);
+ REFFD_DEC(i->q.r);
free(i);
}
/* --- @identify@ --- *
*
* Arguments: @const id_req *q@ = pointer to request block
- * @void (*func)(void *p)@ = function to call when done
- * @void *p@ = argument to pass to function
*
* Returns: ---
*
* which will, eventually, report a message to the system log.
*/
-void identify(const id_req *q,
- void (*func)(void */*p*/), void *p)
+void identify(const id_req *q)
{
id *i;
i = xmalloc(sizeof(*i));
i->q = *q;
- i->func = func;
- i->p = p;
+ REFFD_INC(i->q.r);
str_sanitize(i->host, inet_ntoa(q->rsin.sin_addr), sizeof(i->host));
strcpy(i->user, "<ANONYMOUS>");
if ((fd = socket(PF_INET, SOCK_STREAM, 0)) < 0)
id_conn(-1, i);
else {
+ memset(&sin, 0, sizeof(sin));
sin.sin_family = AF_INET;
sin.sin_addr = q->lsin.sin_addr;
sin.sin_port = 0;
close(fd);
id_conn(-1, i);
} else {
+ int opt = 1;
sin.sin_family = AF_INET;
sin.sin_addr = q->rsin.sin_addr;
sin.sin_port = htons(113);
+ setsockopt(fd, SOL_SOCKET, SO_OOBINLINE, &opt, sizeof(opt));
conn_init(&i->c, sel, fd,
(struct sockaddr *)&sin, sizeof(sin),
id_conn, i);