uint32_t localdata2;
char *str;
const uint8_t *ptr;
- char *pnt;
ptr = lcom->val + (i * LCOMMUNITY_SIZE);
memcpy(&lcomval, ptr, LCOMMUNITY_SIZE);
/* Allocate memory. 48 bytes taken off bgp_lcommunity.c */
- str = pnt = XMALLOC(MTYPE_LCOMMUNITY_STR, 48);
-
ptr = (uint8_t *)lcomval.val;
ptr = ptr_get_be32(ptr, &globaladmin);
ptr = ptr_get_be32(ptr, &localdata1);
ptr = ptr_get_be32(ptr, &localdata2);
(void)ptr; /* consume value */
- sprintf(pnt, "%u:%u:%u", globaladmin, localdata1, localdata2);
- pnt += strlen(pnt);
- *pnt = '\0';
+ str = XMALLOC(MTYPE_LCOMMUNITY_STR, 48);
+ snprintf(str, 48, "%u:%u:%u", globaladmin, localdata1, localdata2);
return str;
}
.config_write = config_write_bgp_dump,
};
-#if 0
-char *
-config_time2str (unsigned int interval)
-{
- static char buf[BUFSIZ];
-
- buf[0] = '\0';
-
- if (interval / 3600)
- {
- sprintf (buf, "%dh", interval / 3600);
- interval %= 3600;
- }
- if (interval / 60)
- {
- sprintf (buf + strlen (buf), "%dm", interval /60);
- interval %= 60;
- }
- if (interval)
- {
- sprintf (buf + strlen (buf), "%d", interval);
- }
- return buf;
-}
-#endif
-
static int config_write_bgp_dump(struct vty *vty)
{
if (bgp_dump_all.filename) {
if ((peer->status == OpenConfirm)
|| (peer->status == Established)) {
/* ORF received prefix-filter pnt */
- sprintf(orf_name, "%s.%d.%d", peer->host, afi, safi);
+ snprintf(orf_name, sizeof(orf_name), "%s.%d.%d",
+ peer->host, afi, safi);
prefix_bgp_orf_remove_all(afi, orf_name);
}
}
config_file_tmp = XMALLOC(MTYPE_TMP, strlen(config_file) + 8);
- sprintf(config_file_tmp, "%s.XXXXXX", config_file);
+ snprintf(config_file_tmp, strlen(config_file) + 8, "%s.XXXXXX",
+ config_file);
/* Open file to configuration write. */
fd = mkstemp(config_file_tmp);
static int set_log_file(struct zlog_cfg_file *target, struct vty *vty,
const char *fname, int loglevel)
{
- char *p = NULL;
+ char path[MAXPATHLEN + 1];
const char *fullpath;
bool ok;
+
/* Path detection. */
if (!IS_DIRECTORY_SEP(*fname)) {
char cwd[MAXPATHLEN + 1];
return CMD_WARNING_CONFIG_FAILED;
}
- p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2);
- sprintf(p, "%s/%s", cwd, fname);
- fullpath = p;
+ snprintf(path, sizeof(path), "%s/%s", cwd, fname);
+ fullpath = path;
} else
fullpath = fname;
target->prio_min = loglevel;
ok = zlog_file_set_filename(target, fullpath);
- XFREE(MTYPE_TMP, p);
-
if (!ok) {
if (vty)
vty_out(vty, "can't open logfile %s\n", fname);
}
fullpath_tmp = malloc(strlen(fullpath) + 8);
- sprintf(fullpath_tmp, "%s.XXXXXX", fullpath);
+ snprintf(fullpath_tmp, strlen(fullpath) + 8, "%s.XXXXXX", fullpath);
/* Open file to configuration write. */
tmp = mkstemp(fullpath_tmp);
if (area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
inet_ntop(AF_INET, area_id, buf, length);
else
- sprintf(buf, "%lu", (unsigned long)ntohl(area_id->s_addr));
+ snprintf(buf, length, "%lu",
+ (unsigned long)ntohl(area_id->s_addr));
}
static int str2metric(const char *str, int *metric)
static int config_write_network_area(struct vty *vty, struct ospf *ospf)
{
struct route_node *rn;
- uint8_t buf[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
/* `network area' print. */
for (rn = route_top(ospf->networks); rn; rn = route_next(rn))
/* Create Area ID string by specified Area ID format. */
if (n->area_id_fmt == OSPF_AREA_ID_FMT_DOTTEDQUAD)
- inet_ntop(AF_INET, &n->area_id, (char *)buf,
+ inet_ntop(AF_INET, &n->area_id, buf,
sizeof(buf));
else
- sprintf((char *)buf, "%lu",
- (unsigned long int)ntohl(
- n->area_id.s_addr));
+ snprintf(buf, sizeof(buf), "%lu",
+ (unsigned long int)ntohl(
+ n->area_id.s_addr));
/* Network print. */
vty_out(vty, " network %s/%d area %s\n",
{
struct listnode *node;
struct ospf_area *area;
- uint8_t buf[INET_ADDRSTRLEN];
+ char buf[INET_ADDRSTRLEN];
/* Area configuration print. */
for (ALL_LIST_ELEMENTS_RO(ospf->areas, node, area)) {
struct route_node *rn1;
- area_id2str((char *)buf, sizeof(buf), &area->area_id,
+ area_id2str(buf, sizeof(buf), &area->area_id,
area->area_id_fmt);
if (area->auth_type != OSPF_AUTH_NULL) {