1 /*
2 * SNMP supplies test program for CUPS.
3 *
4 * Copyright © 2020-2024 by OpenPrinting.
5 * Copyright © 2008-2011 by Apple Inc.
6 *
7 * Licensed under Apache License v2.0. See the file "LICENSE" for more
8 * information.
9 */
10
11 /*
12 * Include necessary headers.
13 */
14
15 #include "backend-private.h"
16
17
18 /*
19 * 'main()' - Show the supplies state of a printer.
20 */
21
22 int /* O - Exit status */
main(int argc,char * argv[])23 main(int argc, /* I - Number of command-line args */
24 char *argv[]) /* I - Command-line arguments */
25 {
26 http_addrlist_t *host; /* Host addresses */
27 int snmp_fd; /* SNMP socket */
28 int page_count, /* Current page count */
29 printer_state; /* Current printer state */
30
31
32 if (argc != 2)
33 {
34 puts("Usage: testsupplies ip-or-hostname");
35 return (1);
36 }
37
38 if ((host = httpAddrGetList(argv[1], AF_UNSPEC, "9100")) == NULL)
39 {
40 perror(argv[1]);
41 return (1);
42 }
43
44 if ((snmp_fd = _cupsSNMPOpen(host->addr.addr.sa_family)) < 0)
45 {
46 perror(argv[1]);
47 return (1);
48 }
49
50 for (;;)
51 {
52 fputs("backendSNMPSupplies: ", stdout);
53
54 if (backendSNMPSupplies(snmp_fd, &(host->addr), &page_count,
55 &printer_state))
56 {
57 puts("FAIL");
58 return (1);
59 }
60
61 printf("backendSNMPSupplies: %s (page_count=%d, printer_state=%d)\n",
62 page_count < 0 || printer_state < CUPS_TC_other ||
63 printer_state > CUPS_TC_warmup ? "FAIL" : "PASS",
64 page_count, printer_state);
65
66 sleep(5);
67 }
68 }
69