⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 snmp_api.h

📁 嵌入式操作系统ECOS的网络开发包
💻 H
📖 第 1 页 / 共 3 页
字号:
//==========================================================================
//
//      ./lib/current/include/snmp_api.h
//
//
//==========================================================================
//####ECOSGPLCOPYRIGHTBEGIN####
// -------------------------------------------
// This file is part of eCos, the Embedded Configurable Operating System.
// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.
//
// eCos is free software; you can redistribute it and/or modify it under
// the terms of the GNU General Public License as published by the Free
// Software Foundation; either version 2 or (at your option) any later version.
//
// eCos is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
// for more details.
//
// You should have received a copy of the GNU General Public License along
// with eCos; if not, write to the Free Software Foundation, Inc.,
// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
//
// As a special exception, if other files instantiate templates or use macros
// or inline functions from this file, or you compile this file and link it
// with other works to produce a work based on this file, this file does not
// by itself cause the resulting work to be covered by the GNU General Public
// License. However the source code for this file must still be made available
// in accordance with section (3) of the GNU General Public License.
//
// This exception does not invalidate any other reasons why a work based on
// this file might be covered by the GNU General Public License.
//
// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.
// at http://sources.redhat.com/ecos/ecos-license/
// -------------------------------------------
//####ECOSGPLCOPYRIGHTEND####
//####UCDSNMPCOPYRIGHTBEGIN####
//
// -------------------------------------------
//
// Portions of this software may have been derived from the UCD-SNMP
// project,  <http://ucd-snmp.ucdavis.edu/>  from the University of
// California at Davis, which was originally based on the Carnegie Mellon
// University SNMP implementation.  Portions of this software are therefore
// covered by the appropriate copyright disclaimers included herein.
//
// The release used was version 4.1.2 of May 2000.  "ucd-snmp-4.1.2"
// -------------------------------------------
//
//####UCDSNMPCOPYRIGHTEND####
//==========================================================================
//#####DESCRIPTIONBEGIN####
//
// Author(s):    hmt
// Contributors: hmt
// Date:         2000-05-30
// Purpose:      Port of UCD-SNMP distribution to eCos.
// Description:  
//              
//
//####DESCRIPTIONEND####
//
//==========================================================================
/********************************************************************
       Copyright 1989, 1991, 1992 by Carnegie Mellon University

			  Derivative Work -
Copyright 1996, 1998, 1999, 2000 The Regents of the University of California

			 All Rights Reserved

Permission to use, copy, modify and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appears in all copies and
that both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU and The Regents of
the University of California not be used in advertising or publicity
pertaining to distribution of the software without specific written
permission.

CMU AND THE REGENTS OF THE UNIVERSITY OF CALIFORNIA DISCLAIM ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL CMU OR
THE REGENTS OF THE UNIVERSITY OF CALIFORNIA BE LIABLE FOR ANY SPECIAL,
INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
FROM THE LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF
CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*********************************************************************/
#ifndef SNMP_API_H
#define SNMP_API_H

/*
 * snmp_api.h - API for access to snmp.
 *
 * Caution: when using this library in a multi-threaded application,
 * the values of global variables "snmp_errno" and "snmp_detail"
 * cannot be reliably determined.  Suggest using snmp_error()
 * to obtain the library error codes.
 */

#ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
#define SET_SNMP_ERROR(x) snmp_errno=(x)
#else
#define SET_SNMP_ERROR(x) 
#endif

 
#ifdef __cplusplus
extern "C" {
#endif

/***********************************************************
	Copyright 1989 by Carnegie Mellon University

                      All Rights Reserved

Permission to use, copy, modify, and distribute this software and its
documentation for any purpose and without fee is hereby granted,
provided that the above copyright notice appear in all copies and that
both that copyright notice and this permission notice appear in
supporting documentation, and that the name of CMU not be
used in advertising or publicity pertaining to distribution of the
software without specific, written prior permission.

CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
SOFTWARE.
******************************************************************/


struct variable_list;
struct timeval;


	/*
	 * Mimic size and alignment of 'struct sockaddr_storage' (see RFC 2553)
	 * But retain field names of traditional 'struct sockaddr'
	 */

#define _UCD_SS_MAXSIZE   92		/* <= sizeof( sockaddr_un ) */
#define _UCD_SS_ALIGNSIZE (sizeof (long))

#define _UCD_SS_PAD1SIZE  (_UCD_SS_ALIGNSIZE - sizeof( unsigned short ))
#define _UCD_SS_PAD2SIZE  (_UCD_SS_MAXSIZE - \
		(sizeof( unsigned short ) + _UCD_SS_PAD1SIZE + _UCD_SS_ALIGNSIZE ))

