📄 interfaces.c
字号:
* This assumes that the table is a 'simple' table.
* See the implementation documentation for the meaning of this.
* You will need to provide the correct value for the TABLE_SIZE parameter
*
* If this table does not meet the requirements for a simple table,
* you will need to provide the replacement code yourself.
* Mib2c is not smart enough to write this for you.
* Again, see the implementation documentation for what is required.
*/
if ( header_simple_table( vp,name,length,exact,var_len,write_method,
interface_count)
== MATCH_FAILED )
return NULL;
if_num = name[ (*length)-1 ];
ifp = cyg_snmp_get_if(if_num);
if (!ifp)
return NULL;
// This is to assist customers with their own special interfaces; if they
// define IFT_CUSTOMER_SPECIAL to whatever their own device is, then its
// ioctl() will be called to handle these enquiries.
#ifdef IFT_CUSTOMER_SPECIAL
if ( (ifp->if_type == IFT_CUSTOMER_SPECIAL) && (NULL != ifp->if_ioctl) )
{
if( (vp->magic == IFDESCR) || (vp->magic == IFPHYSADDRESS) )
{
(*ifp->if_ioctl)(ifp, vp->magic, (caddr_t)string);
*var_len = strlen(string);
return (unsigned char *) string;
}
else
{
(*ifp->if_ioctl)(ifp, vp->magic, (caddr_t)&long_ret);
return (unsigned char *) &long_ret;
}
}
#endif // IFT_CUSTOMER_SPECIAL
if ( IFT_ETHER == ifp->if_type &&
((IFDESCR == vp->magic) ||
(IFSPEED == vp->magic) ||
(IFOUTDISCARDS == vp->magic) ||
(IFOUTQLEN == vp->magic) )
) {
// then acquire up to date information and deal with the relevent
// keys (only):
int i = -1;
struct ether_drv_stats x;
bzero( &x, sizeof( x ) );
// Call the ioctl to get all the info.
// (We KNOW it's an ether dev here, it should have an ioctl())
if ( NULL != ifp->if_ioctl )
i = (*ifp->if_ioctl)(ifp, SIOCGIFSTATSUD, (caddr_t)&x);
switch(vp->magic) {
case IFDESCR:
if ( i || 0 == x.description[0] )
strcpy( string, "<Ethernet, details not available>" );
else
strcpy( string, x.description );
*var_len = strlen(string);
return (unsigned char *) string;
case IFSPEED:
long_ret = x.speed;
return (unsigned char *) &long_ret;
case IFOUTDISCARDS:
long_ret = x.tx_dropped;
return (unsigned char *) &long_ret;
case IFOUTQLEN:
long_ret = x.tx_queue_len;
return (unsigned char *) &long_ret;
default:
CYG_FAIL( "Bad magic; shouldn't be in here" );
break;
}
}
switch(vp->magic) {
case IFINDEX:
long_ret = name[(*length)-1];
return (unsigned char *) &long_ret;
case IFDESCR:
switch ( ifp->if_type ) {
case IFT_LOOP:
strcpy( string, "(Loopback device)" );
break;
case IFT_PROPVIRTUAL:
strcpy( string, "(Proprietary Virtual/Internal)" );
break;
case IFT_PPP:
strcpy( string, "(Point to point interface)" );
break;
default:
strcpy( string, "Some shy network adaptor" );
break;
}
*var_len = strlen(string);
return (unsigned char *) string;
case IFTYPE:
long_ret = ifp->if_type;
return (unsigned char *) &long_ret;
case IFMTU:
long_ret = ifp->if_mtu;
return (unsigned char *) &long_ret;
case IFSPEED:
if ( IFT_LOOP == ifp->if_type )
long_ret = 0;
else
long_ret = ifp->if_baudrate;
return (unsigned char *) &long_ret;
case IFPHYSADDRESS: {
if ( IFT_ETHER == ifp->if_type ) {
struct arpcom *ac = (struct arpcom *)ifp;
bcopy(&ac->ac_enaddr, string, ETHER_ADDR_LEN);
}
else {
bzero( string, ETHER_ADDR_LEN );
}
*var_len = ETHER_ADDR_LEN;
return (unsigned char *) string;
}
case IFADMINSTATUS:
//NOTSUPPORTED: *write_method = write_ifAdminStatus;
long_ret = (ifp->if_flags & IFF_RUNNING) ? 1 : 2;
return (unsigned char *) &long_ret;
case IFOPERSTATUS:
long_ret = (ifp->if_flags & IFF_UP) ? 1 : 2;
return (unsigned char *) &long_ret;
case IFLASTCHANGE:
long_ret = 0; //FIXME: ifp->if_lastchange;
return (unsigned char *) &long_ret;
case IFINOCTETS:
long_ret = ifp->if_ibytes;
return (unsigned char *) &long_ret;
case IFINUCASTPKTS:
long_ret = ifp->if_ipackets - ifp->if_imcasts;
return (unsigned char *) &long_ret;
case IFINNUCASTPKTS:
long_ret = ifp->if_imcasts;
return (unsigned char *) &long_ret;
case IFINDISCARDS:
long_ret = ifp->if_iqdrops;
return (unsigned char *) &long_ret;
case IFINERRORS:
long_ret = ifp->if_ierrors;
return (unsigned char *) &long_ret;
case IFINUNKNOWNPROTOS:
long_ret = ifp->if_noproto;
return (unsigned char *) &long_ret;
case IFOUTOCTETS:
long_ret = ifp->if_obytes;
return (unsigned char *) &long_ret;
case IFOUTUCASTPKTS:
long_ret = ifp->if_opackets - ifp->if_omcasts;
return (unsigned char *) &long_ret;
case IFOUTNUCASTPKTS:
long_ret = ifp->if_omcasts;
return (unsigned char *) &long_ret;
case IFOUTDISCARDS:
long_ret = 0; // ETHER case dealt with above
return (unsigned char *) &long_ret;
case IFOUTERRORS:
long_ret = ifp->if_oerrors;
return (unsigned char *) &long_ret;
case IFOUTQLEN:
long_ret = 0; // ETHER case dealt with above
return (unsigned char *) &long_ret;
case IFSPECIFIC:
objid[0] = 0;
objid[1] = 0;
*var_len = 2*sizeof(oid);
return (unsigned char *) objid;
default:
ERROR_MSG("");
}
return NULL;
}
//NOTSUPPORTED:
#if 0
int
write_ifAdminStatus(int action,
u_char *var_val,
u_char var_val_type,
size_t var_val_len,
u_char *statP,
oid *name,
size_t name_len)
{
static long *long_ret;
int size;
switch ( action ) {
case RESERVE1:
if (var_val_type != ASN_INTEGER){
fprintf(stderr, "write to ifAdminStatus not ASN_INTEGER\n");
return SNMP_ERR_WRONGTYPE;
}
if (var_val_len > sizeof(long_ret)){
fprintf(stderr,"write to ifAdminStatus: bad length\n");
return SNMP_ERR_WRONGLENGTH;
}
break;
case RESERVE2:
size = var_val_len;
long_ret = (long *) var_val;
break;
case FREE:
/* Release any resources that have been allocated */
break;
case ACTION:
/* The variable has been stored in long_ret for you to use,
and you have just been asked to do something with it. Note
that anything done here must be reversable in the UNDO case */
break;
case UNDO:
/* Back out any changes made in the ACTION case */
break;
case COMMIT:
/* Things are working well, so it's now safe to make the change
permanently. Make sure that anything done here can't fail! */
break;
}
return SNMP_ERR_NOERROR;
}
#endif
// EOF interfaces.c
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -