Juli Mallett wrote:
* De: Jens Rehsack <[EMAIL PROTECTED]> [ Data: 2003-03-01 ]
        [ Subjecte: Re: PATCH: type errors in src-tree ]

caddr_t is discouraged, with preference of writing an actual type.  caddr_t
is just an obfuscation.  I'm unclear what it gains in your context.

Okay, sorry for misusing caddr_t. Here's a patch without any caddr_t, but with 'char *' and 'const char *'.


Let me know what you're thinking about it.

Jens
--- sbin/atm/ilmid/ilmid.c.orig Wed Jan  1 18:48:45 2003
+++ sbin/atm/ilmid/ilmid.c      Sat Mar  1 23:31:29 2003
@@ -162,7 +162,7 @@
        union {
                int             ival;           /* INTEGER/TIMESTAMP */
                Objid           oval;           /* OBJID */
-               long            aval;           /* IPADDR */
+               uint32_t        aval;           /* IPADDR */
                char            sval[STRLEN];   /* OCTET */
        } var;
        Variable        *next;
@@ -173,10 +173,10 @@
  * which doesn't have the last three fields is the TRAP type.
  */
 struct snmp_header {
-       int             pdulen;
-       int             version;
+       uint32_t        pdulen;
+       uint32_t        version;
        char            community[64];
-       int             pdutype;
+       uint32_t        pdutype;
 
        /* GET/GETNEXT/GETRESP/SET */
        int             reqid;
@@ -185,11 +185,11 @@
 
        /* TRAP */
        Objid           enterprise;
-       int             ipaddr;
+       uint32_t        ipaddr;
        int             generic_trap;
        int             specific_trap;
 
-       int             varlen;
+       uint32_t        varlen;
        Variable        *head,
                        *tail;
 };
@@ -279,7 +279,7 @@
  * Temporary buffer for building response packets. Should help ensure
  * that we aren't accidently overwriting some other memory.
  */
-u_char Resp_Buf[1024];
+char   Resp_Buf[1024];
 
 /*
  * Copy the reponse into a buffer we can modify without
@@ -292,7 +292,7 @@
  * TRAP generic trap types
  */
 char   *Traps[] = { "coldStart", "warmStart", "linkDown", "linkUp",
-               "authenticationFailure", "egpNeighborLoss",
+                       "authenticationFailure", "egpNeighborLoss",
                        "enterpriseSpecific" };
 
 
@@ -320,6 +320,9 @@
  */
 Objid                  addressEntry[MAX_UNITS + 1];
 
+static const char      ilmi_ident_str[] = "ILMI";
+static const size_t    ilmi_ident_str_len = strlen("ILMI");
+
 /*
  * When this daemon started
  */
@@ -335,7 +338,7 @@
 #define        LOG_FILE        "/var/log/ilmid"
 FILE   *Log;                   /* File descriptor for log messages */
 
-void   set_reqid( u_char *, int );
+void   set_reqid( char *, uint32_t );
 void   Increment_DL( int );
 void   Decrement_DL( int );
 
@@ -376,7 +379,7 @@
 
 /*
  * Utility to pretty print buffer as hex dumps
- * 
+ *
  * Arguments:
  *     bp      - buffer pointer
  *     len     - length to pretty print
@@ -387,10 +390,10 @@
  */
 void
 hexdump ( bp, len )
