📄 arp.c
字号:
/* $Header: /usr/cvsroot/target/src/wrn/wm/demo/snmptalk/arp.c,v 1.3 2002/03/11 19:17:06 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 1991-1997 Epilogue Technology Corporation. * Copyright 1998 Integrated Systems, Inc. * All rights reserved. ****************************************************************************//* dump the arp table *//* * $Log: arp.c,v $ * Revision 1.3 2002/03/11 19:17:06 josh * snmptalk's destination address is now stored and passed around * as an ipaddr_t. This required changes to a lot of internal function * calls that used to expect an inaddr_t to be passed around. Also, * snmptalk is now capable of using IPv6 sockets * * Revision 1.2 2001/11/08 16:47:21 tneale * Updated for newset file layout * * Revision 1.1.1.1 2001/11/05 17:49:11 tneale * Tornado shuffle * * Revision 7.10 2001/01/19 22:24:42 paul * Update copyright. * * Revision 7.9 2000/03/17 00:14:32 meister * Update copyright message * * Revision 7.8 1998/06/23 20:56:41 sar * Moved parse.h to snark/h/parse.h * * Revision 7.7 1998/02/25 04:57:52 sra * Update copyrights. * * Revision 7.6 1997/03/20 06:53:43 sra * DFARS-safe copyright text. Zap! * * Revision 7.5 1997/02/25 10:58:16 sra * Update copyright notice, dust under the bed. * * Revision 7.4 1997/02/19 08:10:29 sra * More fun merging snmptalk into snark, general snark cleanup. * * Revision 7.3 1997/01/09 22:44:19 sar * Modified the command calling sequence again, this time to mathc * what snark was using. * * Revision 7.2 1997/01/08 23:26:53 sar * Updated include files to use envoy/h as appropriate after * move from envoy/utils to snark/snmptalk * * Revision 7.1 1997/01/08 01:55:00 sar * Modified to use the snark sty driver for in/output * * Revision 7.0 1996/03/18 20:19:20 sar * Updated rev to 7.0 and copyright to 96 * * Revision 6.1 1995/10/20 22:39:59 sar * Modified call to snmptalk_create_request * * Revision 6.0 1995/05/31 21:49:58 sra * Release 6.0. * * Revision 5.0 1994/05/16 15:57:40 sar * Updated revision to 5.0 and copyright to include 1994 * * Revision 4.0 1993/06/24 17:14:56 sar * Updated rev to 4.0 and copyright to 93 * * Revision 3.3 1993/05/19 20:38:22 sar * Added procedure prototypes to some of the routines. (#if !defined(NO_PP)...) * * Revision 3.2 1993/02/22 21:04:10 dab * Changed to use SNMPTalk_Create_Request so does either v1 or v2. * * Revision 3.1 1993/02/05 18:47:56 dab * Changed "system.h" to <snmptalk.h> * * Revision 3.0 1992/04/03 19:53:14 dab * Release 3.0 * * Revision 1.5 91/11/06 13:54:09 dab * Added function prototypes for internal functions and other fixups so * pickier compilers would be happy. * * Revision 1.4 91/11/04 16:12:58 dab * Improved for use with higher warning levels on the compiler. * * Revision 1.3 91/10/30 09:19:07 dab * Don't do command if destination isn't set. * * Revision 1.2 91/10/24 11:55:17 dab * Changed to call oidorder instead of oidcmp. * * Revision 1.1 91/09/30 14:07:47 dab * Initial revision * *//* [clearcase]modification history-------------------01a,19apr05,job update copyright notices*/#include <snmptalk.h>#include <stdio.h>#include <wrn/wm/snmp/engine/asn1.h>#include <wrn/wm/snmp/engine/localio.h>#include <wrn/wm/snmp/engine/buffer.h>#include <wrn/wm/snmp/engine/objectid.h>#include <wrn/wm/snmp/engine/snmp.h>#include <wrn/wm/snmp/engine/auxfuncs.h>#include <wrn/wm/snmp/engine/buildpkt.h>#include "md.h"#include "snmpint.h"#include "mibutils.h"#include <wrn/wm/demo/snarklib.h>#include <wrn/wm/demo/snmpconf.h>enum help_level { help_none, help_short, help_long };#define OIDSZ(oid) (sizeof(oid)/sizeof(OIDC_T))#define INSTANCE(oid) (oid + OIDSZ(oid))/* Make the typing a bit easier */#define MIB2 1, 3, 6, 1, 2, 1#define ip MIB2, 4#define nmTable ip, 22#define nmEntry nmTable, 1/* no instance space needed */OIDC_T nmPhys[] = { nmEntry, 2 };OIDC_T nmType[] = { nmEntry, 4 };extern int req_id;static void arp_error(struct sty *sty, char *err_msg){ sty_printf(sty, "%s\n", err_msg); command_next(sty);}/* Handle responses while ARP dumping. If we're still in the ARP table then * print what we learned and go on to the next. */static void arp_response(struct sty *sty, SNMP_PKT_T *rpkt){ SNMP_PKT_T *tpkt; VB_T *vbl; static char bad_type[] = "<type>"; char pbuf[20]; OIDC_T *oid; int i; unsigned char *cp; char *err_msg; /* If we get an error back from the agent. */ if (rpkt->pdu.std_pdu.error_status != NO_ERROR) { print_snmp_error(sty, rpkt); command_next(sty); } else { vbl = rpkt->pdu.std_pdu.std_vbl.vblist; if (vbl == 0) { sty_puts(sty, "varbind list is empty\n"); command_next(sty); } else { /* Check that we're still in the ARP table */ oid = vbl->vb_obj_id.component_list; if ((vbl->vb_obj_id.num_components < OIDSZ(nmType)) || (oidorder(nmType, oid, OIDSZ(nmType)) != 0)) { command_next(sty); } else { /* Packet for next row */ tpkt = SNMPTalk_Create_Request(GET_NEXT_REQUEST_PDU, 2, 0, 0); /* nmType */ if (vbl->vb_data_flags_n_type != VT_NUMBER) sty_printf(sty, "%-10s ", bad_type); else { int2string(nmType, OIDSZ(nmType), vbl->value_u.v_number, pbuf, sizeof(pbuf), 1); sty_printf(sty, "%-10s ", pbuf); } SNMP_Bind_Null(tpkt, 0, vbl->vb_obj_id.num_components, vbl->vb_obj_id.component_list);/* get next one */ /* Show the instance (IP address) */ sprintf(pbuf, "%d.%d.%d.%d", (int)*(oid + OIDSZ(nmType) + 1), (int)*(oid + OIDSZ(nmType) + 2), (int)*(oid + OIDSZ(nmType) + 3), (int)*(oid + OIDSZ(nmType) + 4)); sty_printf(sty, "%15s ", pbuf); /* nmPhys */ vbl++; sty_printf(sty, "-- "); if (vbl->vb_data_flags_n_type != VT_STRING) sty_printf(sty, "%10s\n", bad_type); else { cp = vbl->value_u.v_string.start_bp; for (i = EBufferUsed(&vbl->value_u.v_string); i; i--) sty_printf(sty, "%02x%c", *cp++, i > 1 ? ':' : '\n'); } SNMP_Bind_Null(tpkt, 1, vbl->vb_obj_id.num_components, vbl->vb_obj_id.component_list);/* get next one */ /* Get next row */ err_msg = snmp_send_rec(sty, tpkt, &dest_addr, arp_response, arp_error); if (err_msg) { sty_printf(sty, "%s\n", err_msg); command_next(sty); } } } } SNMP_Free(rpkt);}boolean_t do_arp(struct sty *sty, enum help_level help, int argc, char *argv[]){ SNMP_PKT_T *tpkt; char *err_msg; switch (help) { case help_short: sty_puts(sty, "arp - dump ARP cache\n"); break; case help_long: sty_puts(sty, "\The 'arp' command gets the data from the destination's\n\ARP table and prints it.\n"); break; case help_none: if (!destination) { sty_puts(sty, "Need to specify destination first\n"); return 1; } /* Create the first request. */ tpkt = SNMPTalk_Create_Request(GET_NEXT_REQUEST_PDU, 2, 0, 0); SNMP_Bind_Null(tpkt, /* index to set */ 0, OIDSZ(nmType), nmType); SNMP_Bind_Null(tpkt, /* index to set */ 1, OIDSZ(nmPhys), nmPhys); err_msg = snmp_send_rec(sty, tpkt, &dest_addr, arp_response, arp_error); if (err_msg) { sty_printf(sty, "%s\n", err_msg); return(1); } return(0); } return(1);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -