home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.umcs.maine.edu
/
2015-02-07.ftp.umcs.maine.edu.tar
/
ftp.umcs.maine.edu
/
pub
/
thesis
/
zhongy
/
snmp
/
snmparse.c
< prev
next >
Wrap
C/C++ Source or Header
|
1994-05-11
|
2KB
|
105 lines
/*
This is snmp parse packet. It is used to parse the receiving character
string to a C structure. So we can access the C structure later
programmer: Zhong Yunxiang
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/time.h>
#include <sys/types.h>
#include "asn1.h"
#include "snmp.h"
/*
decode a packet
*/
void de_packet(struct req_desc *rqdq, unsigned char *buff_in,int len)
{
int len_interest; /*receive value start point*/
/* &&We must do many check here
*/
/* printf("\n in the de_packet function");
*/
len_interest=len-2; /*minus size of last two bytes*/
/*find type*/
rqdq->bind.sb_val.sv_type=(int)buff_in[len_interest];
/*get the len of value*/
rqdq->bind.sb_alslen=buff_in[len_interest+1];
/*get internal express of this value*/
rqdq->bind.sb_alstr=buff_in+len_interest+2;
}
/*
convert an ASN.1 encodeed integer into a machine integer
*/
int alreadint(unsigned char *pack,int len)
{
int i,tlen;
unsigned int result;
char neg;
/* printf("\n in the alreadint function:%d",sizeof(int));
*/
if ((tlen=len) > sizeof(int))
return(0);
result=0;
for (i=0;i<len;i++) {
result=(result << 8);
result=result | (int)pack[i];
}
return(result);
}
/*
alreadval-convert object in ASN.1 edcoded form to internal form
*/
void alreadval(struct req_desc *rqdq)
{
int type;
/* printf("\n in the alreadval function");
*/
type=rqdq->bind.sb_val.sv_type;
switch (type) {
case ASN1_INT:
case ASN1_COUNTER:
case ASN1_GAUGE:
case ASN1_TIMETICKS:
rqdq->bind.sb_val.sv_val.sv_int=alreadint(rqdq->bind.sb_alstr,rqdq->bind.sb_alslen);
break;
case ASN1_OCTSTR:
break;
case ASN1_NULL:
break;
case ASN1_OBJID:
break;
case ASN1_IPADDR:
break;
default:
break;
}
}