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

📄 general.c

📁 wm PNE 3.3 source code, running at more than vxworks6.x version.
💻 C
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/unxagent/sun/general.c,v 1.2 2001/11/09 21:49:01 josh Exp $ *//* * Copyright (C) 1999-2005 Wind River Systems, Inc. * All rights reserved.  Provided under license only. * Distribution or other use of this software is only * permitted pursuant to the terms of a license agreement * from Wind River Systems (and is otherwise prohibited). * Refer to that license agreement for terms of use. *//**************************************************************************** *  Copyright 1988-1997 Epilogue Technology Corporation. *  Copyright 1998 Integrated Systems, Inc. *  All rights reserved. ****************************************************************************//* * $Log: general.c,v $ * Revision 1.2  2001/11/09 21:49:01  josh * unxagent demo path adjustment, first pass * * Revision 1.1.1.1  2001/11/05 17:49:16  tneale * Tornado shuffle * * Revision 7.6  2001/01/19 22:25:01  paul * Update copyright. * * Revision 7.5  2000/03/17 00:15:16  meister * Update copyright message * * Revision 7.4  1998/02/25 04:58:18  sra * Update copyrights. * * Revision 7.3  1997/03/20 06:54:07  sra * DFARS-safe copyright text.  Zap! * * Revision 7.2  1997/02/25 10:58:16  sra * Update copyright notice, dust under the bed. * * Revision 7.1  1997/01/08 23:01:49  sar * Updated copyright and modified include files to use envoy/h as * appropriate * * Revision 7.0  1996/03/15  22:07:57  sar * Updated revision to 7.0 and copyright to 96 * * Revision 6.1  1995/11/01  01:03:00  sar * added pp style argument lists * repaginated * * Revision 6.0  1995/05/31  21:49:42  sra * Release 6.0. * * Revision 5.0  1994/05/16  16:20:43  sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0  1993/06/24  17:34:02  sar * Updated rev to 4.0 copyright to 93 * * Revision 3.2  1993/06/13  02:53:35  sar * Removed sysent.h and libc.h and moved them into envoy.h * for mach386. * * Revision 3.1  1993/05/13  22:20:00  sar * Added defines, includes (<sysent.h>, <errno.h>, <libc.h>) and casts * (struct sockaddr *) as well as changed memfoo to MEMFOO and objidcmp * to llist_cmp to get rid of warnings. * * Revision 3.0  1992/04/03  19:53:44  dab * Release 3.0 * * Revision 2.101  92/02/04  10:46:43  dab * Updated for release 3.0 of SNMP. *  * Revision 2.100  92/02/03  16:46:07  dab * Generic unix SNMP agent. *  *  *    Rev 2.0   31 Mar 1990 15:34:20 * Initial revision. * *//* [clearcase]modification history-------------------01a,19apr05,job  update copyright notices*/#include <stdio.h>#include <nlist.h>#include <sys/types.h>#include <sys/stat.h>#include <fcntl.h>#include <sys/socket.h>#include <netinet/in.h>#include <net/if.h>#include <netinet/if_ether.h>#include <errno.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include "../agent.h"#include "snmpvars.h"#include "general.h"/* This routine needs to get into caching in a big way. */off_t  find_loc(struct kernel_symbol *sym){    struct nlist syms[2];    if (sym->flags & KO_FAILED)      return 0;    if (sym->flags & KO_VALID)      return sym->offset;    memset((char *)syms, 0, sizeof(syms));    syms[0].n_name = sym->name;    if (trace_level > 0) {	printf("Looking up kernel variable `%s'\n", sym->name);	fflush(stdout);    }    nlist(kernel_file, syms);    if (syms[0].n_value == 0) {	printf("  Couldn't find kernel variable `%s' in kernel file `%s'\n",	       sym->name, kernel_file);	fflush(stdout);	sym->flags |= KO_FAILED;	return 0;    }    else {	sym->flags |= KO_VALID;	if (trace_level > 2) {	    printf("  Offset is %8.8X(hex)  %d(decimal)\n",		   syms[0].n_value, syms[0].n_value);	    fflush(stdout);	}	return sym->offset = syms[0].n_value;    }}static int kmem = -2;static char kmem_file[] = "/dev/kmem";static char no_kmem[] = "Can not open kernel memory";int  read_int(off_t loc){  int ret_value;  if (kmem == -2) {    kmem = open(kmem_file, O_RDWR, 777);    if (kmem == -1) {      perror(no_kmem);      exit(1);      }    }  if (kmem >= 0) {    lseek(kmem, (long)loc, 0);    read(kmem, &ret_value, sizeof(int));    return ret_value;    }  else    return 0;}int  read_bytes(off_t loc,	     char *buf,	     int   len){  if (kmem == -2)    kmem = open(kmem_file, O_RDWR, 777);  if (kmem == -1) {    perror(no_kmem);    exit(1);    }  if (kmem >= 0) {    lseek(kmem, (long)loc, 0);    len = read(kmem, buf, len);    return len;    }  else    return 0;}int  write_bytes(off_t loc,	      char *buf,	      int   len){  if (kmem == -2)    kmem = open(kmem_file, O_RDWR, 777);  if (kmem == -1) {    perror(no_kmem);    exit(1);    }  if (kmem >= 0) {    lseek(kmem, (long)loc, 0);    len = write(kmem, buf, len);    return len;    }  else    return 0;}

⌨️ 快捷键说明

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