1
/* cvm/module_udp.c - UDP CVM server module main routine
2
* Copyright (C) 2001 Bruce Guenter <bruceg@em.ca>
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 2 of the License, or
7
* (at your option) any later version.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24
#include "socket/socket.h"
29
static unsigned short port;
31
static int read_input(void)
33
inbuflen = socket_recv4(sock, inbuffer, BUFSIZE, ip, &port);
34
if (inbuflen == (unsigned)-1) return CVME_IO;
38
static void write_output(void)
40
socket_send4(sock, outbuffer, outbuflen, ip, port);
49
static const char usagestr[] =
50
"usage: cvm-module-udp IP PORT\n";
52
static void usage(void)
54
write(2, usagestr, sizeof usagestr);
58
int main(int argc, char** argv)
64
if (argc != 3) usage();
66
signal(SIGINT, exitfn);
67
signal(SIGTERM, exitfn);
69
if ((he = gethostbyname(argv[1])) == 0) usage();
70
memcpy(ip, he->h_addr_list[0], 4);
71
if ((port = strtoul(argv[2], &tmp, 10)) == 0 ||
72
port >= 0xffff || *tmp != 0) usage();
73
if ((sock = socket_udp()) == -1) perror("socket");
74
if (!socket_bind4(sock, ip, port)) perror("bind");
75
if ((code = cvm_auth_init()) != 0) return code;
80
if ((code = read_input()) != 0) continue;
81
code = handle_request();
82
cvm_fact_end(code & CVME_MASK);
85
} while ((code & CVME_FATAL) == 0);