1
/* upsct - simple "client" to test communications (TCP mode)
3
Copyright (C) 1999 Russell Kroll <rkroll@exploits.org>
5
This program is free software; you can redistribute it and/or modify
6
it under the terms of the GNU General Public License as published by
7
the Free Software Foundation; either version 2 of the License, or
8
(at your option) any later version.
10
This program is distributed in the hope that it will be useful,
11
but WITHOUT ANY WARRANTY; without even the implied warranty of
12
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
GNU General Public License for more details.
15
You should have received a copy of the GNU General Public License
16
along with this program; if not, write to the Free Software
17
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23
#include <netinet/in.h>
24
#include <sys/socket.h>
27
int main (int argc, char **argv)
29
char vars[LARGEBUF], value[128], *v, *upsname, *ptr, *host;
33
printf ("usage: %s <host>\n", argv[0]);
37
/* handle upsname@hostname syntax and split up parts */
38
ptr = strstr (argv[1], "@");
49
fd = upsconnect (host);
51
printf ("Unable to connect to %s - %s\n", host,
52
upsstrerror(upserror));
56
if (getupsvarlistfd (fd, upsname, vars, sizeof(vars)) < 0) {
57
printf ("Unable to get variable list - %s\n",
58
upsstrerror(upserror));
62
printf ("host: %s\n", host);
64
if (strlen(vars) == 0) {
65
printf ("No variables available! Check your configuration (ups.conf and upsd.conf)\n");
71
ptr = strchr (v, ' ');
76
if (getupsvarfd(fd, upsname, v, value, sizeof(value)) < 0)
77
printf ("Error: %s\n", upsstrerror(upserror));
79
printf ("%s\n", value);