~ubuntu-branches/ubuntu/saucy/nut/saucy

« back to all changes in this revision

Viewing changes to clients/upsct.c

  • Committer: Bazaar Package Importer
  • Author(s): Arnaud Quette
  • Date: 2004-05-28 13:10:01 UTC
  • mto: (16.1.1 squeeze)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040528131001-yj2m9qcez4ya2w14
Tags: upstream-1.4.2
ImportĀ upstreamĀ versionĀ 1.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* upsct - simple "client" to test communications (TCP mode)
2
 
 
3
 
   Copyright (C) 1999  Russell Kroll <rkroll@exploits.org>
4
 
 
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.
9
 
 
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.
14
 
 
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
18
 
*/
19
 
 
20
 
#include "common.h"
21
 
 
22
 
#include <netdb.h>
23
 
#include <netinet/in.h>
24
 
#include <sys/socket.h>
25
 
#include "upsfetch.h"
26
 
 
27
 
int main (int argc, char **argv)
28
 
{
29
 
        char    vars[LARGEBUF], value[128], *v, *upsname, *ptr, *host;
30
 
        int     fd;
31
 
 
32
 
        if (argc < 2) {
33
 
                printf ("usage: %s <host>\n", argv[0]);
34
 
                exit (1);
35
 
        }
36
 
 
37
 
        /* handle upsname@hostname syntax and split up parts */
38
 
        ptr = strstr (argv[1], "@");
39
 
        if (ptr != NULL) {
40
 
                ptr[0] = 0;
41
 
                upsname = argv[1];
42
 
                host = ptr + 1;
43
 
        }
44
 
        else {
45
 
                upsname = NULL;
46
 
                host = argv[1];
47
 
        }
48
 
 
49
 
        fd = upsconnect (host);
50
 
        if (fd < 0) {
51
 
                printf ("Unable to connect to %s - %s\n", host,
52
 
                        upsstrerror(upserror));
53
 
                exit (1);
54
 
        }
55
 
 
56
 
        if (getupsvarlistfd (fd, upsname, vars, sizeof(vars)) < 0) {
57
 
                printf ("Unable to get variable list - %s\n", 
58
 
                        upsstrerror(upserror));
59
 
                exit (1);
60
 
        }
61
 
 
62
 
        printf ("host: %s\n", host);
63
 
 
64
 
        if (strlen(vars) == 0) {
65
 
                printf ("No variables available!  Check your configuration (ups.conf and upsd.conf)\n");
66
 
                exit (1);
67
 
        }
68
 
 
69
 
        v = vars;
70
 
        while (v != NULL) {
71
 
                ptr = strchr (v, ' ');
72
 
                if (ptr)
73
 
                        *ptr++ = '\0';
74
 
 
75
 
                printf ("%s: ", v);
76
 
                if (getupsvarfd(fd, upsname, v, value, sizeof(value)) < 0)
77
 
                        printf ("Error: %s\n", upsstrerror(upserror));
78
 
                else
79
 
                        printf ("%s\n", value);
80
 
 
81
 
                v = ptr;
82
 
        }               
83
 
 
84
 
        return (0);
85
 
}