typedef struct {

#ifdef STRUCT_SOCKADDR_HAS_SA_UNION_SA_GENERIC_SA_FAMILY2
	/*
	 * Certain systems (notably Irix 6.x) have a non-traditional
	 *   socket structure, and #define the traditional field names.
	 * This local definition should reproduce this structure, and still
	 *    be large enough to handle any necessary Unix domain addresses.
	 */
  union {
   struct {
#ifdef _HAVE_SA_LEN
    unsigned char	sa_len2;
    unsigned char	sa_family2;
#else
    unsigned short	sa_family2;
#endif
    char		sa_data2[ _UCD_SS_PAD1SIZE ];
   } sa_generic;
    long		sa_align;
    char		sa_pad2[ _UCD_SS_PAD2SIZE ];
  } sa_union;

#else

#ifdef STRUCT_SOCKADDR_HAS_SA_LEN
    unsigned char	sa_len;
    unsigned char	sa_family;
#else
    unsigned short	sa_family;
#endif
    char		sa_data[ _UCD_SS_PAD1SIZE ];
    long		sa_align;
    char		sa_pad2[ _UCD_SS_PAD2SIZE ];
#endif

} snmp_ipaddr;

#define USM_AUTH_KU_LEN     32
#define USM_PRIV_KU_LEN     32

struct snmp_pdu {

	/*
	 * Protocol-version independent fields
	 */
    long    version;
    int	    command;	/* Type of this PDU */
    long    reqid;	/* Request id - note: not incremented on retries */
    long    msgid;      /* Message id for V3 messages 
                         * note: incremented for each retry */
    long    transid;    /* Unique ID for incoming transactions */
    long    sessid;     /* Session id for AgentX messages */
    long    errstat;	/* Error status (non_repeaters in GetBulk) */
    long    errindex;	/* Error index (max_repetitions in GetBulk) */
    u_long  time;	/* Uptime */
    u_long  flags;

    int	    securityModel;
    int	    securityLevel;  /* noAuthNoPriv, authNoPriv, authPriv */
    int	    msgParseModel;

    snmp_ipaddr  address;	/* Address of peer or trap destination */

    struct variable_list *variables;


	/*
	 * SNMPv1 & SNMPv2c fields
	 */
    u_char  *community;		/* community for outgoing requests. */
    size_t  community_len;	/* Length of community name. */

	/*
	 * Trap information
	 */
    oid	    *enterprise;	/* System OID */
    size_t  enterprise_length;
    long    trap_type;		/* trap type */
    long    specific_type;	/* specific type */
    snmp_ipaddr	agent_addr;

	/*
	 * SNMPv3 fields
	 */
    u_char  *contextEngineID;	/* context snmpEngineID */
    size_t  contextEngineIDLen; /* Length of contextEngineID */
    char    *contextName;	/* authoritative contextName */
    size_t  contextNameLen;	/* Length of contextName */
    u_char  *securityEngineID;	/* authoritative snmpEngineID for security */
    size_t  securityEngineIDLen;/* Length of securityEngineID */
    char    *securityName;	/* on behalf of this principal */
    size_t  securityNameLen;	/* Length of securityName. */

	/*
	 * AgentX fields
	 *	(also uses SNMPv1 community field)
	 */
    int	    priority;
    int	    range_subid;

    void * securityStateRef;
};

struct snmp_session;
typedef int (*snmp_callback) (int, struct snmp_session *, int, struct snmp_pdu *, void *);

struct snmp_session {
	/*
	 * Protocol-version independent fields
	 */
    long  version;
    int	    retries;	/* Number of retries before timeout. */
    long    timeout;    /* Number of uS until first timeout, then exponential backoff */
    u_long  flags;
    struct  snmp_session *subsession;
    struct  snmp_session *next;

    char    *peername;	/* Domain name or dotted IP address of default peer */
    u_short remote_port;/* UDP port number of peer. */
    u_short local_port; /* My UDP port number, 0 for default, picked randomly */
    /* Authentication function or NULL if null authentication is used */
    u_char    *(*authenticator) (u_char *, size_t *, u_char *, size_t);
    snmp_callback callback; /* Function to interpret incoming data */
    /* Pointer to data that the callback function may consider important */
    void    *callback_magic;

    int     s_errno;        /* copy of system errno */
    int     s_snmp_errno;   /* copy of library errno */
    long    sessid;         /* Session id - AgentX only */

	/*
	 * SNMPv1 & SNMPv2c fields

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -