File: id_query.c

package info (click to toggle)
socks4-server 4.3.beta2-6
  • links: PTS
  • area: main
  • in suites: slink
  • size: 1,508 kB
  • ctags: 1,762
  • sloc: ansic: 19,217; makefile: 387; sh: 65
file content (68 lines) | stat: -rw-r--r-- 1,194 bytes parent folder | download | duplicates (9)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
** id_query.c                             Transmit a query to an IDENT server
**
** Author: Peter Eriksson <pen@lysator.liu.se>
*/

#include <stdio.h>
#include <errno.h>
#if defined(ISC)
#include <net/errno.h>
#endif /* #if defined(ISC) */
#include <signal.h>

#include <sys/types.h>
#if defined(ISC)
#include <sys/bsdtypes.h>
#endif /* #if defined(ISC) */
#include <sys/wait.h>
#include <sys/time.h>

#include "ident.h"


int id_query
#ifdef __STDC__
  (ident_t *id, int lport, int fport, struct timeval *timeout)
#else
  (id, lport, fport, timeout)
ident_t *id;
int lport;
int fport;
struct timeval *timeout;
#endif
{
#if defined(SOLARIS) || defined(_SEQUENT_) || defined(SCO)
  void (*old_sig)();
#else
  void *old_sig;
#endif
  int res;
  char buf[80];
  fd_set ws;
  
  sprintf(buf, "%d , %d\r\n", lport, fport);

  if (timeout)
  {
    FD_ZERO(&ws);
    FD_SET(id->fd, &ws);
    
    if ((res = select(FD_SETSIZE, (fd_set *)0, &ws, (fd_set *)0, timeout)) < 0)
      return -1;

    if (res == 0)
    {
      errno = ETIMEDOUT;
      return -1;
    }
  }

  old_sig = signal(SIGPIPE, SIG_IGN);
  
  res = write(id->fd, buf, strlen(buf));

  signal(SIGPIPE, old_sig);
  
  return res;
}