1/* 2 * "$Id: snmp-private.h 11560 2014-02-06 20:10:19Z msweet $" 3 * 4 * Private SNMP definitions for CUPS. 5 * 6 * Copyright 2007-2014 by Apple Inc. 7 * Copyright 2006-2007 by Easy Software Products, all rights reserved. 8 * 9 * These coded instructions, statements, and computer programs are the 10 * property of Apple Inc. and are protected by Federal copyright 11 * law. Distribution and use rights are outlined in the file "LICENSE.txt" 12 * "LICENSE" which should have been included with this file. If this 13 * file is missing or damaged, see the license at "http://www.cups.org/". 14 * 15 * This file is subject to the Apple OS-Developed Software exception. 16 */ 17 18#ifndef _CUPS_SNMP_PRIVATE_H_ 19# define _CUPS_SNMP_PRIVATE_H_ 20 21 22/* 23 * Include necessary headers. 24 */ 25 26#include <cups/http.h> 27 28 29/* 30 * Constants... 31 */ 32 33#define CUPS_SNMP_PORT 161 /* SNMP well-known port */ 34#define CUPS_SNMP_MAX_COMMUNITY 512 /* Maximum size of community name */ 35#define CUPS_SNMP_MAX_OID 128 /* Maximum number of OID numbers */ 36#define CUPS_SNMP_MAX_PACKET 1472 /* Maximum size of SNMP packet */ 37#define CUPS_SNMP_MAX_STRING 1024 /* Maximum size of string */ 38#define CUPS_SNMP_VERSION_1 0 /* SNMPv1 */ 39 40 41/* 42 * Types... 43 */ 44 45enum cups_asn1_e /**** ASN1 request/object types ****/ 46{ 47 CUPS_ASN1_END_OF_CONTENTS = 0x00, /* End-of-contents */ 48 CUPS_ASN1_BOOLEAN = 0x01, /* BOOLEAN */ 49 CUPS_ASN1_INTEGER = 0x02, /* INTEGER or ENUMERATION */ 50 CUPS_ASN1_BIT_STRING = 0x03, /* BIT STRING */ 51 CUPS_ASN1_OCTET_STRING = 0x04, /* OCTET STRING */ 52 CUPS_ASN1_NULL_VALUE = 0x05, /* NULL VALUE */ 53 CUPS_ASN1_OID = 0x06, /* OBJECT IDENTIFIER */ 54 CUPS_ASN1_SEQUENCE = 0x30, /* SEQUENCE */ 55 CUPS_ASN1_HEX_STRING = 0x40, /* Binary string aka Hex-STRING */ 56 CUPS_ASN1_COUNTER = 0x41, /* 32-bit unsigned aka Counter32 */ 57 CUPS_ASN1_GAUGE = 0x42, /* 32-bit unsigned aka Gauge32 */ 58 CUPS_ASN1_TIMETICKS = 0x43, /* 32-bit unsigned aka Timeticks32 */ 59 CUPS_ASN1_GET_REQUEST = 0xa0, /* GetRequest-PDU */ 60 CUPS_ASN1_GET_NEXT_REQUEST = 0xa1, /* GetNextRequest-PDU */ 61 CUPS_ASN1_GET_RESPONSE = 0xa2 /* GetResponse-PDU */ 62}; 63typedef enum cups_asn1_e cups_asn1_t; /**** ASN1 request/object types ****/ 64 65typedef struct cups_snmp_string_s /**** String value ****/ 66{ 67 unsigned char bytes[CUPS_SNMP_MAX_STRING]; 68 /* Bytes in string */ 69 unsigned num_bytes; /* Number of bytes */ 70} cups_snmp_string_t; 71 72union cups_snmp_value_u /**** Object value ****/ 73{ 74 int boolean; /* Boolean value */ 75 int integer; /* Integer value */ 76 int counter; /* Counter value */ 77 unsigned gauge; /* Gauge value */ 78 unsigned timeticks; /* Timeticks value */ 79 int oid[CUPS_SNMP_MAX_OID]; /* OID value */ 80 cups_snmp_string_t string; /* String value */ 81}; 82 83typedef struct cups_snmp_s /**** SNMP data packet ****/ 84{ 85 const char *error; /* Encode/decode error */ 86 http_addr_t address; /* Source address */ 87 int version; /* Version number */ 88 char community[CUPS_SNMP_MAX_COMMUNITY]; 89 /* Community name */ 90 cups_asn1_t request_type; /* Request type */ 91 unsigned request_id; /* request-id value */ 92 int error_status; /* error-status value */ 93 int error_index; /* error-index value */ 94 int object_name[CUPS_SNMP_MAX_OID]; 95 /* object-name value */ 96 cups_asn1_t object_type; /* object-value type */ 97 union cups_snmp_value_u 98 object_value; /* object-value value */ 99} cups_snmp_t; 100 101typedef void (*cups_snmp_cb_t)(cups_snmp_t *packet, void *data); 102 103/* 104 * Prototypes... 105 */ 106 107# ifdef __cplusplus 108extern "C" { 109# endif /* __cplusplus */ 110 111extern void _cupsSNMPClose(int fd) _CUPS_API_1_4; 112extern int *_cupsSNMPCopyOID(int *dst, const int *src, int dstsize) 113 _CUPS_API_1_4; 114extern const char *_cupsSNMPDefaultCommunity(void) _CUPS_API_1_4; 115extern int _cupsSNMPIsOID(cups_snmp_t *packet, const int *oid) 116 _CUPS_API_1_4; 117extern int _cupsSNMPIsOIDPrefixed(cups_snmp_t *packet, 118 const int *prefix) _CUPS_API_1_4; 119extern char *_cupsSNMPOIDToString(const int *src, char *dst, 120 size_t dstsize) _CUPS_API_1_4; 121extern int _cupsSNMPOpen(int family) _CUPS_API_1_4; 122extern cups_snmp_t *_cupsSNMPRead(int fd, cups_snmp_t *packet, 123 double timeout) _CUPS_API_1_4; 124extern void _cupsSNMPSetDebug(int level) _CUPS_API_1_4; 125extern int *_cupsSNMPStringToOID(const char *src, 126 int *dst, int dstsize) 127 _CUPS_API_1_4; 128extern int _cupsSNMPWalk(int fd, http_addr_t *address, int version, 129 const char *community, const int *prefix, 130 double timeout, cups_snmp_cb_t cb, 131 void *data) _CUPS_API_1_4; 132extern int _cupsSNMPWrite(int fd, http_addr_t *address, int version, 133 const char *community, 134 cups_asn1_t request_type, 135 const unsigned request_id, 136 const int *oid) _CUPS_API_1_4; 137 138# ifdef __cplusplus 139} 140# endif /* __cplusplus */ 141#endif /* !_CUPS_SNMP_PRIVATE_H_ */ 142 143 144/* 145 * End of "$Id: snmp-private.h 11560 2014-02-06 20:10:19Z msweet $". 146 */ 147