From owner-freebsd-current Thu Feb 27 5:11:57 2003 Delivered-To: freebsd-current@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id E63F337B401 for ; Thu, 27 Feb 2003 05:11:16 -0800 (PST) Received: from mail.liwing.de (mail.liwing.de [213.70.188.162]) by mx1.FreeBSD.org (Postfix) with ESMTP id E819643FCB for ; Thu, 27 Feb 2003 05:11:14 -0800 (PST) (envelope-from rehsack@liwing.de) Received: (qmail 50366 invoked from network); 27 Feb 2003 13:11:13 -0000 Received: from stingray.liwing.de (HELO liwing.de) ([213.70.188.164]) (envelope-sender ) by mail.liwing.de (qmail-ldap-1.03) with SMTP for ; 27 Feb 2003 13:11:13 -0000 Message-ID: <3E5E0E71.7000803@liwing.de> Date: Thu, 27 Feb 2003 14:11:13 +0100 From: Jens Rehsack Organization: LiWing IT-Services User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 To: current@FreeBSD.ORG Subject: type errors in src-tree Content-Type: multipart/mixed; boundary="------------080600080001000600070003" Sender: owner-freebsd-current@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.ORG This is a multi-part message in MIME format. --------------080600080001000600070003 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit Hi, I made some experiments with the optimization switches of the cc of FBSD-CURRENT, and if I turned on -finline-functions, the link of src/bin/cat fails, because of: cc -O -O3 -fforce-addr -fforce-mem -msse -mmmx -m3dnow -momit-leaf-frame-pointer -fcse-follow-jumps -fcse-skip-blocks -fgcse -frerun-cse-after-loop -fstrength-reduce -fgcse-lm -fgcse-sm -frerun-loop-opt -fschedule-insns2 -pipe -DNO_WERROR -march=athlon-tbird -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wformat=2 -Wno-format-extra-args -Werror -c /usr/src/bin/cat/cat.c cc -O -O3 -fforce-addr -fforce-mem -msse -mmmx -m3dnow -momit-leaf-frame-pointer -fcse-follow-jumps -fcse-skip-blocks -fgcse -frerun-cse-after-loop -fstrength-reduce -fgcse-lm -fgcse-sm -frerun-loop-opt -fschedule-insns2 -pipe -DNO_WERROR -march=athlon-tbird -Werror -Wall -Wno-format-y2k -Wno-uninitialized -Wformat=2 -Wno-format-extra-args -Werror -static -o cat cat.o /usr/obj/usr/src/i386/usr/lib/libc.a(atexit.o): In function `atexit': atexit.o(.text+0xc0): undefined reference to `_pthread_mutex_unlock' atexit.o(.text+0xce): undefined reference to `_pthread_mutex_lock' atexit.o(.text+0xdc): undefined reference to `_pthread_mutex_unlock' atexit.o(.text+0xfb): undefined reference to `_pthread_mutex_lock' atexit.o(.text+0x10c): undefined reference to `_pthread_mutex_unlock' atexit.o(.text+0x133): undefined reference to `_pthread_mutex_lock' /usr/obj/usr/src/i386/usr/lib/libc.a(_flock_stub.o): In function `flockfile': _flock_stub.o(.text+0x10): undefined reference to `_pthread_self' _flock_stub.o(.text+0x25): undefined reference to `_pthread_mutex_lock' /usr/obj/usr/src/i386/usr/lib/libc.a(_flock_stub.o): In function `_flockfile_debug': _flock_stub.o(.text+0x60): undefined reference to `_pthread_self' _flock_stub.o(.text+0x75): undefined reference to `_pthread_mutex_lock' /usr/obj/usr/src/i386/usr/lib/libc.a(_flock_stub.o): In function `ftrylockfile': _flock_stub.o(.text+0xb5): undefined reference to `_pthread_self' _flock_stub.o(.text+0xca): undefined reference to `_pthread_mutex_trylock' /usr/obj/usr/src/i386/usr/lib/libc.a(_flock_stub.o): In function `funlockfile': _flock_stub.o(.text+0x10d): undefined reference to `_pthread_self' _flock_stub.o(.text+0x145): undefined reference to `_pthread_mutex_unlock' *** Error code 1 Stop in /usr/src/bin/cat. *** Error code 1 Stop in /usr/src/bin. *** Error code 1 Stop in /usr/src. *** Error code 1 Stop in /usr/src. *** Error code 1 Stop in /usr/src. I patched the file src/lib/libc/gen/_pthread_stubs.c that way, that the generated functions are not static anymore. A test with the compiler using '-S' for compiling til assembly output shows no difference between static and extern declared functions. The compiler did never inline a static function unless -finline-functions is specified, and than it's done for statics and externs as well. The second error I got is from src/sbin/atm/ilmid/ilmid.c: ===> sbin/atm/ilmid cc -O -O3 -fforce-addr -fforce-mem -msse -mmmx -m3dnow -momit-leaf-frame-pointer -fcse-follow-jumps -fcse-skip-blocks -fgcse -frerun-cse-after-loop -fstrength-reduce -fgcse-lm -fgcse-sm -frerun-loop-opt -fschedule-insns2 -pipe -DNO_WERROR -march=athlon-tbird -I/usr/src/sbin/atm/ilmid/../../../sys -Werror -Wall -Wno-format-y2k -Wno-uninitialized -c /usr/src/sbin/atm/ilmid/ilmid.c cc1: warnings being treated as errors In file included from /usr/src/sbin/atm/ilmid/ilmid.c:861: /usr/src/sbin/atm/ilmid/ilmid.c: In function `parse_oids': /usr/src/sbin/atm/ilmid/ilmid.c:456: warning: passing arg 0 of `asn_get_pdu_len' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:867: /usr/src/sbin/atm/ilmid/ilmid.c:659: warning: passing arg 0 of `asn_get_objid' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:872: /usr/src/sbin/atm/ilmid/ilmid.c:538: warning: passing arg 0 of `asn_get_int' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:879: /usr/src/sbin/atm/ilmid/ilmid.c:659: warning: passing arg 0 of `asn_get_objid' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:882: /usr/src/sbin/atm/ilmid/ilmid.c:737: warning: passing arg 0 of `asn_get_octet' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:2144: /usr/src/sbin/atm/ilmid/ilmid.c: In function `process_get': /usr/src/sbin/atm/ilmid/ilmid.c:1833: warning: passing arg 0 of `get_local_ip' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:2328: /usr/src/sbin/atm/ilmid/ilmid.c: In function `ilmi_do_state': /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:2384: /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type In file included from /usr/src/sbin/atm/ilmid/ilmid.c:2425: /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type /usr/src/sbin/atm/ilmid/ilmid.c:1074: warning: passing arg 0 of `oid_ncmp' from incompatible pointer type *** Error code 1 Stop in /usr/src/sbin/atm/ilmid. *** Error code 1 Stop in /usr/src/sbin/atm. *** Error code 1 ... I've checked the file and saw many problems with declared functions and used types. As far as I didn't understand why 'asn_get_pdu_len' (and similar) couldn't be called using a 'caddr_t *' as first argument instead of 'u_char **', I think it's an error calling 'oid_ncmp' using a 'caddr_t' when a 'Objid *' is available and required by the function (it casts the 'caddr_t' to 'Objid *'. Further I didn't understand why 'get_local_ip' is called using a 'long *' when a 'int *' is available on 32-bit and 64-bit architectures. Does FreeBSD run on any architecture where an int may become 32-bit? I read the source carefully and wondered about much, so I took the Stevens (Unix Network Programming, Volume 1) and the Kernighan & Richie (Programming in C) out of my bookshelf and try to make the source more standard conform. So I consequently use 'uint32_t' for an ip-address, because htonl/ntohl require exact this type and it's more cross-plattform-safe using that instead of wild int/long casting. Furthermore I used caddr_t instead of mixing 'uchar *', 'caddr_t' and 'char *'. A real error has been fixed in function 'build_cold_start' and every possible sizeof(type) has been replaced by sizeof(var). Useless type casts have been removed. Because I don't have any atm hardware, I cannot test the results, but i compiles fine without any errors and can be called. A tester would be nice :-) So long, Jens Rehsack -- L i W W W i Jens Rehsack L W W W L i W W W W i nnn gggg LiWing IT-Services L i W W W W i n n g g LLLL i W W i n n g g Friesenstraße 2 gggg 06112 Halle g g g Tel.: +49 - 3 45 - 5 17 05 91 ggg e-Mail: Fax: +49 - 3 45 - 5 17 05 92 http://www.liwing.de/ --------------080600080001000600070003 Content-Type: text/plain; name="patch-lib-libc-gen-_pthread_stubs.c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-lib-libc-gen-_pthread_stubs.c" --- lib/libc/gen/_pthread_stubs.c.orig Tue Feb 18 18:52:31 2003 +++ lib/libc/gen/_pthread_stubs.c Tue Feb 18 19:05:04 2003 @@ -97,18 +97,18 @@ #define FUNC_EXP(name) __CONCAT(name, _exp) #define STUB_FUNC(name, idx, ret) \ - static ret FUNC_EXP(name)(void) __unused; \ - static ret FUNC_INT(name)(void) __unused; \ + extern ret FUNC_EXP(name)(void) __unused; \ + extern ret FUNC_INT(name)(void) __unused; \ WEAK_REF(FUNC_EXP(name), name); \ WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ typedef ret (*FUNC_TYPE(name))(void); \ - static ret FUNC_EXP(name)(void) \ + ret FUNC_EXP(name)(void) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ return (func()); \ } \ - static ret FUNC_INT(name)(void) \ + ret FUNC_INT(name)(void) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ @@ -116,18 +116,18 @@ } #define STUB_FUNC1(name, idx, ret, p0_type) \ - static ret FUNC_EXP(name)(p0_type) __unused; \ - static ret FUNC_INT(name)(p0_type) __unused; \ + extern ret FUNC_EXP(name)(p0_type) __unused; \ + extern ret FUNC_INT(name)(p0_type) __unused; \ WEAK_REF(FUNC_EXP(name), name); \ WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ typedef ret (*FUNC_TYPE(name))(p0_type); \ - static ret FUNC_EXP(name)(p0_type p0) \ + ret FUNC_EXP(name)(p0_type p0) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ return (func(p0)); \ } \ - static ret FUNC_INT(name)(p0_type p0) \ + ret FUNC_INT(name)(p0_type p0) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ @@ -135,18 +135,18 @@ } #define STUB_FUNC2(name, idx, ret, p0_type, p1_type) \ - static ret FUNC_EXP(name)(p0_type, p1_type) __unused; \ - static ret FUNC_INT(name)(p0_type, p1_type) __unused; \ + extern ret FUNC_EXP(name)(p0_type, p1_type) __unused; \ + extern ret FUNC_INT(name)(p0_type, p1_type) __unused; \ WEAK_REF(FUNC_EXP(name), name); \ WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ typedef ret (*FUNC_TYPE(name))(p0_type, p1_type); \ - static ret FUNC_EXP(name)(p0_type p0, p1_type p1) \ + ret FUNC_EXP(name)(p0_type p0, p1_type p1) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ return (func(p0, p1)); \ } \ - static ret FUNC_INT(name)(p0_type p0, p1_type p1) \ + ret FUNC_INT(name)(p0_type p0, p1_type p1) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ @@ -154,18 +154,18 @@ } #define STUB_FUNC3(name, idx, ret, p0_type, p1_type, p2_type) \ - static ret FUNC_EXP(name)(p0_type, p1_type, p2_type) __unused; \ - static ret FUNC_INT(name)(p0_type, p1_type, p2_type) __unused; \ + extern ret FUNC_EXP(name)(p0_type, p1_type, p2_type) __unused; \ + extern ret FUNC_INT(name)(p0_type, p1_type, p2_type) __unused; \ WEAK_REF(FUNC_EXP(name), name); \ WEAK_REF(FUNC_INT(name), __CONCAT(_, name)); \ typedef ret (*FUNC_TYPE(name))(p0_type, p1_type, p2_type); \ - static ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \ + ret FUNC_EXP(name)(p0_type p0, p1_type p1, p2_type p2) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][0]; \ return (func(p0, p1, p2)); \ } \ - static ret FUNC_INT(name)(p0_type p0, p1_type p1, p2_type p2) \ + ret FUNC_INT(name)(p0_type p0, p1_type p1, p2_type p2) \ { \ FUNC_TYPE(name) func; \ func = (FUNC_TYPE(name))__thr_jtable[idx][1]; \ --------------080600080001000600070003 Content-Type: text/plain; name="patch-sbin_atm_ilmid_ilmid_c" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch-sbin_atm_ilmid_ilmid_c" --- ilmid.c.orig Thu Feb 27 10:16:55 2003 +++ ilmid.c Thu Feb 27 13:02:18 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_ident_str); + /* * 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( caddr_t, 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; + caddr_t bp; + 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 * - decoded length @@ -451,21 +454,21 @@ */ int asn_get_pdu_len ( bufp, plen ) - u_char **bufp; - int *plen; + caddr_t *bufp; + uint32_t *plen; { - u_char *bp = *bufp; - int len = 0; - int i, b; + caddr_t 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; + caddr_t *bufp; + uint32_t *len; { - u_char *bp = *bufp; - int val = 0; - int l = *len; + caddr_t 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 * - value of encoded integer * */ int asn_get_int ( bufp, plen ) - u_char **bufp; - int *plen; + caddr_t *bufp; + uint32_t *plen; { - int i; - int len; - int v = 0; - u_char *bp = *bufp; + uint32_t i; + uint32_t len; + int v = 0; + caddr_t 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; + caddr_t *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; + caddr_t 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 ( (caddr_t)&u.c[sizeof(u.i)-len], bp, len ); bp += len; *bufp = bp; @@ -618,7 +621,7 @@ print_objid ( objid ) 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; + caddr_t *bufp; + Objid *objid; + uint32_t *plen; +{ + uint32_t len; + caddr_t bp = *bufp; + int *ip = (int *)objid + 1; /* First byte will contain length */ + 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,28 @@ */ int asn_put_objid ( bufp, objid ) - u_char **bufp; - Objid *objid; + caddr_t *bufp; + Objid *objid; { - int len = 0; - u_char *bp = *bufp; - u_char *cpp; - int i; + uint32_t len = 0; + caddr_t bp = *bufp; + caddr_t cpp; + uint32_t i, oidlen = objid->oid[0]; cpp = bp; *bp++ = objid->oid[0]; - len++; - for ( i = 1; i <= objid->oid[0]; i++ ) { + ++len; + for ( i = 1; i <= oidlen; ++i ) { /* FIXME: objid->oid[0] can be greater than 128 which is sizeof(objid->oid) */ u_int 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 +731,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; + caddr_t *bufp; + caddr_t octet; + uint32_t *plen; +{ + caddr_t 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; @@ -831,22 +834,22 @@ Snmp_Header *h; caddr_t *bp; { - int len = h->varlen; - int sublen; + uint32_t len = h->varlen; + uint32_t sublen; Variable *var; caddr_t 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 +875,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 +918,25 @@ */ Snmp_Header * asn_get_header ( bufp ) - u_char **bufp; + caddr_t *bufp; { Snmp_Header *h; - u_char *bp = *bufp; - int len = 0; - int dummy = 0; + caddr_t 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 +975,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 +1032,15 @@ */ int oid_cmp ( oid1, oid2 ) - Objid *oid1, *oid2; + Objid *oid1, *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 ); @@ -1070,9 +1075,9 @@ int oid_ncmp ( oid1, oid2, len ) Objid *oid1, *oid2; - int len; + uint32_t len; { - int i; + uint32_t i; /* * value by value compare @@ -1102,7 +1107,7 @@ find_var ( var ) Variable *var; { - int i; + int i; for ( i = 0; i < NUM_OIDS; i++ ) if ( oid_cmp ( &var->oid, &Objids[i] ) == 0 ) { @@ -1114,7 +1119,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 @@ -1172,14 +1177,14 @@ Snmp_Header *hdr; int type; { - u_char *bp = Resp_Buf; - u_char *vpp; - u_char *ppp; + caddr_t bp = Resp_Buf; + caddr_t vpp; + caddr_t 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 +1193,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 +1213,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 +1255,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 +1267,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 +1280,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; + caddr_t 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; + caddr_t lpp; /* Variable type */ *bp++ = var->type; - len++; + ++len; lpp = bp; switch ( var->type ) { case ASN_INTEGER: @@ -1317,7 +1322,7 @@ break; case ASN_OCTET: *bp++ = var->var.sval[0]; - len++; + ++len; bcopy ( (caddr_t)&var->var.sval[1], bp, var->var.sval[0] ); len += var->var.sval[0]; @@ -1325,7 +1330,7 @@ break; case ASN_NULL: *bp++ = 0x00; - len++; + ++len; break; case ASN_OBJID: len += asn_put_objid ( &bp, &var->var.oval ); @@ -1333,11 +1338,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 +1354,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,14 +1418,14 @@ */ void set_reqid ( resp, reqid ) - u_char *resp; - int reqid; + caddr_t resp; + uint32_t reqid; { - u_char *bp = (u_char *)&resp[18]; + caddr_t bp = resp+18; union { - int i; - u_char c[4]; - } u; + uint32_t i; + char c[sizeof(uint32_t)]; + } u; u.i = htonl(reqid); @@ -1433,7 +1438,7 @@ } /* - * Send a generic response packet + * Send a generic response packet - FIXME: documentation doesn't match declaration * * Arguments: * sd - socket to send the reply on @@ -1448,12 +1453,12 @@ send_resp ( intf, Hdr, resp ) int intf; Snmp_Header *Hdr; - u_char *resp; + caddr_t 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] ); @@ -1477,33 +1482,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 +1524,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 +1568,7 @@ */ if ( buf_len <= 0 ) { bzero ( Cfg, sizeof(Cfg) ); - bzero( Intf, sizeof(Intf) ); + bzero ( Intf, sizeof(Intf) ); NUnits = 0; return; } @@ -1570,11 +1576,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 +1599,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 +1626,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 ) { @@ -1688,7 +1694,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 +1708,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; @@ -1828,11 +1834,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; @@ -1855,7 +1861,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 ); @@ -1901,7 +1907,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,7 +1915,7 @@ * 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 ( errno != EALREADY ) { @@ -1957,17 +1963,17 @@ 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,20 +1997,20 @@ 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; -{ + char *path; /* FIXME: caddr_t? */ +{ char *fname; if ( ( fname = (char *)strrchr ( path, '/' ) ) != NULL ) @@ -2036,7 +2042,7 @@ if ( foregnd ) { Log = stderr; } else { - if ( ( Log = fopen ( LOG_FILE, "a" ) ) == NULL ) + if ( ( Log = fopen ( LOG_FILE, "a" ) ) == NULL ) Log = NULL; } if ( Log ) { @@ -2098,9 +2104,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 +2158,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 +2183,7 @@ { struct timeval tvp; fd_set rfd; - u_char buf[1024]; + char buf[1024]; Variable *var; int intf; int maxfd = 0; @@ -2238,7 +2244,7 @@ * ILMI_COLDSTART. */ /* atm_timeout() */ - + /* Enter new state */ ilmi_state[intf] = ILMI_INIT; /* fall into ILMI_INIT */ @@ -2252,37 +2258,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 +2301,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 +2311,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]; 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 +2331,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 +2387,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 +2428,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); --------------080600080001000600070003-- To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message