masqmail

diff src/libident/id_query.c @ 0:08114f7dcc23

this is masqmail-0.2.21 from oliver kurth
author meillo@marmaro.de
date Fri, 26 Sep 2008 17:05:23 +0200
parents
children 26e34ae9a3e3
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/libident/id_query.c	Fri Sep 26 17:05:23 2008 +0200
     1.3 @@ -0,0 +1,88 @@
     1.4 +/*
     1.5 +** id_query.c                             Transmit a query to an IDENT server
     1.6 +**
     1.7 +** Author: Peter Eriksson <pen@lysator.liu.se>
     1.8 +*/
     1.9 +
    1.10 +#ifdef NeXT3
    1.11 +#  include <libc.h>
    1.12 +#endif
    1.13 +
    1.14 +#include <stdio.h>
    1.15 +#include <errno.h>
    1.16 +#include <signal.h>
    1.17 +
    1.18 +#ifdef HAVE_ANSIHEADERS
    1.19 +#  include <stdlib.h>
    1.20 +#  include <string.h>
    1.21 +#  include <unistd.h>
    1.22 +#endif
    1.23 +
    1.24 +#include <sys/types.h>
    1.25 +#include <sys/wait.h>
    1.26 +#include <sys/time.h>
    1.27 +
    1.28 +#ifdef _AIX
    1.29 +#  include <sys/select.h>
    1.30 +#endif
    1.31 +
    1.32 +#ifdef _AIX
    1.33 +#  include <sys/select.h>
    1.34 +#endif
    1.35 +#ifdef VMS
    1.36 +#  include <sys/socket.h>     /* for fd_set */
    1.37 +#endif
    1.38 +#define IN_LIBIDENT_SRC
    1.39 +#include "ident.h"
    1.40 +
    1.41 +
    1.42 +/*
    1.43 +int id_query __P4(ident_t *, id,
    1.44 +		  int, lport,
    1.45 +		  int, fport,
    1.46 +		  struct timeval *, timeout)
    1.47 +*/
    1.48 +
    1.49 +int    id_query __P((	ident_t *id,                 
    1.50 +			int lport,                   
    1.51 +			int fport,                   
    1.52 +			__STRUCT_TIMEVAL_P timeout))
    1.53 +{
    1.54 +#ifdef SIGRETURNTYPE
    1.55 +    SIGRETURNTYPE (*old_sig)();
    1.56 +#else
    1.57 +    void (*old_sig) __P((int));
    1.58 +#endif
    1.59 +    int res;
    1.60 +    char buf[80];
    1.61 +    fd_set ws;
    1.62 +    
    1.63 +    sprintf(buf, "%d , %d\r\n", lport, fport);
    1.64 +    
    1.65 +    if (timeout)
    1.66 +    {
    1.67 +	FD_ZERO(&ws);
    1.68 +	FD_SET(id->fd, &ws);
    1.69 +
    1.70 +#ifdef __hpux
    1.71 +	if ((res = select(FD_SETSIZE, (int *)0, (int *)&ws, (int *)0, timeout)) < 0)
    1.72 +#else
    1.73 +	if ((res = select(FD_SETSIZE, (fd_set *)0, &ws, (fd_set *)0, timeout)) < 0)
    1.74 +#endif
    1.75 +	    return -1;
    1.76 +	
    1.77 +	if (res == 0)
    1.78 +	{
    1.79 +	    errno = ETIMEDOUT;
    1.80 +	    return -1;
    1.81 +	}
    1.82 +    }
    1.83 +
    1.84 +    old_sig = signal(SIGPIPE, SIG_IGN);
    1.85 +    
    1.86 +    res = write(id->fd, buf, strlen(buf));
    1.87 +    
    1.88 +    signal(SIGPIPE, old_sig);
    1.89 +    
    1.90 +    return res;
    1.91 +}