0
|
1 /*
|
|
2 ** id_query.c Transmit a query to an IDENT server
|
|
3 **
|
|
4 ** Author: Peter Eriksson <pen@lysator.liu.se>
|
|
5 */
|
|
6
|
|
7 #ifdef NeXT3
|
|
8 # include <libc.h>
|
|
9 #endif
|
|
10
|
|
11 #include <stdio.h>
|
|
12 #include <errno.h>
|
|
13 #include <signal.h>
|
|
14
|
|
15 #ifdef HAVE_ANSIHEADERS
|
|
16 # include <stdlib.h>
|
|
17 # include <string.h>
|
|
18 # include <unistd.h>
|
|
19 #endif
|
|
20
|
|
21 #include <sys/types.h>
|
|
22 #include <sys/wait.h>
|
|
23 #include <sys/time.h>
|
|
24
|
|
25 #ifdef _AIX
|
|
26 # include <sys/select.h>
|
|
27 #endif
|
|
28
|
|
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"
|
|
37
|
|
38
|
|
39 /*
|
|
40 int id_query __P4(ident_t *, id,
|
|
41 int, lport,
|
|
42 int, fport,
|
|
43 struct timeval *, timeout)
|
|
44 */
|
|
45
|
|
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;
|
|
59
|
|
60 sprintf(buf, "%d , %d\r\n", lport, fport);
|
|
61
|
|
62 if (timeout)
|
|
63 {
|
|
64 FD_ZERO(&ws);
|
|
65 FD_SET(id->fd, &ws);
|
|
66
|
|
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;
|
|
73
|
|
74 if (res == 0)
|
|
75 {
|
|
76 errno = ETIMEDOUT;
|
|
77 return -1;
|
|
78 }
|
|
79 }
|
|
80
|
|
81 old_sig = signal(SIGPIPE, SIG_IGN);
|
|
82
|
|
83 res = write(id->fd, buf, strlen(buf));
|
|
84
|
|
85 signal(SIGPIPE, old_sig);
|
|
86
|
|
87 return res;
|
|
88 }
|