]>
jfr.im git - solanum.git/blob - servlink/servlink.c
1 /************************************************************************
2 * IRC - Internet Relay Chat, servlink/servlink.c
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 1, or (at your option)
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
18 * $Id: servlink.c 6 2005-09-10 01:02:21Z nenolod $
23 #include <sys/types.h>
25 #include <sys/socket.h>
40 static void usage(void);
42 struct slink_state in_state
;
43 struct slink_state out_state
;
45 struct fd_table fds
[3] = {
46 {0, read_ctrl
, NULL
}, /* ctrl */
47 {0, NULL
, NULL
}, /* data */
48 {0, NULL
, NULL
}, /* net */
53 * Display usage message
58 fprintf(stderr
, "ircd-ratbox server link v1.2\n");
59 fprintf(stderr
, "2004-03-02\n");
60 fprintf(stderr
, "\n");
61 fprintf(stderr
, "This program is called by the ircd-ratbox ircd.\n");
62 fprintf(stderr
, "It cannot be used on its own.\n");
67 main(int argc
, char *argv
[])
78 /* Make sure we are running under ircd.. */
80 if(argc
!= 4 || strcmp(argv
[0], "-slink"))
84 for (i
= 0; i
< 3; i
++)
86 fds
[i
].fd
= atoi(argv
[i
+ 1]);
91 for (i
= 0; i
< 3; i
++)
93 /* XXX: Hack alert...we need to do dup2() here for some dumb
94 * platforms (Solaris) that don't like select using fds > 255
99 for(x
= 0; x
< 255; x
++)
101 if(x
!= fds
[0].fd
&& x
!= fds
[1].fd
&& x
!= fds
[2].fd
)
103 if(dup2(fds
[i
].fd
, x
) < 0)
111 fcntl(fds
[i
].fd
, F_SETFL
, O_NONBLOCK
);
112 if(fds
[i
].fd
> max_fd
)