re-format
This commit is contained in:
		
							parent
							
								
									634ac82d1c
								
							
						
					
					
						commit
						94f842e473
					
				@ -47,7 +47,6 @@ static char copyright[] =
 | 
			
		||||
#include <stropts.h>
 | 
			
		||||
#include <unistd.h>
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * Local static values
 | 
			
		||||
 */
 | 
			
		||||
@ -60,7 +59,6 @@ static int Sd = -1;			/* stream device descriptor; not open
 | 
			
		||||
					 * if -1 */
 | 
			
		||||
static char ErrMsg[GET_MIB2_ERRMSGL];	/* error message buffer */
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
 * close_mib2() - close MIB2 access
 | 
			
		||||
 *
 | 
			
		||||
@ -72,10 +70,7 @@ static char ErrMsg[GET_MIB2_ERRMSGL];	/* error message buffer */
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
close_mib2(
 | 
			
		||||
	char **errmsg			/* error message buffer return
 | 
			
		||||
					 * address */
 | 
			
		||||
	)
 | 
			
		||||
close_mib2(char **errmsg)
 | 
			
		||||
{
 | 
			
		||||
    *errmsg = ErrMsg;
 | 
			
		||||
    if (Sd < 0) {
 | 
			
		||||
@ -115,14 +110,10 @@ close_mib2(
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
get_mib2(
 | 
			
		||||
	struct opthdr **opt,		/* opthdr struct pointer return
 | 
			
		||||
					 * address */
 | 
			
		||||
	char **data,			/* data buffer return address */
 | 
			
		||||
	int *datalen,			/* data length return address */
 | 
			
		||||
	char **errmsg			/* error message buffer return
 | 
			
		||||
					 * address */
 | 
			
		||||
	)
 | 
			
		||||
get_mib2(struct opthdr **opt,
 | 
			
		||||
         char **data,
 | 
			
		||||
         int *datalen,
 | 
			
		||||
         char **errmsg)
 | 
			
		||||
{
 | 
			
		||||
    static struct T_optmgmt_ack *a;	/* message ACK pointer */
 | 
			
		||||
    static struct strbuf c;		/* streams control buffer */
 | 
			
		||||
@ -135,7 +126,7 @@ get_mib2(
 | 
			
		||||
    int rc;				/* reply code */
 | 
			
		||||
 | 
			
		||||
    *errmsg = ErrMsg;
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * If MIB2 access isn't open, open it and issue the preliminary stream
 | 
			
		||||
     * messages.
 | 
			
		||||
     */
 | 
			
		||||
@ -144,8 +135,9 @@ get_mib2(
 | 
			
		||||
	/*
 | 
			
		||||
	 * Open access.  Return on error.
 | 
			
		||||
	 */
 | 
			
		||||
	    if ((err = open_mib2(errmsg)))
 | 
			
		||||
        if ((err = open_mib2(errmsg))) {
 | 
			
		||||
            return(err);
 | 
			
		||||
        }
 | 
			
		||||
	/*
 | 
			
		||||
	 * Set up message request and option.
 | 
			
		||||
	 */
 | 
			
		||||
@ -185,7 +177,7 @@ get_mib2(
 | 
			
		||||
        e = (struct T_error_ack *)Smb;
 | 
			
		||||
        o = (struct opthdr *)&Smb[sizeof(struct T_optmgmt_ack)];
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Get the next (first) reply message.
 | 
			
		||||
     */
 | 
			
		||||
    f = 0;
 | 
			
		||||
@ -194,57 +186,64 @@ get_mib2(
 | 
			
		||||
                       strerror(errno));
 | 
			
		||||
        return(GET_MIB2_ERR_GETMSGR);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Check for end of data.
 | 
			
		||||
     */
 | 
			
		||||
    if (rc == 0
 | 
			
		||||
	&&  c.len >= sizeof(struct T_optmgmt_ack)
 | 
			
		||||
	&&  a->PRIM_type == T_OPTMGMT_ACK
 | 
			
		||||
	&&  a->MGMT_flags == T_SUCCESS
 | 
			
		||||
	&&  o->len == 0) {
 | 
			
		||||
	&&  o->len == 0)
 | 
			
		||||
    {
 | 
			
		||||
        err = close_mib2(errmsg);
 | 
			
		||||
	    if (err)
 | 
			
		||||
        if (err) {
 | 
			
		||||
            return(err);
 | 
			
		||||
        }
 | 
			
		||||
        return(GET_MIB2_EOD);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Check for error.
 | 
			
		||||
     */
 | 
			
		||||
    if (c.len >= sizeof(struct T_error_ack)
 | 
			
		||||
	&&  e->PRIM_type == T_ERROR_ACK) {
 | 
			
		||||
	&&  e->PRIM_type == T_ERROR_ACK)
 | 
			
		||||
    {
 | 
			
		||||
        (void) sprintf(ErrMsg,
 | 
			
		||||
                       "get_mib2: T_ERROR_ACK: len=%d, TLI=%#x, UNIX=%#x",
 | 
			
		||||
                       c.len, (int)e->TLI_error, (int)e->UNIX_error);
 | 
			
		||||
        return(GET_MIB2_ERR_ACK);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Check for no data.
 | 
			
		||||
     */
 | 
			
		||||
    if (rc != MOREDATA
 | 
			
		||||
	||  c.len < sizeof(struct T_optmgmt_ack)
 | 
			
		||||
	||  a->PRIM_type != T_OPTMGMT_ACK
 | 
			
		||||
	||  a->MGMT_flags != T_SUCCESS) {
 | 
			
		||||
	||  a->MGMT_flags != T_SUCCESS)
 | 
			
		||||
    {
 | 
			
		||||
        (void) sprintf(ErrMsg,
 | 
			
		||||
		"get_mib2: T_OPTMGMT_ACK: rc=%d len=%d type=%#x flags=%#x",
 | 
			
		||||
                       "get_mib2: T_OPTMGMT_ACK: "
 | 
			
		||||
                       "rc=%d len=%d type=%#x flags=%#x",
 | 
			
		||||
                       rc, c.len, (int)a->PRIM_type, (int)a->MGMT_flags);
 | 
			
		||||
        return(GET_MIB2_ERR_NODATA);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Allocate (or enlarge) the data buffer.
 | 
			
		||||
     */
 | 
			
		||||
    if (o->len >= Dbl) {
 | 
			
		||||
        Dbl = o->len;
 | 
			
		||||
	    if (Db == NULL)
 | 
			
		||||
        if (Db == NULL) {
 | 
			
		||||
            Db = (char *)malloc(Dbl);
 | 
			
		||||
	    else
 | 
			
		||||
        }
 | 
			
		||||
        else {
 | 
			
		||||
            Db = (char *)realloc(Db, Dbl);
 | 
			
		||||
        }
 | 
			
		||||
        if (Db == NULL) {
 | 
			
		||||
            (void) sprintf(ErrMsg,
 | 
			
		||||
                           "get_mib2: no space for %d byte data buffer", Dbl);
 | 
			
		||||
            return(GET_MIB2_ERR_NOSPC);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Get the data part of the message -- the MIB2 part.
 | 
			
		||||
     */
 | 
			
		||||
    d.maxlen = o->len;
 | 
			
		||||
@ -262,7 +261,7 @@ get_mib2(
 | 
			
		||||
                       rc, d.maxlen, d.len, strerror(errno));
 | 
			
		||||
        return(GET_MIB2_ERR_GETMSGD);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Compose a successful return.
 | 
			
		||||
     */
 | 
			
		||||
    *opt = o;
 | 
			
		||||
@ -283,20 +282,17 @@ get_mib2(
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
int
 | 
			
		||||
open_mib2(
 | 
			
		||||
	char **errmsg			/* error message buffer return
 | 
			
		||||
					 * address */
 | 
			
		||||
	)
 | 
			
		||||
open_mib2(char **errmsg)
 | 
			
		||||
{
 | 
			
		||||
    *errmsg = ErrMsg;
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * It's an error if the stream device is already open.
 | 
			
		||||
     */
 | 
			
		||||
    if (Sd >= 0) {
 | 
			
		||||
        (void) strcpy(ErrMsg, "open_mib2: MIB2 access already open");
 | 
			
		||||
        return(GET_MIB2_ERR_OPEN);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Open the ARP stream device, push TCP and UDP on it.
 | 
			
		||||
     */
 | 
			
		||||
    if ((Sd = open(GET_MIB2_ARPDEV, O_RDWR, 0600)) < 0) {
 | 
			
		||||
@ -314,20 +310,22 @@ open_mib2(
 | 
			
		||||
                       GET_MIB2_UDPSTREAM, strerror(errno));
 | 
			
		||||
        return(GET_MIB2_ERR_UDPPUSH);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * Allocate a stream message buffer.
 | 
			
		||||
     */
 | 
			
		||||
    Smbl = sizeof(struct opthdr) + sizeof(struct T_optmgmt_req);
 | 
			
		||||
	if (Smbl < (sizeof (struct opthdr) + sizeof(struct T_optmgmt_ack)))
 | 
			
		||||
    if (Smbl < (sizeof (struct opthdr) + sizeof(struct T_optmgmt_ack))) {
 | 
			
		||||
        Smbl = sizeof (struct opthdr) + sizeof(struct T_optmgmt_ack);
 | 
			
		||||
	if (Smbl < sizeof(struct T_error_ack))
 | 
			
		||||
    }
 | 
			
		||||
    if (Smbl < sizeof(struct T_error_ack)) {
 | 
			
		||||
        Smbl = sizeof(struct T_error_ack);
 | 
			
		||||
    }
 | 
			
		||||
    if ((Smb = (char *)malloc(Smbl)) == NULL) {
 | 
			
		||||
        (void) strcpy(ErrMsg,
 | 
			
		||||
                      "open_mib2: no space for stream message buffer");
 | 
			
		||||
        return(GET_MIB2_ERR_NOSPC);
 | 
			
		||||
    }
 | 
			
		||||
/*
 | 
			
		||||
    /*
 | 
			
		||||
     * All is OK.  Return that indication.
 | 
			
		||||
     */
 | 
			
		||||
    return(GET_MIB2_OK);
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user