/*
* "$Id$"
*
- * SNMP test program for the Common UNIX Printing System (CUPS).
+ * SNMP test program for CUPS.
*
- * Copyright 2008 by Apple Inc.
+ * Copyright 2008-2010 by Apple Inc.
*
* These coded instructions, statements, and computer programs are the
* property of Apple Inc. and are protected by Federal copyright
* Include necessary headers...
*/
-#include <stdio.h>
-#include <stdlib.h>
-#include <errno.h>
-#include "string.h"
-#include "snmp.h"
+#include "cups-private.h"
+#include "snmp-private.h"
/*
*/
static void print_packet(cups_snmp_t *packet, void *data);
-static int *scan_oid(const char *s, int *oid, int oidsize);
static int show_oid(int fd, const char *community,
http_addr_t *addr, const char *s, int walk);
static void usage(void);
const char *community; /* Community name */
- fputs("cupsSNMPDefaultCommunity: ", stdout);
+ fputs("_cupsSNMPDefaultCommunity: ", stdout);
- if ((community = cupsSNMPDefaultCommunity()) == NULL)
+ if ((community = _cupsSNMPDefaultCommunity()) == NULL)
{
puts("FAIL (NULL community name)");
return (1);
community = argv[i];
}
else if (!strcmp(argv[i], "-d"))
- cupsSNMPSetDebug(10);
+ _cupsSNMPSetDebug(10);
else if (!strcmp(argv[i], "-w"))
walk = 1;
else if (!host)
if (fd < 0)
{
- fputs("cupsSNMPOpen: ", stdout);
+ fputs("_cupsSNMPOpen: ", stdout);
- if ((fd = cupsSNMPOpen(host->addr.addr.sa_family)) < 0)
+ if ((fd = _cupsSNMPOpen(host->addr.addr.sa_family)) < 0)
{
printf("FAIL (%s)\n", strerror(errno));
return (1);
if (!oid)
{
if (!show_oid(fd, community, &(host->addr),
- walk ? "1.3.6.1.2.1.43" :
- "1.3.6.1.2.1.43.10.2.1.4.1.1", walk))
+ walk ? ".1.3.6.1.2.1.43" :
+ ".1.3.6.1.2.1.43.10.2.1.4.1.1", walk))
return (1);
}
void *data) /* I - User data pointer (not used) */
{
int i; /* Looping var */
+ char temp[1024]; /* Temporary OID string */
(void)data;
- printf("%d", packet->object_name[0]);
- for (i = 1; packet->object_name[i] >= 0; i ++)
- printf(".%d", packet->object_name[i]);
- fputs(" = ", stdout);
+ printf("%s = ", _cupsSNMPOIDToString(packet->object_name, temp, sizeof(temp)));
switch (packet->object_type)
{
break;
case CUPS_ASN1_BIT_STRING :
- printf("BIT-STRING \"%s\"\n", packet->object_value.string);
+ printf("BIT-STRING \"%s\"\n",
+ (char *)packet->object_value.string.bytes);
break;
case CUPS_ASN1_OCTET_STRING :
- printf("OCTET-STRING \"%s\"\n", packet->object_value.string);
+ printf("OCTET-STRING \"%s\"\n",
+ (char *)packet->object_value.string.bytes);
break;
case CUPS_ASN1_NULL_VALUE :
break;
case CUPS_ASN1_OID :
- printf("OID %d", packet->object_value.oid[0]);
- for (i = 1; packet->object_value.oid[i] >= 0; i ++)
- printf(".%d", packet->object_value.oid[i]);
- putchar('\n');
+ printf("OID %s\n", _cupsSNMPOIDToString(packet->object_value.oid,
+ temp, sizeof(temp)));
break;
case CUPS_ASN1_HEX_STRING :
fputs("Hex-STRING", stdout);
- for (i = 0; i < packet->object_value.hex_string.num_bytes; i ++)
- printf(" %02X", packet->object_value.hex_string.bytes[i]);
+ for (i = 0; i < packet->object_value.string.num_bytes; i ++)
+ printf(" %02X", packet->object_value.string.bytes[i]);
putchar('\n');
break;
}
-/*
- * 'scan_oid()' - Scan an OID value.
- */
-
-static int * /* O - OID or NULL on error */
-scan_oid(const char *s, /* I - OID string */
- int *oid, /* I - OID array */
- int oidsize) /* I - Size of OID array in integers */
-{
- int i; /* Index into OID array */
- char *ptr; /* Pointer into string */
-
-
- for (ptr = (char *)s, i = 0, oidsize --; ptr && *ptr && i < oidsize; i ++)
- {
- if (!isdigit(*ptr & 255))
- return (NULL);
-
- oid[i] = strtol(ptr, &ptr, 10);
- if (ptr && *ptr == '.')
- ptr ++;
- }
-
- if (i >= oidsize)
- return (NULL);
-
- oid[i] = -1;
-
- return (oid);
-}
-
-
/*
* 'show_oid()' - Show the specified OID.
*/
int i; /* Looping var */
int oid[CUPS_SNMP_MAX_OID]; /* OID */
cups_snmp_t packet; /* SNMP packet */
+ char temp[1024]; /* Temporary OID string */
- if (!scan_oid(s, oid, sizeof(oid) / sizeof(oid[0])))
+ if (!_cupsSNMPStringToOID(s, oid, sizeof(oid) / sizeof(oid[0])))
{
puts("testsnmp: Bad OID");
return (0);
if (walk)
{
- printf("cupsSNMPWalk(%d", oid[0]);
- for (i = 1; oid[i] >= 0; i ++)
- printf(".%d", oid[i]);
- puts("):");
+ printf("_cupsSNMPWalk(%s): ", _cupsSNMPOIDToString(oid, temp, sizeof(temp)));
- if (cupsSNMPWalk(fd, addr, CUPS_SNMP_VERSION_1, community, oid, 5000,
+ if (_cupsSNMPWalk(fd, addr, CUPS_SNMP_VERSION_1, community, oid, 5.0,
print_packet, NULL) < 0)
{
printf("FAIL (%s)\n", strerror(errno));
}
else
{
- printf("cupsSNMPWrite(%d", oid[0]);
- for (i = 1; oid[i] >= 0; i ++)
- printf(".%d", oid[i]);
- fputs("): ", stdout);
+ printf("_cupsSNMPWrite(%s): ", _cupsSNMPOIDToString(oid, temp, sizeof(temp)));
- if (!cupsSNMPWrite(fd, addr, CUPS_SNMP_VERSION_1, community,
+ if (!_cupsSNMPWrite(fd, addr, CUPS_SNMP_VERSION_1, community,
CUPS_ASN1_GET_REQUEST, 1, oid))
{
printf("FAIL (%s)\n", strerror(errno));
puts("PASS");
- fputs("cupsSNMPRead(5000): ", stdout);
+ fputs("_cupsSNMPRead(5.0): ", stdout);
- if (!cupsSNMPRead(fd, &packet, 5000))
+ if (!_cupsSNMPRead(fd, &packet, 5.0))
{
puts("FAIL (timeout)");
return (0);
}
- if (!cupsSNMPIsOID(&packet, oid))
+ if (!_cupsSNMPIsOID(&packet, oid))
{
printf("FAIL (bad OID %d", packet.object_name[0]);
for (i = 1; packet.object_name[i] >= 0; i ++)