From: wessels <> Date: Sat, 29 Nov 1997 06:25:25 +0000 (+0000) Subject: - clean up snmplib #includes to eliminate compiler warnings X-Git-Tag: SQUID_3_0_PRE1~4460 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=931ae822ce95284f3ba42ac5a183c4d868f58345;p=thirdparty%2Fsquid.git - clean up snmplib #includes to eliminate compiler warnings - also use xcalloc() instead of calloc(), etc. --- diff --git a/include/snmp_api.h b/include/snmp_api.h index 5241da56ac..1889da1877 100644 --- a/include/snmp_api.h +++ b/include/snmp_api.h @@ -306,6 +306,8 @@ void snmp_timeout (void); * Operations are defined below: */ +extern int snmp_build(struct snmp_session *, struct snmp_pdu *, u_char *, int *, int); + #define RECEIVED_MESSAGE 1 #define TIMED_OUT 2 diff --git a/include/snmp_impl.h b/include/snmp_impl.h index f6e8f1d7dd..a2cf874a10 100644 --- a/include/snmp_impl.h +++ b/include/snmp_impl.h @@ -79,7 +79,8 @@ SOFTWARE. #define NSAP (ASN_APPLICATION | 5) #define COUNTER64 (ASN_APPLICATION | 6) #define UINTEGER (ASN_APPLICATION | 7) -#define DEBUG + +#undef DEBUG #ifdef DEBUG #define ERROR(string) fprintf(stderr,"%s(%d): ERROR %s\n",__FILE__, __LINE__, string); #else diff --git a/snmplib/mib.c b/snmplib/mib.c index 0b070ff686..d1a1aa2b42 100644 --- a/snmplib/mib.c +++ b/snmplib/mib.c @@ -28,6 +28,22 @@ SOFTWARE. #if HAVE_STDLIB_H #include #endif +#if HAVE_SYS_TYPES_H +#include +#endif +#if HAVE_CTYPE_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STRINGS_H +#include +#endif +#if HAVE_BSTRING_H +#include +#endif + #include "asn1.h" #include "snmp.h" @@ -768,7 +784,7 @@ read_objid(input, output, out_len) oid *op = output; char buf[512]; - bzero(buf, sizeof(buf)); + memset(buf, '\0', sizeof(buf)); if (*input == '.') input++; diff --git a/snmplib/parse.c b/snmplib/parse.c index a126452f81..4bdfc4736f 100644 --- a/snmplib/parse.c +++ b/snmplib/parse.c @@ -31,7 +31,7 @@ SOFTWARE. #if HAVE_SYS_TYPES_H #include #endif -#if HAVE_STDLIB>H +#if HAVE_STDLIB_H #include #endif #if HAVE_STRING_H @@ -45,6 +45,8 @@ SOFTWARE. #include "parse.h" +#include "util.h" + /* A quoted string value-- too long for a general "token" */ char *quoted_string_buffer; @@ -231,7 +233,7 @@ hash_init() int h; int b; - bzero((char *) buckets, sizeof(buckets)); + memset(buckets, '\0', sizeof(buckets)); for (tp = tokens; tp->name; tp++) { for (h = 0, cp = tp->name; *cp; cp++) h += *cp; @@ -255,7 +257,7 @@ init_node_hash(nodes) char *cp; int hash; - bzero((char *) nbuckets, sizeof(nbuckets)); + memset(nbuckets, '\0', sizeof(nbuckets)); for (np = nodes; np;) { nextp = np->next; hash = 0; @@ -275,7 +277,7 @@ Malloc(num) * library malloc */ if (num < 16) num = 16; - return (char *) calloc(1, num); + return xcalloc(1, num); } static void @@ -644,7 +646,7 @@ parse_objectid(fp, name) } if ((length = getoid(fp, oid, 32)) != 0) { np = root = (struct node *) Malloc(sizeof(struct node)); - bzero((char *) np, sizeof(struct node)); + memset(np, '\0', sizeof(struct node)); /* * For each parent-child subid pair in the subid array, * create a node and link it into the node list. @@ -662,7 +664,7 @@ parse_objectid(fp, name) np->enums = 0; /* set up next entry */ np->next = (struct node *) Malloc(sizeof(*np->next)); - bzero((char *) np->next, sizeof(struct node)); + memset(np->next, '\0', sizeof(struct node)); oldnp = np; np = np->next; } @@ -1099,7 +1101,7 @@ parse_objecttype(fp, name) printf("Description== \"%.50s\"\n", quoted_string_buffer); #endif np->description = quoted_string_buffer; - quoted_string_buffer = (char *) calloc(1, MAXQUOTESTR); + quoted_string_buffer = xcalloc(1, MAXQUOTESTR); break; case REFERENCE: @@ -1193,7 +1195,7 @@ parse_objectgroup(fp, name) printf("Description== \"%.50s\"\n", quoted_string_buffer); #endif np->description = quoted_string_buffer; - quoted_string_buffer = (char *) calloc(1, MAXQUOTESTR); + quoted_string_buffer = xcalloc(1, MAXQUOTESTR); break; default: @@ -1260,7 +1262,7 @@ parse_notificationDefinition(fp, name) printf("Description== \"%.50s\"\n", quoted_string_buffer); #endif np->description = quoted_string_buffer; - quoted_string_buffer = (char *) calloc(1, MAXQUOTESTR); + quoted_string_buffer = xcalloc(1, MAXQUOTESTR); break; default: @@ -1431,8 +1433,8 @@ parse(fp) struct node *np = 0, *root = NULL; hash_init(); - quoted_string_buffer = (char *) calloc(1, MAXQUOTESTR); /* free this later */ - bzero(tclist, 64 * sizeof(struct tc)); + quoted_string_buffer = xcalloc(1, MAXQUOTESTR); /* free this later */ + memset(tclist, '\0', 64 * sizeof(struct tc)); while (type != ENDOFFILE) { type = get_token(fp, token); diff --git a/snmplib/snmp_api.c b/snmplib/snmp_api.c index 45e8a0e6f4..e294700a0c 100644 --- a/snmplib/snmp_api.c +++ b/snmplib/snmp_api.c @@ -22,23 +22,50 @@ /* * snmp_api.c - API for access to snmp. */ -#define DEBUG_SNMPTRACE 0 /* set to 1 to print all SNMP actions */ -#define DEBUG_SNMPFULLDUMP 0 /* set to 1 to dump all SNMP packets */ -#include +#include "config.h" + +#if HAVE_UNISTD_H +#include +#endif +#if HAVE_STDLIB_H +#include +#endif +#if HAVE_SYS_TYPES_H #include -#include -#include -#include +#endif +#if HAVE_CTYPE_H +#include +#endif +#if HAVE_GNUMALLOC_H +#include +#elif HAVE_MALLOC_H && !defined(_SQUID_FREEBSD_) && !defined(_SQUID_NEXT_) +#include +#endif +#if HAVE_MEMORY_H +#include +#endif +#ifdef HAVE_STRING_H +#include +#endif +#ifdef HAVE_STRINGS_H +#include +#endif +#if HAVE_BSTRING_H +#include +#endif +#if HAVE_SYS_SOCKET_H #include -#include -#ifdef linux +#endif +#if HAVE_NETINET_IN_H +#include +#endif +#if HAVE_ARPA_INET_H #include -#include -#include -#include #endif +#define DEBUG_SNMPTRACE 0 /* set to 1 to print all SNMP actions */ +#define DEBUG_SNMPFULLDUMP 0 /* set to 1 to dump all SNMP packets */ #include "asn1.h" #include "snmp.h" @@ -46,6 +73,8 @@ #include "snmp_api.h" #include "snmp_client.h" +#include "util.h" + #define PACKET_LENGTH 4500 oid default_enterprise[] = @@ -109,6 +138,7 @@ int snmp_synch_response(); void md5Digest(); +#if NO_PRINTFS static char * api_errstring(snmp_errnumber) int snmp_errnumber; @@ -119,6 +149,7 @@ api_errstring(snmp_errnumber) return "Unknown Error"; } } +#endif #if UNUSED_CODE /* @@ -150,12 +181,14 @@ snmp_print_packet(packet, length, addr, code) if (length < 0) { return; } +#if NO_PRINTFS if (code <= 0) { /* received */ printf("\nReceived %4d bytes from ", length); } else { /* sending */ printf("\nSending %4d bytes to ", length); } printf("%s:", inet_ntoa(addr.sin_addr)); +#endif #if DEBUG_SNMPFULLDUMP for (count = 0; count < length; count++) { if ((count & 15) == 0) { @@ -164,7 +197,9 @@ snmp_print_packet(packet, length, addr, code) printf("%02X ", (int) (packet[count] & 255)); } #endif +#if NO_PRINTFS fflush(stdout); +#endif } #if DEBUG_SNMPTRACE @@ -226,11 +261,11 @@ snmp_open(session) extern int check_received_pkt(); /* Copy session structure and link into list */ - slp = (struct session_list *) calloc(1, sizeof(struct session_list)); - slp->internal = isp = (struct snmp_internal_session *) calloc(1, sizeof(struct snmp_internal_session)); - bzero((char *) isp, sizeof(struct snmp_internal_session)); + slp = xcalloc(1, sizeof(struct session_list)); + slp->internal = isp = xcalloc(1, sizeof(struct snmp_internal_session)); + memset(isp, '\0', sizeof(struct snmp_internal_session)); slp->internal->sd = -1; /* mark it not set */ - slp->session = (struct snmp_session *) calloc(1, sizeof(struct snmp_session)); + slp->session = xcalloc(1, sizeof(struct snmp_session)); bcopy((char *) session, (char *) slp->session, sizeof(struct snmp_session)); session = slp->session; /* now link it in. */ @@ -244,7 +279,7 @@ snmp_open(session) */ if (session->peername != NULL) { - cp = (u_char *) calloc(1, (unsigned) strlen(session->peername) + 1); + cp = xcalloc(1, (unsigned) strlen(session->peername) + 1); strcpy((char *) cp, session->peername); session->peername = (char *) cp; } @@ -261,19 +296,19 @@ snmp_open(session) if (session->community_len != SNMP_DEFAULT_COMMUNITY_LEN) { if (*session->community == '+') { session->community_len--; - cp = (u_char *) calloc(1, (unsigned) session->community_len); + cp = xcalloc(1, (unsigned) session->community_len); bcopy((char *) session->community + 1, (char *) cp, session->community_len); session->version = SNMP_VERSION_2C; } else { - cp = (u_char *) calloc(1, (unsigned) session->community_len); + cp = xcalloc(1, (unsigned) session->community_len); bcopy((char *) session->community, (char *) cp, session->community_len); } } else { session->community_len = strlen(DEFAULT_COMMUNITY); - cp = (u_char *) calloc(1, (unsigned) session->community_len); + cp = xcalloc(1, (unsigned) session->community_len); bcopy((char *) DEFAULT_COMMUNITY, (char *) cp, session->community_len); } @@ -283,7 +318,9 @@ snmp_open(session) perror("socket"); snmp_errno = SNMPERR_GENERR; if (!snmp_close(session)) { +#if NO_PRINTFS fprintf(stderr, "Couldn't abort session: %s. Exiting\n", api_errstring(snmp_errno)); +#endif exit(1); } return 0; @@ -296,10 +333,14 @@ snmp_open(session) } else { hp = gethostbyname(session->peername); if (hp == NULL) { +#if NO_PRINTFS fprintf(stderr, "unknown host: %s\n", session->peername); +#endif snmp_errno = SNMPERR_BAD_ADDRESS; if (!snmp_close(session)) { +#if NO_PRINTFS fprintf(stderr, "Couldn't abort session: %s. Exiting\n", api_errstring(snmp_errno)); +#endif exit(2); } return 0; @@ -330,8 +371,10 @@ snmp_open(session) perror("bind"); snmp_errno = SNMPERR_BAD_LOCPORT; if (!snmp_close(session)) { +#if NO_PRINTFS fprintf(stderr, "Couldn't abort session: %s. Exiting\n", api_errstring(snmp_errno)); +#endif exit(3); } return 0; @@ -373,11 +416,13 @@ sync_with_agent(session) session->agentClock = response->params.agentTime - time(NULL); } else { +#if NO_PRINTFS if (status == STAT_TIMEOUT) { printf("No Response from %s\n", session->peername); } else { /* status == STAT_ERROR */ printf("An error occurred, Quitting\n"); } +#endif exit(-1); } @@ -626,7 +671,9 @@ snmp_parse(session, pdu, data, length) return -1; if (version != SNMP_VERSION_1 && version != SNMP_VERSION_2C && version != SNMP_VERSION_2) { +#if NO_PRINTFS fprintf(stderr, "Wrong version: %ld\n", version); +#endif return -1; } save_data = data; @@ -657,7 +704,7 @@ snmp_parse(session, pdu, data, length) data = asn_parse_objid(data, &length, &type, objid, &pdu->enterprise_length); if (data == NULL) return -1; - pdu->enterprise = (oid *) calloc(1, pdu->enterprise_length * sizeof(oid)); + pdu->enterprise = xcalloc(1, pdu->enterprise_length * sizeof(oid)); bcopy((char *) objid, (char *) pdu->enterprise, pdu->enterprise_length * sizeof(oid)); four = 4; @@ -681,9 +728,9 @@ snmp_parse(session, pdu, data, length) return -1; while ((int) length > 0) { if (pdu->variables == NULL) { - pdu->variables = vp = (struct variable_list *) calloc(1, sizeof(struct variable_list)); + pdu->variables = vp = xcalloc(1, sizeof(struct variable_list)); } else { - vp->next_variable = (struct variable_list *) calloc(1, sizeof(struct variable_list)); + vp->next_variable = xcalloc(1, sizeof(struct variable_list)); vp = vp->next_variable; } vp->next_variable = NULL; @@ -693,14 +740,14 @@ snmp_parse(session, pdu, data, length) data = snmp_parse_var_op(data, objid, &vp->name_length, &vp->type, &vp->val_len, &var_val, (int *) &length); if (data == NULL) return -1; - op = (oid *) calloc(1, (unsigned) vp->name_length * sizeof(oid)); + op = xcalloc(1, (unsigned) vp->name_length * sizeof(oid)); bcopy((char *) objid, (char *) op, vp->name_length * sizeof(oid)); vp->name = op; len = PACKET_LENGTH; switch ((short) vp->type) { case ASN_INTEGER: - vp->val.integer = (long *) calloc(1, sizeof(long)); + vp->val.integer = xcalloc(1, sizeof(long)); vp->val_len = sizeof(long); asn_parse_int(var_val, &len, &vp->type, (long *) vp->val.integer, sizeof(vp->val.integer)); break; @@ -708,12 +755,12 @@ snmp_parse(session, pdu, data, length) case GAUGE: case TIMETICKS: case UINTEGER: - vp->val.integer = (long *) calloc(1, sizeof(unsigned long)); + vp->val.integer = xcalloc(1, sizeof(unsigned long)); vp->val_len = sizeof(unsigned long); asn_parse_unsigned_int(var_val, &len, &vp->type, (unsigned long *) vp->val.integer, sizeof(vp->val.integer)); break; case COUNTER64: - vp->val.counter64 = (struct counter64 *) calloc(1, sizeof(struct counter64)); + vp->val.counter64 = xcalloc(1, sizeof(struct counter64)); vp->val_len = sizeof(struct counter64); asn_parse_unsigned_int64(var_val, &len, &vp->type, (struct counter64 *) vp->val.counter64, @@ -723,14 +770,14 @@ snmp_parse(session, pdu, data, length) case IPADDRESS: case OPAQUE: case NSAP: - vp->val.string = (u_char *) calloc(1, (unsigned) vp->val_len); + vp->val.string = xcalloc(1, (unsigned) vp->val_len); asn_parse_string(var_val, &len, &vp->type, vp->val.string, &vp->val_len); break; case ASN_OBJECT_ID: vp->val_len = MAX_NAME_LEN; asn_parse_objid(var_val, &len, &vp->type, objid, &vp->val_len); vp->val_len *= sizeof(oid); - vp->val.objid = (oid *) calloc(1, (unsigned) vp->val_len); + vp->val.objid = xcalloc(1, (unsigned) vp->val_len); bcopy((char *) objid, (char *) vp->val.objid, vp->val_len); break; case SNMP_NOSUCHOBJECT: @@ -739,7 +786,9 @@ snmp_parse(session, pdu, data, length) case ASN_NULL: break; default: +#if NO_PRINTFS fprintf(stderr, "bad type returned (%x)\n", vp->type); +#endif break; } } @@ -795,7 +844,7 @@ snmp_send(session, pdu) /* fill in trap defaults */ pdu->reqid = 1; /* give a bogus non-error reqid for traps */ if (pdu->enterprise_length == SNMP_DEFAULT_ENTERPRISE_LENGTH) { - pdu->enterprise = (oid *) calloc(1, sizeof(DEFAULT_ENTERPRISE)); + pdu->enterprise = xcalloc(1, sizeof(DEFAULT_ENTERPRISE)); bcopy((char *) DEFAULT_ENTERPRISE, (char *) pdu->enterprise, sizeof(DEFAULT_ENTERPRISE)); pdu->enterprise_length = sizeof(DEFAULT_ENTERPRISE) / sizeof(oid); } @@ -806,13 +855,17 @@ snmp_send(session, pdu) if (isp->addr.sin_addr.s_addr != SNMP_DEFAULT_ADDRESS) { bcopy((char *) &isp->addr, (char *) &pdu->address, sizeof(pdu->address)); } else { +#if NO_PRINTFS fprintf(stderr, "No remote IP address specified\n"); +#endif snmp_errno = SNMPERR_BAD_ADDRESS; return 0; } } if (snmp_build(session, pdu, packet, &length, 0) < 0) { +#if NO_PRINTFS fprintf(stderr, "Error building packet\n"); +#endif snmp_errno = SNMPERR_GENERR; return 0; } @@ -828,13 +881,15 @@ snmp_send(session, pdu) if (pdu->command == GET_REQ_MSG || pdu->command == GETNEXT_REQ_MSG || pdu->command == SET_REQ_MSG || pdu->command == GETBULK_REQ_MSG) { /* set up to expect a response */ - rp = (struct request_list *) calloc(1, sizeof(struct request_list)); + rp = xcalloc(1, sizeof(struct request_list)); +#if NOT_NEEDED if (!rp) { fprintf(stderr, "Out of memory!\n"); snmp_errno = SNMPERR_GENERR; return 0; } +#endif rp->next_request = isp->requests; isp->requests = rp; rp->pdu = pdu; @@ -917,20 +972,23 @@ snmp_read(fdset) if (snmp_dump_packet) { snmp_print_packet(packet, length, from, 0); } - pdu = (struct snmp_pdu *) calloc(1, sizeof(struct snmp_pdu)); - + pdu = xcalloc(1, sizeof(struct snmp_pdu)); +#if NOT_NEEDED if (!pdu) { fprintf(stderr, "Out of memory!\n"); snmp_errno = SNMPERR_GENERR; return; } +#endif pdu->address = from; pdu->reqid = 0; pdu->variables = NULL; pdu->enterprise = NULL; pdu->enterprise_length = 0; if (snmp_parse(sp, pdu, packet, length) < 0) { +#if NO_PRINTFS fprintf(stderr, "Mangled packet\n"); +#endif snmp_free_pdu(pdu); return; } @@ -1095,7 +1153,9 @@ snmp_timeout() rp->retries++; rp->timeout <<= 1; if (snmp_build(sp, rp->pdu, packet, &length, 0) < 0) { +#if NO_PRINTFS fprintf(stderr, "Error building packet\n"); +#endif } if (snmp_dump_packet) { snmp_print_packet(packet, length, rp->pdu->address, 1);