masqmail-0.2

view src/libident/id_query.c @ 2:653aef34b225

removed distribution specific data
author meillo@marmaro.de
date Fri, 26 Sep 2008 21:26:36 +0200
parents
children 26e34ae9a3e3
line source
1 /*
2 ** id_query.c Transmit a query to an IDENT server
3 **
4 ** Author: Peter Eriksson <pen@lysator.liu.se>
5 */
7 #ifdef NeXT3
8 # include <libc.h>
9 #endif
11 #include <stdio.h>
12 #include <errno.h>
13 #include <signal.h>
15 #ifdef HAVE_ANSIHEADERS
16 # include <stdlib.h>
17 # include <string.h>
18 # include <unistd.h>
19 #endif
21 #include <sys/types.h>
22 #include <sys/wait.h>
23 #include <sys/time.h>
25 #ifdef _AIX
26 # include <sys/select.h>
27 #endif
29 #ifdef _AIX
30 # include <sys/select.h>
31 #endif
32 #ifdef VMS
33 # include <sys/socket.h> /* for fd_set */
34 #endif
35 #define IN_LIBIDENT_SRC
36 #include "ident.h"
39 /*
40 int id_query __P4(ident_t *, id,
41 int, lport,
42 int, fport,
43 struct timeval *, timeout)
44 */
46 int id_query __P(( ident_t *id,
47 int lport,
48 int fport,
49 __STRUCT_TIMEVAL_P timeout))
50 {
51 #ifdef SIGRETURNTYPE
52 SIGRETURNTYPE (*old_sig)();
53 #else
54 void (*old_sig) __P((int));
55 #endif
56 int res;
57 char buf[80];
58 fd_set ws;
60 sprintf(buf, "%d , %d\r\n", lport, fport);
62 if (timeout)
63 {
64 FD_ZERO(&ws);
65 FD_SET(id->fd, &ws);
67 #ifdef __hpux
68 if ((res = select(FD_SETSIZE, (int *)0, (int *)&ws, (int *)0, timeout)) < 0)
69 #else
70 if ((res = select(FD_SETSIZE, (fd_set *)0, &ws, (fd_set *)0, timeout)) < 0)
71 #endif
72 return -1;
74 if (res == 0)
75 {
76 errno = ETIMEDOUT;
77 return -1;
78 }
79 }
81 old_sig = signal(SIGPIPE, SIG_IGN);
83 res = write(id->fd, buf, strlen(buf));
85 signal(SIGPIPE, old_sig);
87 return res;
88 }