-       u_char  *bp;
-       int     len;
+       const char      *bp;
+       const uint32_t  len;
 {
-       int     i, j;
+       uint32_t        i, j;
 
        /*
         * Print as 4 groups of four bytes. Each byte is separated
@@ -443,7 +446,7 @@
  *     bufp    - pointer to buffer pointer
  *     plen    - pointer to PDU length or NULL if not a concern
  *
- * Returns: 
+ * Returns:
  *     bufp    - updated buffer pointer
  *     plen    - (possibly) adjusted pdu length
  *     <len>   - decoded length
@@ -451,21 +454,21 @@
  */
 int
 asn_get_pdu_len ( bufp, plen )
-       u_char  **bufp;
-       int     *plen;
+       const char      ** const bufp;
+       uint32_t        * const plen;
 {
-       u_char  *bp = *bufp;
-       int     len = 0;
-       int     i, b;
+       const char *bp =        *bufp;
+       uint32_t        len = 0;
+       uint32_t        i, b;
 
        b = *bp++;
        if ( plen )
-               (*plen)--;
-        if ( b & 0x80 ) {
-               for ( i = 0; i < (b & ~0x80); i++ ) {
+               --(*plen);
+       if ( b & 0x80 ) {
+               for ( i = 0; i < (b & ~0x80); ++i ) {
                        len = len * 256 + *bp++;
                        if ( plen )
-                               (*plen)--;
+                               --(*plen);
                }
        } else
                len = b;
@@ -492,12 +495,12 @@
  */
 int
 asn_get_encoded ( bufp, len )
-       u_char  **bufp;
-       int     *len;
+       const char      ** const bufp;
+       uint32_t        * const len;
 {
-       u_char  *bp = *bufp;
-       int     val = 0;
-       int     l = *len;
+       const char      *bp = *bufp;
+       int             val = 0; /* FIXME: signed? sure? */
+       uint32_t        l = *len;
 
        /*
         * Keep going while high bit is set
@@ -507,7 +510,7 @@
                 * Each byte can represent 7 bits
                 */
                val = ( val << 7 ) + ( *bp & ~0x80 );
-               l--;
+               --l;
        } while ( *bp++ & 0x80 );
 
        *bufp = bp;             /* update buffer pointer */
@@ -526,28 +529,28 @@
  *     plen    - pointer to PDU length or NULL if not a concern
  *
  * Returns:
- *     bufp    - updated buffer pointer 
+ *     bufp    - updated buffer pointer
  *     plen    - (possibly) updated PDU length
  *     <val>   - value of encoded integer
  *
  */
 int
 asn_get_int ( bufp, plen )
-       u_char  **bufp;
-       int     *plen;
+       const char      ** const bufp;
+       uint32_t        * const plen;
 {
-       int     i;
-       int     len;
-       int     v = 0;
-       u_char  *bp = *bufp;
+       uint32_t        i;
+       uint32_t        len;
+       int             v = 0;
+       const char      *bp = *bufp;
 
        len = *bp++;
        if ( plen )
-               (*plen)--;
-       for ( i = 0; i < len; i++ ) {
+               --(*plen);
+       for ( i = 0; i < len; ++i ) {
                v = (v * 256) + *bp++;
                if ( plen )
-                       (*plen)--;
+                       --(*plen);
        }
        *bufp = bp;
        return ( v );
@@ -567,16 +570,16 @@
  */
 void
 asn_set_int ( bufp, val )
-       u_char  **bufp;
-       int     val;
+       char            **bufp;
+       uint32_t        val;
 {
        union {
-               int     i;
-               u_char  c[4];
+               uint32_t        i;
+               u_char  c[sizeof(uint32_t)];
        } u;
-       int     len = sizeof(int);
-       int     i = 0;
-       u_char  *bp = *bufp;
+       uint32_t        len = sizeof(uint32_t);
+       uint32_t        i = 0;
+       char *bp = *bufp;
 
        /* Check for special case where val == 0 */
        if ( val == 0 ) {
@@ -588,16 +591,16 @@
 
        u.i = htonl ( val );
 
-       while ( u.c[i] == 0  && i++ < sizeof(int) )
-               len--;
+       while ( u.c[i] == 0 && ++i < sizeof(u.i) ) /* 'i++ < x' increases x even if 
increase break bounds */
+               --len;
 
        if ( u.c[i] > 0x7f ) {
-               i--;
-               len++;
+               --i;
+               ++len;
        }
 
-       *bp++ = len;
-       bcopy ( (caddr_t)&u.c[sizeof(int)-len], bp, len );
+       *bp++ = (char)len;
+       bcopy ( &u.c[sizeof(u.i)-len], bp, len );
        bp += len;
        *bufp = bp;
 
@@ -616,9 +619,9 @@
  */
 void
 print_objid ( objid )
-       Objid   *objid;
+       const Objid     *objid;
 {
-       int     i;
+       uint32_t        i, cmp = objid->oid[0];
 
        /*
         * First oid coded as 40 * X + Y
@@ -628,7 +631,7 @@
            fprintf ( Log, ".%d.%d", objid->oid[1] / 40,
                objid->oid[1] % 40 );
        }
-       for ( i = 2; i <= objid->oid[0]; i++ )
+       for ( i = 2; i <= cmp; ++i )
            if ( Log )
                fprintf ( Log, ".%d", objid->oid[i] );
        if ( Log )
@@ -653,23 +656,23 @@
  */
 void
 asn_get_objid ( bufp, objid, plen )
-       u_char  **bufp;
-       Objid   *objid;
-       int     *plen;
-{
-       int     len;
-       u_char  *bp = *bufp;
-       int     *ip = (int *)objid + 1; /* First byte will contain length */
-       int     oidlen = 0;
+       const char      **bufp;
+       Objid           * const objid;
+       uint32_t        * const plen;
+{
+       uint32_t        len;
+       const char      *bp = *bufp;
+       int             *ip = (int *)objid + 1; /* First byte will contain length */ 
/* FIXME: first byte or first word? */
+       uint32_t        oidlen = 0;
 
        len = *bp++;
        if ( plen )
-               (*plen)--;
+               --(*plen);
        while ( len ) {
                *ip++ = asn_get_encoded ( &bp, &len );
                if ( plen )
-                       (*plen)--;
-               oidlen++;
+                       --(*plen);
+               ++oidlen;
        }
        objid->oid[0] = oidlen;
        *bufp = bp;
@@ -683,28 +686,29 @@
  */
 int
 asn_put_objid ( bufp, objid )
-       u_char  **bufp;
-       Objid   *objid;
+       char            **bufp;
+       const Objid     * const objid;
 {
-       int     len = 0;
-       u_char  *bp = *bufp;
-       u_char  *cpp;
-       int     i;
+       uint32_t        len = 0;
+       char            *bp = *bufp;
+       char            *cpp;
+       uint32_t        i;
+       const uint32_t  oidlen = objid->oid[0];
 
        cpp = bp;
        *bp++ = objid->oid[0];
-       len++;
-       for ( i = 1; i <= objid->oid[0]; i++ ) {
-               u_int   c = objid->oid[i];
+       ++len;
+       for ( i = 1; i <= oidlen; ++i ) { /* FIXME: objid->oid[0] can be greater than 
128 which is sizeof(objid->oid) */
+               unsigned char   c = objid->oid[i];
 
                while ( c > 127 ) {
                        *bp++ = ( ( c >> 7 ) & 0x7f ) | 0x80;
-                       len++;
+                       ++len;
                        c &= 0x7f;              /* XXX - assumption of two bytes */
-                       (*cpp)++;
+                       ++(*cpp);
                }
                *bp++ = c;
-               len++;
+               ++len;
        }
 
        *bufp = bp;
@@ -728,27 +732,27 @@
  *     octet   - encoded Octet String
  *     plen    - (possibly) adjusted PDU length
  *
- */ 
+ */
 void
 asn_get_octet ( bufp, octet, plen )
-       u_char  **bufp;
-       char    *octet;
-       int     *plen;
-{
-       u_char  *bp = *bufp;
-       int     i = 0;
-       int     len = 0;
+       const char      ** const bufp;
+       char            *octet;
+       uint32_t        * const plen;
+{
+       const char      *bp = *bufp;
+       uint32_t        i = 0;
+       uint32_t        len = 0;
 
        /*
         * &i is really a dummy value here as we don't keep track
         * of the ongoing buffer length
         */
-       len = asn_get_encoded ( &bp, &i, plen );
+       len = (uint32_t)asn_get_encoded ( &bp, &i, plen );
 
-       for ( i = 0; i < len; i++ ) {
+       for ( i = 0; i < len; ++i ) {
                *octet++ = *bp++;
                if ( plen )
-                       (*plen)--;
+                       --(*plen);
        }
 
        *bufp = bp;
@@ -769,7 +773,7 @@
  */
 void
 print_header ( Hdr )
-       Snmp_Header *Hdr;
+       const Snmp_Header       * const Hdr;
 {
        Variable        *var;
 
@@ -829,24 +833,24 @@
 void
 parse_oids ( h, bp )
        Snmp_Header     *h;
-       caddr_t         *bp;
+       const char      **bp;
 {
-       int             len = h->varlen;
-       int             sublen;
+       uint32_t        len = h->varlen;
+       uint32_t        sublen;
        Variable        *var;
-       caddr_t         bufp = *bp;
+       const char      *bufp = *bp;
 
        while ( len > 0 ) {
            if ( *bufp++ == ASN_SEQUENCE ) {
-               len--;
+               --len;
 
                /* Create new Variable instance */
-               if ( ( var = (Variable *)malloc(sizeof(Variable)) ) == NULL )
+               if ( ( var = malloc(sizeof(*var)) ) == NULL )
                {
                        *bp = bufp;
                        return;
                }
-               bzero(var, sizeof(Variable));
+               bzero(var, sizeof(*var));
                /* Link to tail */
                if ( h->tail )
                        h->tail->next = var;
@@ -872,8 +876,8 @@
                        var->var.ival = asn_get_int ( &bufp, &len );
                        break;
                case ASN_NULL:
-                       bufp++;
-                       len--;
+                       ++bufp;
+                       --len;
                        break;
                case ASN_OBJID:
                        asn_get_objid ( &bufp, &var->var.oval, &len );
@@ -915,23 +919,25 @@
  */
 Snmp_Header *
 asn_get_header ( bufp )
-       u_char **bufp;
+       const char      **bufp;
 {
        Snmp_Header     *h;
-       u_char          *bp = *bufp;
-       int             len = 0;
-       int             dummy = 0;
+       const char      *bp = *bufp;
+       uint32_t        len = 0;
+       /*
+       uint32_t        dummy = 0;
+       */
 
        /*
         * Allocate memory to hold the SNMP header
         */
-       if ( ( h = (Snmp_Header *)malloc(sizeof(Snmp_Header)) ) == NULL )
+       if ( ( h = malloc(sizeof(*h)) ) == NULL ) /* void * matches any pointer type */
                return ( (Snmp_Header *)NULL );
 
        /*
         * Ensure that we wipe the slate clean
         */
-       bzero(h, sizeof(Snmp_Header));
+       bzero(h, sizeof(*h));
 
        /*
         * PDU has to start as SEQUENCE OF
@@ -970,7 +976,7 @@
         */
        if ( h->pdutype != PDU_TYPE_TRAP ) {    /* TRAP uses different format */
 
-               (void) asn_get_pdu_len ( &bp, &dummy );
+               (void) asn_get_pdu_len ( &bp, NULL ); /* &dummy -> NULL */
 
                /* Request ID */
                if ( *bp++ != ASN_INTEGER ) {
@@ -1027,15 +1033,15 @@
  */
 int
 oid_cmp ( oid1, oid2 )
-       Objid *oid1, *oid2;
+       const Objid     * const oid1, * const oid2;
 {
-       int     i;
-       int     len;
+       uint32_t        i;
+       uint32_t        len;
 
        /*
         * Compare lengths
         */
-       if ( !(oid1->oid[0] == oid2->oid[0] ) )
+       if ( !(oid1->oid[0] == oid2->oid[0] ) ) /* FIXME: how about if( oid1->oid[0] 
!= oid2->oid[0] ) */
                /* Different lengths */
                return ( 1 );
 
@@ -1069,10 +1075,10 @@
  */
 int
 oid_ncmp ( oid1, oid2, len )
-       Objid *oid1, *oid2;
-       int     len;
+       const Objid     * const oid1, * const oid2;
+       const uint32_t  len;
 {
-       int     i;
+       uint32_t        i;
 
        /*
         * value by value compare
@@ -1100,9 +1106,9 @@
  */
 int
 find_var ( var )
-       Variable        *var;
+       const Variable  * const var;
 {
-       int     i;
+       int             i;
 
        for ( i = 0; i < NUM_OIDS; i++ )
                if ( oid_cmp ( &var->oid, &Objids[i] ) == 0 ) {
@@ -1114,7 +1120,7 @@
 }
 
 /*
- * Return the time process has been running as a number of ticks 
+ * Return the time process has been running as a number of ticks
  *
  * Arguments:
  *     none
@@ -1169,17 +1175,17 @@
  */
 void
 build_pdu ( hdr, type )
-       Snmp_Header     *hdr;
-       int             type;
+       Snmp_Header *   const hdr;
+       const int       type;
 {
-       u_char          *bp = Resp_Buf;
-       u_char          *vpp;
-       u_char          *ppp;
+       char            *bp = Resp_Buf;
+       char            *vpp;
+       char            *ppp;
        int             erridx = 0;
        int             varidx = 1;
-       int             varlen = 0;
-       int             pdulen = 0;
-       int             traplen = 0;
+       uint32_t        varlen = 0;
+       uint32_t        pdulen = 0;
+       uint32_t        traplen = 0;
        Variable        *var;
 
        /*
@@ -1188,14 +1194,14 @@
        bzero ( Resp_Buf, sizeof(Resp_Buf) );
 
        /* [0] is reserved for overall length */
-       bp++;
+       ++bp;
 
        /* Start with SEQUENCE OF */
        *bp++ = ASN_SEQUENCE;
        /* - assume we can code length in two octets */
        *bp++ = 0x82;
-       bp++;
-       bp++;
+       ++bp;
+       ++bp;
        /* Version */
        *bp++ = ASN_INTEGER;
        asn_set_int ( &bp, hdr->version );
@@ -1208,7 +1214,7 @@
        *bp++ = type;
        ppp = bp;
        /* Length of OID data - assume it'll fit in one octet */
-       bp++;
+       ++bp;
 
        if ( type != PDU_TYPE_TRAP ) {
            /* Sequence ID */
@@ -1250,7 +1256,7 @@
                /* Fill in IP address */
                *bp++ = ASN_IPADDR;
                *bp++ = sizeof ( hdr->ipaddr );
-               bcopy ( (caddr_t)&hdr->ipaddr, bp, sizeof(hdr->ipaddr) );
+               bcopy ( &hdr->ipaddr, bp, sizeof(hdr->ipaddr) );
                bp += sizeof(hdr->ipaddr);
 
                /* Fill in generic and specific trap types */
@@ -1262,7 +1268,7 @@
                /* Fill in time-stamp  - assume 0 for now */
                *bp++ = ASN_TIMESTAMP;
                asn_set_int ( &bp, 0 );
-               
+
                /* encoded length */
                traplen = ( bp - ppp - 1 );
 
@@ -1275,40 +1281,40 @@
        /* - assume we can code length in two octets */
        vpp = bp;
        varlen = 0;
-       bp++;
-       bp++;
+       ++bp;
+       ++bp;
 
        /* Install Variables */
        var = hdr->head;
        varidx = 1;
        while ( var ) {
-               u_char *bpp;
-               int     len = 0;
+               char            *bpp;
+               uint32_t        len = 0;
 
                /* SEQUENCE OF */
                *bp++ = ASN_SEQUENCE;
                *bp++ = 0x82;
                /* - assume we can code length in two octets */
                bpp = bp;
-               bp++;
-               bp++;
+               ++bp;
+               ++bp;
                /* OBJID */
                *bp++ = ASN_OBJID;
-               len++;
+               ++len;
 
                len += asn_put_objid ( &bp, &var->oid );
 
                if ( erridx && varidx >= erridx ) {
                        /* Code this variable as NULL */
                        *bp++ = ASN_NULL;
-                       len++;
-                       bp++;
-                       len++;
+                       ++len;
+                       ++bp;
+                       ++len;
                } else {
-                       u_char *lpp;
+                       char    *lpp;
                        /* Variable type */
                        *bp++ = var->type;
-                       len++;
+                       ++len;
                        lpp = bp;
                        switch ( var->type ) {
                        case ASN_INTEGER:
@@ -1317,15 +1323,15 @@
                                break;
                        case ASN_OCTET:
                                *bp++ = var->var.sval[0];
-                               len++;
-                               bcopy ( (caddr_t)&var->var.sval[1],
+                               ++len;
+                               bcopy ( &var->var.sval[1],
                                        bp, var->var.sval[0] );
                                len += var->var.sval[0];
                                bp += var->var.sval[0];
                                break;
                        case ASN_NULL:
                                *bp++ = 0x00;
-                               len++;
+                               ++len;
                                break;
                        case ASN_OBJID:
                                len += asn_put_objid ( &bp, &var->var.oval );
@@ -1333,11 +1339,11 @@
                        case ASN_SEQUENCE:
                                break;
                        case ASN_IPADDR:
-                               *bp++ = 4;
-                               len++;
-                               bcopy ( (caddr_t)&var->var.aval, bp, 4 );
-                               len += 4;
-                               bp += 4;
+                               *bp++ = sizeof(var->var.aval);
+                               ++len;
+                               bcopy ( &var->var.aval, bp, sizeof(var->var.aval) );
+                               len += sizeof(var->var.aval);
+                               bp += sizeof(var->var.aval);
                                break;
                        case ASN_TIMESTAMP:
                                asn_set_int ( &bp, var->var.ival );
@@ -1349,7 +1355,7 @@
                }
 
                /* Accumulate total Variable sequence length */
-               varlen += (len + 4);
+               varlen += (len + 4); /* FIXME: why 4? is it sizeof(var->var.aval) */
 
                /* Fill in length of this sequence */
                bpp[1] = len & 0xff;
@@ -1413,27 +1419,27 @@
  */
 void
 set_reqid ( resp, reqid )
-       u_char  *resp;
-       int     reqid;
+       char            *resp;
+       uint32_t        reqid;
 {
-       u_char          *bp = (u_char *)&resp[18];
+       char    *bp = resp+18;
        union {
-               int     i;
-               u_char  c[4];
-       } u;    
+               uint32_t        i;
+               char            c[sizeof(uint32_t)];
+       } u;
 
-       u.i = htonl(reqid);
+       u.i = htonl( reqid );
 
        /*
         * Replace the current Request ID with the supplied value
         */
-       bcopy ( (caddr_t)&u.c[4-resp[17]], bp, resp[17] );
+       bcopy ( &u.c[4-resp[17]], bp, resp[17] );
 
        return;
 }
 
 /*
- * Send a generic response packet
+ * Send a generic response packet - FIXME: documentation doesn't match declaration
  *
  * Arguments:
  *     sd      - socket to send the reply on
@@ -1446,20 +1452,20 @@
  */
 void
 send_resp ( intf, Hdr, resp )
-       int             intf;
-       Snmp_Header     *Hdr;
-       u_char          *resp;
+       int                     intf;
+       Snmp_Header             *Hdr;
+       char                    *resp;
 {
        int     n;
 
-       if ( ilmi_fd[intf] > 0 ) {
-           n = write ( ilmi_fd[intf], (caddr_t)&resp[1], resp[0] );
+       if ( ilmi_fd[intf] > 0 ) { /* FIXME: does ilmi_fd[intf] exists? out of range? 
*/
+           n = write ( ilmi_fd[intf], resp+1, resp[0] );
            if ( Log && Debug_Level > 1 ) {
                write_timestamp();
                fprintf ( Log, "===== Sent %d of %d bytes (%d) =====\n", n, resp[0], 
ilmi_fd[intf] );
                print_header ( Hdr );
                if ( Debug_Level > 2 )
-                       hexdump ( (u_char *)&resp[1], resp[0] );
+                       hexdump ( &resp[1], resp[0] );
            }
        }
 
@@ -1477,33 +1483,34 @@
        Snmp_Header     *hdr;
        Variable        *var;
 
-       hdr = (Snmp_Header *)malloc(sizeof(Snmp_Header));
+       hdr = malloc(sizeof(*hdr));
        if (hdr == NULL) {
-               fprintf(stderr, "malloc() failed in %s()\n", __func__);
+               fprintf(stderr, "malloc() failed in %s() line %d\n", __func__, 
__LINE__);
                exit(1);
        }
-       bzero(hdr, sizeof(Snmp_Header));
+       bzero(hdr, sizeof(*hdr));
 
+       /* FIXME: bzero has done that
        hdr->pdulen = 0;
+       */
        hdr->version = SNMP_VERSION_1 - 1;
-       snprintf ( hdr->community, sizeof(hdr->community), "ILMI" );
+       snprintf ( hdr->community, ilmi_ident_str_len, ilmi_ident_str );
 
-       hdr->ipaddr = 0x0;      /* 0.0.0.0 */
+       /* FIXME: bzero: hdr->ipaddr = 0x0;     */ /* 0.0.0.0 */
        hdr->generic_trap = TRAP_COLDSTART;
-       hdr->specific_trap = 0;
-       bcopy ( (caddr_t)&Objids[ENTERPRISE_OBJID], (caddr_t)&hdr->enterprise,
+       /* FIXME: bzero: hdr->specific_trap = 0; */
+       bcopy ( &Objids[ENTERPRISE_OBJID], &hdr->enterprise,
                sizeof(Objid) );
 
-       hdr->head = (Variable *)malloc(sizeof(Variable));
-       if (hdr == NULL) {
-               fprintf(stderr, "malloc() failed in %s()\n", __func__);
+       hdr->head = malloc(sizeof(*hdr->head));
+       if (hdr->head == NULL) {
+               fprintf(stderr, "malloc() failed in %s() line %d\n", __func__, 
__LINE__);
                exit(1);
        }
-       bzero(hdr->head, sizeof(Variable));
+       bzero(hdr->head, sizeof(*hdr->head));
 
        var = hdr->head;
-       bcopy ( (caddr_t)&Objids[UPTIME_OBJID], (caddr_t)&var->oid,
-               sizeof(Objid) );
+       bcopy ( &Objids[UPTIME_OBJID], &var->oid, sizeof(var->oid) );
        var->type = ASN_NULL;
 
        return ( hdr );
@@ -1518,40 +1525,40 @@
 {
        Snmp_Header     *hdr;
 
-       hdr = (Snmp_Header *)malloc(sizeof(Snmp_Header));
+       hdr = malloc(sizeof(*hdr));
        if (hdr == NULL) {
                fprintf(stderr, "malloc() failed in %s()\n", __func__);
                exit(1);
        }
-       bzero(hdr, sizeof(Snmp_Header));
+       bzero(hdr, sizeof(*hdr));
 
-       hdr->pdulen = 0;
+       /* FIXME: bzero: hdr->pdulen = 0; */
        hdr->version = SNMP_VERSION_1 - 1;
-       snprintf ( hdr->community, sizeof(hdr->community), "ILMI" );
+       snprintf ( hdr->community, ilmi_ident_str_len, ilmi_ident_str );
 
        return ( hdr );
 }
 
-/* 
+/*
  * Initialize information on what physical adapters HARP knows about
  *
  * Query the HARP subsystem about configuration and physical interface
  * information for any currently registered ATM adapters. Store the information
  * as arrays for easier indexing by SNMP port/index numbers.
- *      
+ *
  * Arguments:
  *      none
  *
  * Returns:
- *      none            Information from HARP available 
- *      
+ *      none            Information from HARP available
+ *
  */
-void    
-init_ilmi()  
+void
+init_ilmi()
 {
-        struct  air_cfg_rsp     *cfg_info = NULL;
-        struct  air_int_rsp    *intf_info = NULL;
-        int                     buf_len;
+        struct  air_cfg_rsp    *cfg_info = NULL;
+        struct  air_int_rsp    *intf_info = NULL;
+        int                    buf_len;
 
        /*
         * Get configuration info - what's available with 'atm sh config'
@@ -1562,7 +1569,7 @@
         */
        if ( buf_len <= 0 ) {
                bzero ( Cfg, sizeof(Cfg) );
-               bzero( Intf, sizeof(Intf) );
+               bzero ( Intf, sizeof(Intf) );
                NUnits = 0;
                return;
        }
@@ -1570,11 +1577,11 @@
        /*
         * Move to local storage
         */
-        bcopy ( cfg_info, (caddr_t)Cfg, buf_len );
+        bcopy ( cfg_info, Cfg, buf_len );
        /*
         * Compute how many units information was returned for
         */
-        NUnits = buf_len / sizeof(struct air_cfg_rsp);
+        NUnits = buf_len / sizeof(*cfg_info);
        /* Housecleaning */
         free ( cfg_info );
         cfg_info = NULL;
@@ -1593,7 +1600,7 @@
        /*
         * Move to local storage
         */
-        bcopy ( intf_info, (caddr_t)Intf, buf_len );
+        bcopy ( intf_info, Intf, buf_len );
        /* Housecleaning */
         free ( intf_info );
         intf_info = NULL;
@@ -1620,28 +1627,28 @@
 void
 ilmi_open ()
 {
-        struct sockaddr_atm     satm;
-        struct t_atm_aal5       aal5;
-        struct t_atm_traffic    traffic;
-        struct t_atm_bearer     bearer;
-        struct t_atm_qos        qos;
+        struct sockaddr_atm    satm;
+        struct t_atm_aal5      aal5;
+        struct t_atm_traffic   traffic;
+        struct t_atm_bearer    bearer;
+        struct t_atm_qos       qos;
        struct t_atm_app_name   appname;
-        Atm_addr                subaddr;
-        char                    nifname[IFNAMSIZ];
-        int                     optlen;
-        int                     unit = 0;
+        Atm_addr               subaddr;
+        char                   nifname[IFNAMSIZ];
+        socklen_t              optlen;
+        int                    unit = 0;
        u_char                  sig_proto;
 
         init_ilmi();
 
-       for ( unit = 0; unit < NUnits; unit++ ) {
+       for ( unit = 0; unit < NUnits; ++unit ) {
 
            /*
             * ILMI only makes sense for UNI signalling protocols
             */
            sig_proto = Intf[unit].anp_sig_proto;
            if ( sig_proto != ATM_SIG_UNI30 && sig_proto != ATM_SIG_UNI31 &&
-               sig_proto != ATM_SIG_UNI40 )
+                sig_proto != ATM_SIG_UNI40 )
                    continue;
 
                    if ( ilmi_fd[unit] == -1 ) {
@@ -1668,7 +1675,7 @@
                 sprintf ( nifname, "%s0", Intf[unit].anp_nif_pref );
                 optlen = sizeof ( nifname );
                 if ( setsockopt ( ilmi_fd[unit], T_ATM_SIGNALING,
-                   T_ATM_NET_INTF, (caddr_t)nifname, optlen ) < 0 ) {
+                   T_ATM_NET_INTF, (char *)nifname, optlen ) < 0 ) {
                                perror ( "setsockopt" );
                        if ( Log ) {
                            write_timestamp();
@@ -1688,7 +1695,7 @@
                 /*
                  * Set up destination SAP
                  */
-                bzero ( (caddr_t) &satm, sizeof(satm) );
+                bzero ( &satm, sizeof(satm) );
                 satm.satm_family = AF_ATM;
 #if (defined(BSD) && (BSD >= 199103))
                 satm.satm_len = sizeof(satm);
@@ -1702,7 +1709,7 @@
                     0 );
                 ATM_PVC_SET_VCI((Atm_addr_pvc *)satm.satm_addr.t_atm_sap_addr.address,
                     16 );
-    
+
                 satm.satm_addr.t_atm_sap_layer2.SVE_tag = T_ATM_PRESENT;
                 satm.satm_addr.t_atm_sap_layer2.ID_type = T_ATM_SIMPLE_ID;
                 satm.satm_addr.t_atm_sap_layer2.ID.simple_ID = T_ATM_BLLI2_I8802;
@@ -1719,7 +1726,7 @@
                 aal5.SSCS_type = T_ATM_NULL;
                 optlen = sizeof(aal5);
                 if ( setsockopt ( ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_AAL5,
-                (caddr_t) &aal5, optlen ) < 0 ) {
+                (char *) &aal5, optlen ) < 0 ) {
                     perror ( "setsockopt(aal5)" );
                    if ( Debug_Level > 1 && Log ) {
                        write_timestamp();
@@ -1747,7 +1754,7 @@
                 traffic.best_effort = T_YES;
                 optlen = sizeof(traffic);
                 if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_TRAFFIC,
-                        (caddr_t)&traffic, optlen) < 0) {
+                        &traffic, optlen) < 0) {
                     perror("setsockopt(traffic)");
                 }
                 bearer.bearer_class = T_ATM_CLASS_X;
@@ -1757,7 +1764,7 @@
                 bearer.connection_configuration = T_ATM_1_TO_1;
                 optlen = sizeof(bearer);
                 if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_BEARER_CAP,
-                        (caddr_t)&bearer, optlen) < 0) {
+                        &bearer, optlen) < 0) {
                     perror("setsockopt(bearer)");
                 }
 
@@ -1765,7 +1772,7 @@
                 qos.forward.qos_class = T_ATM_QOS_CLASS_0;
                 qos.backward.qos_class = T_ATM_QOS_CLASS_0;
                 optlen = sizeof(qos);
-                if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_QOS, 
(caddr_t)&qos,
+                if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_QOS, &qos,
                         optlen) < 0) {
                     perror("setsockopt(qos)");
                 }
@@ -1774,14 +1781,14 @@
                 subaddr.address_length = 0;
                 optlen = sizeof(subaddr);
                 if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_DEST_SUB,
-                        (caddr_t)&subaddr, optlen) < 0) {
+                        &subaddr, optlen) < 0) {
                     perror("setsockopt(dest_sub)");
                 }
 
                strncpy(appname.app_name, "ILMI", T_ATM_APP_NAME_LEN);
                optlen = sizeof(appname);
                if (setsockopt(ilmi_fd[unit], T_ATM_SIGNALING, T_ATM_APP_NAME,
-                       (caddr_t)&appname, optlen) < 0) {
+                       &appname, optlen) < 0) {
                    perror("setsockopt(appname)");
                }
 
@@ -1828,11 +1835,11 @@
  */
 void
 get_local_ip ( s, aval )
-       int     s;
-       long    *aval;
+       int             s;
+       uint32_t        *aval;
 {
        char                    intf_name[IFNAMSIZ];
-       int                     namelen = IFNAMSIZ;
+       socklen_t               namelen = IFNAMSIZ;
        struct air_netif_rsp    *net_info = NULL;
        struct sockaddr_in      *sin;
 
@@ -1840,7 +1847,7 @@
         * Get physical interface name
         */
        if ( getsockopt ( s, T_ATM_SIGNALING, T_ATM_NET_INTF,
-           (caddr_t) intf_name, &namelen ) )
+                         intf_name, &namelen ) )
                return;
 
        /*
@@ -1855,7 +1862,7 @@
        /*
         * Fill in answer
         */
-       bcopy ( (caddr_t)&sin->sin_addr.s_addr, aval, 4 );
+       bcopy ( &sin->sin_addr.s_addr, aval, sizeof(*aval) );
 
        free ( net_info );
 
@@ -1872,7 +1879,7 @@
  *
  * Arguments:
  *     oid     - objid from SET message
- *     hdr     - pointer to internal SNMP header
+ *     hdr     - pointer to internal SNMP header - unused
  *     buf     - pointer to SET buffer
  *     s       - socket to send messages on
  *
@@ -1882,9 +1889,9 @@
  */
 void
 set_prefix ( oid, hdr, intf )
-       Objid           *oid;
-       Snmp_Header     *hdr;
-       int             intf;
+       const Objid             * const oid;
+       const Snmp_Header       * const hdr;
+       const int               intf;
 {
        struct atmsetreq        asr;
        Atm_addr                *aa;
@@ -1901,7 +1908,7 @@
         * Pull prefix out of received Objid
         *      save in set_prefix IOCTL and addressEntry table
         */
-       for ( i = 0; i < oid->oid[13]; i++ ) {
+       for ( i = 0; i < oid->oid[13]; ++i ) {
                asr.asr_prf_pref[i] = oid->oid[i + 14];
        }
 
@@ -1909,9 +1916,9 @@
         * Pass new prefix to the HARP kernel
         */
        fd = socket ( AF_ATM, SOCK_DGRAM, 0 );
-       if ( fd < 0 ) 
+       if ( fd < 0 )
                return;
-       if ( ioctl ( fd, AIOCSET, (caddr_t)&asr ) < 0 ) {
+       if ( ioctl ( fd, AIOCSET, (char *)&asr ) < 0 ) {
                if ( errno != EALREADY ) {
                    syslog ( LOG_ERR, "ilmid: error setting prefix: %m" );
                    if ( Log ) {
@@ -1949,25 +1956,25 @@
 
 void
 set_address ( hdr, intf )
-       Snmp_Header     *hdr;
-       int             intf;
+       const Snmp_Header       * const hdr; /* FIXME: unused? */
+       const int               intf;
 {
        Variable        *var;
        int             i, j;
 
        PDU_Header = build_generic_header();
 
-       PDU_Header->head = (Variable *)malloc(sizeof(Variable));
+       PDU_Header->head = malloc(sizeof(*PDU_Header->head));
        if (PDU_Header->head == NULL) {
-               fprintf(stderr, "malloc() failed in %s()\n", __func__);
+               fprintf(stderr, "malloc() failed in %s() line %d\n", __func__, 
__LINE__);
                exit(1);
        }
-       bzero(PDU_Header->head, sizeof(Variable));
+       bzero(PDU_Header->head, sizeof(*PDU_Header->head));
 
        var = PDU_Header->head;
        /* Copy generic addressEntry OBJID */
-       bcopy ( (caddr_t)&Objids[ADDRESS_OBJID], (caddr_t)&var->oid,
-               sizeof(Objid) );
+       bcopy ( &Objids[ADDRESS_OBJID], &var->oid,
+               sizeof(var->oid) );
        /* Set specific instance */
        i = var->oid.oid[0] + 1;                /* Get length */
        var->oid.oid[i++] = 1;
@@ -1991,26 +1998,26 @@
        send_resp ( intf, PDU_Header, Resp_Buf );
 }
 
-/* 
+/*
  * Utility to strip off any leading path information from a filename
- *      
+ *
  * Arguments:
  *      path            pathname to strip
- *      
+ *
  * Returns:
  *      fname           striped filename
- * 
- */     
+ *
+ */
 char *
 basename ( path )
-        char *path;
-{  
+        const char     *path;
+{
         char *fname;
 
-        if ( ( fname = (char *)strrchr ( path, '/' ) ) != NULL )
+        if ( ( fname = strrchr ( path, '/' ) ) != NULL )
                 fname++;
         else
-                fname = path;
+                fname = (char *)path;
 
         return ( fname );
 }
@@ -2036,7 +2043,7 @@
            if ( foregnd ) {
                Log = stderr;
            } else {
-               if ( ( Log = fopen ( LOG_FILE, "a" ) ) == NULL ) 
+               if ( ( Log = fopen ( LOG_FILE, "a" ) ) == NULL )
                    Log = NULL;
            }
            if ( Log ) {
@@ -2086,8 +2093,8 @@
  */
 void
 process_get ( hdr, intf )
-       Snmp_Header     *hdr;
-       int             intf;
+       Snmp_Header     * const hdr;
+       const int       intf;
 {
        Variable        *var;
        int             idx;
@@ -2098,9 +2105,9 @@
                switch ( idx ) {
                case SYS_OBJID:
                        var->type = ASN_OBJID;
-                       bcopy ( (caddr_t)&Objids[MY_OBJID],
-                           (caddr_t)&var->var.oval,
-                               sizeof(Objid) );
+                       bcopy ( &Objids[MY_OBJID],
+                               &var->var.oval,
+                               sizeof(var->var.oval) );
                        break;
                case UPTIME_OBJID:
                        var->type = ASN_TIMESTAMP;
@@ -2152,9 +2159,9 @@
                        break;
                case ATMF_SYSID:
                        var->type = ASN_OCTET;
-                       var->var.sval[0] = 6;
-                       bcopy ( (caddr_t)&Cfg[intf].acp_macaddr,
-                           (caddr_t)&var->var.sval[1], 6 );
+                       var->var.sval[0] = sizeof(Cfg[intf].acp_macaddr);
+                       bcopy ( &Cfg[intf].acp_macaddr,
+                               &var->var.sval[1], sizeof(Cfg[intf].acp_macaddr) );
                        break;
                default:
                        /* NO_SUCH */
@@ -2177,7 +2184,7 @@
 {
        struct timeval  tvp;
        fd_set          rfd;
-       u_char          buf[1024];
+       char            buf[1024];
        Variable        *var;
        int             intf;
        int             maxfd = 0;
@@ -2188,7 +2195,7 @@
        for ( ; ; ) {
            int         count;
            int         n;
-           caddr_t     bpp;
+           char        *bpp;
            Snmp_Header *Hdr;
 
            /*
@@ -2222,7 +2229,7 @@
                        /*
                         * Clear addressTable
                         */
-                       bzero ( (caddr_t)&addressEntry[intf], sizeof(Objid) );
+                       bzero ( &addressEntry[intf], sizeof(Objid) );
 
                        /*
                         * Start by sending a COLD_START trap. This should cause the
@@ -2238,7 +2245,7 @@
                         * ILMI_COLDSTART.
                         */
                        /* atm_timeout() */
-       
+
                        /* Enter new state */
                        ilmi_state[intf] = ILMI_INIT;
                        /* fall into ILMI_INIT */
@@ -2252,37 +2259,37 @@
                         */
                        PDU_Header = build_generic_header();
 
-                       PDU_Header->head = (Variable *)malloc(sizeof(Variable));
+                       PDU_Header->head = malloc(sizeof(*PDU_Header->head));
                        if (PDU_Header->head == NULL) {
-                               fprintf(stderr, "malloc() failed in %s()\n", __func__);
+                               fprintf(stderr, "malloc() failed in %s() line %d\n", 
__func__, __LINE__);
                                exit(1);
                        }
-                       bzero(PDU_Header->head, sizeof(Variable));
+                       bzero(PDU_Header->head, sizeof(*PDU_Header->head));
 
                        var = PDU_Header->head;
-                       bcopy ( (caddr_t)&Objids[ADDRESS_OBJID], (caddr_t)&var->oid,
-                           sizeof(Objid) );
+                       bcopy ( &Objids[ADDRESS_OBJID], &var->oid,
+                           sizeof(var->oid) );
                        var->type = ASN_NULL;
                        var->next = NULL;
-       
+
                        /*
                         * Send GETNEXT request looking for empty ATM Address Table
                         */
                        PDU_Header->reqid = Req_ID++;
                        build_pdu ( PDU_Header, PDU_TYPE_GETNEXT );
                        send_resp ( intf, PDU_Header, Resp_Buf );
-       
+
                        /*
                         * Start a timeout while looking for SET message. If we don't 
receive
                         * a SET, then go back to COLD_START state.
                         */
                        /* atm_timeout() */
                        break;
-       
+
                case ILMI_RUNNING:
                        /* Normal SNMP processing */
                        break;
-       
+
                default:
                        break;
                }
@@ -2295,8 +2302,8 @@
                 * Check for received messages
                 */
                if ( ilmi_fd[intf] > 0 && FD_ISSET ( ilmi_fd[intf], & rfd ) ) {
-               
-                   n = read ( ilmi_fd[intf], (caddr_t)&buf[1], sizeof(buf) - 1 );
+
+                   n = read ( ilmi_fd[intf], &buf[1], sizeof(buf) - 1 );
                    if ( n == -1 && ( errno == ECONNRESET || errno == EBADF ) ) {
                        ilmi_state[intf] = ILMI_COLDSTART;
                        close ( ilmi_fd[intf] );
@@ -2305,12 +2312,12 @@
                        if ( Log && Debug_Level > 1 ) fprintf ( Log, "***** state %d 
***** read %d bytes from %d (%d) ***** %s *****\n",
                            ilmi_state[intf], n, intf, ilmi_fd[intf], 
PDU_Types[buf[14] - 0xA0] ); {
                                if ( Debug_Level > 2 )
-                                   hexdump ( (caddr_t)&buf[1], n );
+                                   hexdump ( &buf[1], n );
                        }
-                       bpp = (caddr_t)&buf[1];
+                       bpp = &buf[1];
                        if ( ( Hdr = asn_get_header ( &bpp ) ) == NULL )
                            continue;
-       
+
                        /* What we do with this messages depends upon the state we're 
in */
                        switch ( ilmi_state[intf] ) {
                        case ILMI_COLDSTART:
@@ -2325,9 +2332,9 @@
                                 * Should be because the remote side is attempting
                                 * to verify that our table is empty
                                 */
-                               if ( oid_ncmp ( (caddr_t)&Hdr->head->oid,
-                                   (caddr_t)&Objids[ADDRESS_OBJID],
-                                       Objids[ADDRESS_OBJID].oid[0] ) == 0 ) {
+                               if ( oid_ncmp ( &Hdr->head->oid,
+                                               &Objids[ADDRESS_OBJID],
+                                               Objids[ADDRESS_OBJID].oid[0] ) == 0 ) {
                                        if ( addressEntry[intf].oid[0] ) {
                                            /* XXX - FIXME */
                                            /* Our table is not empty - return address 
*/
@@ -2381,12 +2388,12 @@
                                break;
                            case PDU_TYPE_SET:
                                /* Look for SET_PREFIX Objid */
-                               if ( oid_ncmp ( (caddr_t)&Hdr->head->oid,
-                                   (caddr_t)&Objids[SETPFX_OBJID],
-                                       Objids[SETPFX_OBJID].oid[0] ) == 0 ) {
+                               if ( oid_ncmp ( &Hdr->head->oid,
+                                               &Objids[SETPFX_OBJID],
+                                               Objids[SETPFX_OBJID].oid[0] ) == 0 ) {
                                            set_prefix ( &Hdr->head->oid, Hdr, intf );
                                            /* Reply to SET before sending our ADDRESS 
*/
-                                           build_pdu(Hdr, PDU_TYPE_GETRESP);
+                                           build_pdu( Hdr, PDU_TYPE_GETRESP );
                                            send_resp( intf, Hdr, Resp_Buf );
                                            set_address ( Hdr, intf );
                                } else {
@@ -2422,9 +2429,9 @@
                                break;
                            case PDU_TYPE_SET:
                                /* Look for SET_PREFIX Objid */
-                               if ( oid_ncmp ( (caddr_t)&Hdr->head->oid,
-                                   (caddr_t)&Objids[SETPFX_OBJID],
-                                       Objids[SETPFX_OBJID].oid[0] ) == 0 ) {
+                               if ( oid_ncmp ( &Hdr->head->oid,
+                                               &Objids[SETPFX_OBJID],
+                                               Objids[SETPFX_OBJID].oid[0] ) == 0 ) {
                                            set_prefix ( &Hdr->head->oid, Hdr, intf );
                                            /* Reply to SET before sending our ADDRESS 
*/
                                            build_pdu(Hdr, PDU_TYPE_GETRESP);

Reply via email to