Mailing List Archive

minor code cleanup
Hi,

Here is some code cleanup, based on compiler warnings...

--Sowmini


===================================================================
RCS file: rip_routemap.c,v
retrieving revision 1.4
diff -uwb -r1.4 rip_routemap.c
--- rip_routemap.c 2003/05/25 16:02:39 1.4
+++ rip_routemap.c 2004/05/21 16:52:51
@@ -59,11 +59,9 @@
case RMAP_RULE_MISSING:
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
case RMAP_COMPILE_ERROR:
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
}
}
return CMD_SUCCESS;
@@ -84,11 +82,9 @@
case RMAP_RULE_MISSING:
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
case RMAP_COMPILE_ERROR:
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
}
}
return CMD_SUCCESS;
@@ -109,11 +105,9 @@
case RMAP_RULE_MISSING:
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
case RMAP_COMPILE_ERROR:
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
}
}
return CMD_SUCCESS;
@@ -134,19 +128,18 @@
case RMAP_RULE_MISSING:
vty_out (vty, "%% Can't find rule.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
case RMAP_COMPILE_ERROR:
vty_out (vty, "%% Argument is malformed.%s", VTY_NEWLINE);
return CMD_WARNING;
- break;
}
}
return CMD_SUCCESS;
}

/* Hook function for updating route_map assignment. */
+/* ARGSUSED */
void
-rip_route_map_update ()
+rip_route_map_update (char *notused)
{
int i;

===================================================================
RCS file: ripd.c,v
retrieving revision 1.21
diff -uwb -r1.21 ripd.c
--- ripd.c 2004/05/05 14:09:37 1.21
+++ ripd.c 2004/05/21 16:56:44
@@ -885,7 +885,7 @@

/* Overwrite digest by my secret. */
memset (md5data->digest, 0, RIP_AUTH_MD5_SIZE);
- strncpy (md5data->digest, auth_str, RIP_AUTH_MD5_SIZE);
+ strncpy ((char *)md5data->digest, auth_str, RIP_AUTH_MD5_SIZE);

md5_init_ctx (&ctx);
md5_process_bytes (packet, packet_len + md5->auth_len, &ctx);
@@ -993,7 +993,7 @@

/* Generate a digest for the RIP packet. */
memset (secret, 0, RIP_AUTH_MD5_SIZE);
- strncpy (secret, auth_str, RIP_AUTH_MD5_SIZE);
+ strncpy ((char *)secret, auth_str, RIP_AUTH_MD5_SIZE);
md5_init_ctx (&ctx);
md5_process_bytes (s->data, s->endp, &ctx);
md5_process_bytes (secret, RIP_AUTH_MD5_SIZE, &ctx);
@@ -1247,7 +1247,7 @@

/* RIP packet send to destination address. */
int
-rip_send_packet (caddr_t buf, int size, struct sockaddr_in *to,
+rip_send_packet (u_char * buf, int size, struct sockaddr_in *to,
struct interface *ifp, struct connected *connected)
{
int ret, send_sock;
@@ -1556,7 +1556,7 @@
}
packet->command = RIP_RESPONSE;

- rip_send_packet ((caddr_t) packet, size, from, ifp, NULL);
+ rip_send_packet ((u_char *)packet, size, from, ifp, NULL);
}
rip_global_queries++;
}
@@ -1647,7 +1647,8 @@
union rip_buf rip_buf;
struct rip_packet *packet;
struct sockaddr_in from;
- int fromlen, len;
+ int len;
+ socklen_t fromlen;
struct interface *ifp;
struct rip_interface *ri;

@@ -1989,7 +1990,7 @@
stream_putw (s, RIP_AUTH_SIMPLE_PASSWORD);

memset ((s->data + s->putp), 0, 16);
- strncpy ((s->data + s->putp), ri->auth_str, 16);
+ strncpy ((char *)(s->data + s->putp), ri->auth_str, 16);
stream_set_putp (s, s->putp + 16);

num++;
@@ -2011,7 +2012,8 @@
stream_putw (s, RIP_AUTH_SIMPLE_PASSWORD);

memset ((s->data + s->putp), 0, 16);
- strncpy ((s->data + s->putp), key->string, 16);
+ strncpy ((char *)(s->data + s->putp),
+ key->string, 16);
stream_set_putp (s, s->putp + 16);

num++;
@@ -2683,7 +2685,7 @@
* interface does not support multicast. Caller loops
* over each connected address for this case.
*/
- if (rip_send_packet ((caddr_t) &rip_packet, sizeof (rip_packet),
+ if (rip_send_packet ((u_char *) &rip_packet, sizeof (rip_packet),
to, ifp, connected) != sizeof (rip_packet))
return -1;
else
@@ -2700,7 +2702,7 @@
if (p->family != AF_INET)
continue;

- if (rip_send_packet ((caddr_t) &rip_packet, sizeof (rip_packet),
+ if (rip_send_packet ((u_char *) &rip_packet, sizeof (rip_packet),
to, ifp, connected) != sizeof (rip_packet))
return -1;
}
@@ -3719,6 +3721,12 @@
rip_distribute_update_interface (ifp);
}
}
+/* ARGSUSED */
+void
+rip_distribute_update_all_wrapper(struct access_list *notused)
+{
+ rip_distribute_update_all();
+}

/* Delete all added rip route. */
void
@@ -3894,8 +3902,9 @@
}
}

+/* ARGSUSED */
void
-rip_routemap_update ()
+rip_routemap_update (char *notused)
{
struct interface *ifp;
listnode node;
@@ -3956,8 +3965,8 @@

/* Access list install. */
access_list_init ();
- access_list_add_hook (rip_distribute_update_all);
- access_list_delete_hook (rip_distribute_update_all);
+ access_list_add_hook (rip_distribute_update_all_wrapper);
+ access_list_delete_hook (rip_distribute_update_all_wrapper);

/* Prefix list initialize.*/
prefix_list_init ();
Re: minor code cleanup [ In reply to ]
On Fri, 21 May 2004 sowmini.varadhan@sun.com wrote:

>
> Hi,
>
> Here is some code cleanup, based on compiler warnings...

cheers.

> --Sowmini

regards,
--
Paul Jakma paul@clubi.ie paul@jakma.org Key ID: 64A2FF6A
warning: do not ever send email to spam@dishone.st
Fortune:
Moderation in all things.
-- Publius Terentius Afer [Terence]
Re: minor code cleanup [ In reply to ]
On Fri, 21 May 2004 sowmini.varadhan@sun.com wrote:

> + strncpy ((char *)secret, auth_str, RIP_AUTH_MD5_SIZE);

There's a tonne of this kind of thing all over the code. Anyone know
of a good reason for it? For anything that will have arithmetic
performed on it the correct type is surely one of the *int8* types,
no?

Seems like a good candidate to put on the things-to-audit-and-clean
list.

regards,
--
Paul Jakma paul@clubi.ie paul@jakma.org Key ID: 64A2FF6A
warning: do not ever send email to spam@dishone.st
Fortune:
It's a poor workman who blames his tools.