*/
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.64 1999-11-21 09:36:44 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/addrtoname.c,v 1.65 2000-01-17 06:24:23 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
tp->addr = i;
tp->nxt = newhnamemem();
- (void)sprintf(buf, "%u", i);
+ (void)snprintf(buf, sizeof(buf), "%u", i);
tp->name = savestr(buf);
return (tp->name);
}
tp->addr = i;
tp->nxt = newhnamemem();
- (void)sprintf(buf, "%u", i);
+ (void)snprintf(buf, sizeof(buf), "%u", i);
tp->name = savestr(buf);
return (tp->name);
}
while (table->name)
table = table->nxt;
if (nflag) {
- (void)sprintf(buf, "%d", port);
+ (void)snprintf(buf, sizeof(buf), "%d", port);
table->name = savestr(buf);
} else
table->name = savestr(sv->s_name);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.5 1999-11-21 09:36:47 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/machdep.c,v 1.6 2000-01-17 06:24:23 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
#include "machdep.h"
int
-abort_on_misalignment(char *ebuf)
+abort_on_misalignment(char *ebuf, size_t ebufsiz)
{
#ifdef __osf__
static int buf[2] = { SSIN_UACPROC, UAC_SIGBUS };
if (setsysinfo(SSI_NVPAIRS, (caddr_t)buf, 1, 0, 0) < 0) {
- (void)sprintf(ebuf, "setsysinfo: errno %d", errno);
+ (void)snprintf(ebuf, ebufsiz, "setsysinfo: errno %d", errno);
return (-1);
}
#endif
* WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
*
- * @(#) $Header: /tcpdump/master/tcpdump/machdep.h,v 1.1 1999-10-07 23:47:10 mcr Exp $ (LBL)
+ * @(#) $Header: /tcpdump/master/tcpdump/machdep.h,v 1.2 2000-01-17 06:24:24 itojun Exp $ (LBL)
*/
#ifndef tcpdump_machdep_h
#define tcpdump_machdep_h
-int abort_on_misalignment(char *);
+int abort_on_misalignment(char *, size_t);
#endif
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.4 2000-01-09 21:34:16 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ascii.c,v 1.5 2000-01-17 06:24:24 itojun Exp $";
#endif
#include <stdio.h>
#include <sys/types.h>
while (--nshorts >= 0) {
s1 = *cp++;
s2 = *cp++;
- (void)sprintf(hsp, " %02x%02x", s1, s2);
+ (void)snprintf(hsp, sizeof(hsp), " %02x%02x", s1, s2);
hsp += HEXDUMP_HEXSTUFF_PER_SHORT;
*(asp++) = (isgraph(s1) ? s1 : '.');
*(asp++) = (isgraph(s2) ? s2 : '.');
}
if (length & 1) {
s1 = *cp++;
- (void)sprintf(hsp, " %02x", s1);
+ (void)snprintf(hsp, sizeof(hsp), " %02x", s1);
hsp += 3;
*(asp++) = (isgraph(s1) ? s1 : '.');
++i;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.51 1999-11-21 09:36:48 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-atalk.c,v 1.52 2000-01-17 06:24:24 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
if (tp2->addr == i) {
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem();
- (void)sprintf(nambuf, "%s.%d", tp2->name, athost);
+ (void)snprintf(nambuf, sizeof(nambuf), "%s.%d",
+ tp2->name, athost);
tp->name = savestr(nambuf);
return (tp->name);
}
tp->addr = (atnet << 8) | athost;
tp->nxt = newhnamemem();
if (athost != 255)
- (void)sprintf(nambuf, "%d.%d.%d",
+ (void)snprintf(nambuf, sizeof(nambuf), "%d.%d.%d",
atnet >> 8, atnet & 0xff, athost);
else
- (void)sprintf(nambuf, "%d.%d", atnet >> 8, atnet & 0xff);
+ (void)snprintf(nambuf, sizeof(nambuf), "%d.%d", atnet >> 8,
+ atnet & 0xff);
tp->name = savestr(nambuf);
return (tp->name);
static char buf[8];
if (nflag) {
- (void)sprintf(buf, "%d", skt);
+ (void)snprintf(buf, sizeof(buf), "%d", skt);
return (buf);
}
return (tok2str(skt2str, "%d", skt));
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.10 2000-01-09 21:34:17 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-bgp.c,v 1.11 2000-01-17 06:24:24 itojun Exp $";
#endif
#include <sys/param.h>
{
static char buf[20];
if (value < 0 || siz <= value || table[value] == NULL) {
- sprintf(buf, "#%d", value);
+ snprintf(buf, sizeof(buf), "#%d", value);
return buf;
} else
return table[value];
} else
p = NULL;
if (p == NULL) {
- sprintf(buf, "#%d", minor);
+ snprintf(buf, sizeof(buf), "#%d", minor);
return buf;
} else
return p;
((u_char *)&addr)[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff);
}
- sprintf(buf, "%s/%d", getname((char *)&addr), plen);
+ snprintf(buf, buflen, "%s/%d", getname((char *)&addr), plen);
return 1 + (plen + 7) / 8;
}
addr.s6_addr[(plen + 7) / 8 - 1] &=
((0xff00 >> (plen % 8)) & 0xff);
}
- sprintf(buf, "%s/%d", getname6((char *)&addr), plen);
+ snprintf(buf, buflen, "%s/%d", getname6((char *)&addr), plen);
return 1 + (plen + 7) / 8;
}
#endif
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.27 1999-11-21 09:36:50 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-decnet.c,v 1.28 2000-01-17 06:24:24 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
dnnum_string(u_short dnaddr)
{
char *str;
+ size_t siz;
int area = (u_short)(dnaddr & AREAMASK) >> AREASHIFT;
int node = dnaddr & NODEMASK;
- str = (char *)malloc(sizeof("00.0000"));
+ str = (char *)malloc(siz = sizeof("00.0000"));
if (str == NULL)
error("dnnum_string: malloc");
- sprintf(str, "%d.%d", area, node);
+ snprintf(str, siz, "%d.%d", area, node);
return(str);
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.43 1999-11-22 04:28:21 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-icmp.c,v 1.44 2000-01-17 06:24:25 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
case ICMP_UNREACH_PROTOCOL:
TCHECK(dp->icmp_ip.ip_p);
- (void)sprintf(buf, "%s protocol %d unreachable",
- ipaddr_string(&dp->icmp_ip.ip_dst),
- dp->icmp_ip.ip_p);
+ (void)snprintf(buf, sizeof(buf),
+ "%s protocol %d unreachable",
+ ipaddr_string(&dp->icmp_ip.ip_dst),
+ dp->icmp_ip.ip_p);
break;
case ICMP_UNREACH_PORT:
switch (oip->ip_p) {
case IPPROTO_TCP:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s tcp port %s unreachable",
ipaddr_string(&oip->ip_dst),
tcpport_string(dport));
break;
case IPPROTO_UDP:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s udp port %s unreachable",
ipaddr_string(&oip->ip_dst),
udpport_string(dport));
break;
default:
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s protocol %d port %d unreachable",
ipaddr_string(&oip->ip_dst),
oip->ip_p, dport);
mp = (struct mtu_discovery *)&dp->icmp_void;
mtu = EXTRACT_16BITS(&mp->nexthopmtu);
if (mtu)
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag (mtu %d)",
ipaddr_string(&dp->icmp_ip.ip_dst), mtu);
else
- (void)sprintf(buf,
+ (void)snprintf(buf, sizeof(buf),
"%s unreachable - need to frag",
ipaddr_string(&dp->icmp_ip.ip_dst));
}
default:
fmt = tok2str(unreach2str, "#%d %%s unreachable",
dp->icmp_code);
- (void)sprintf(buf, fmt,
+ (void)snprintf(buf, sizeof(buf), fmt,
ipaddr_string(&dp->icmp_ip.ip_dst));
break;
}
TCHECK(dp->icmp_ip.ip_dst);
fmt = tok2str(type2str, "redirect-#%d %%s to net %%s",
dp->icmp_code);
- (void)sprintf(buf, fmt,
+ (void)snprintf(buf, sizeof(buf), fmt,
ipaddr_string(&dp->icmp_ip.ip_dst),
ipaddr_string(&dp->icmp_gwaddr));
break;
ihp = (struct ih_rdiscovery *)&dp->icmp_void;
TCHECK(*ihp);
- (void)strcpy(cp, " lifetime ");
+ (void)strncpy(cp, " lifetime ", sizeof(buf) - (cp - buf));
cp = buf + strlen(buf);
lifetime = EXTRACT_16BITS(&ihp->ird_lifetime);
if (lifetime < 60)
- (void)sprintf(cp, "%u", lifetime);
+ (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u",
+ lifetime);
else if (lifetime < 60 * 60)
- (void)sprintf(cp, "%u:%02u",
+ (void)snprintf(cp, sizeof(buf) - (cp - buf), "%u:%02u",
lifetime / 60, lifetime % 60);
else
- (void)sprintf(cp, "%u:%02u:%02u",
+ (void)snprintf(cp, sizeof(buf) - (cp - buf),
+ "%u:%02u:%02u",
lifetime / 3600,
(lifetime % 3600) / 60,
lifetime % 60);
cp = buf + strlen(buf);
num = ihp->ird_addrnum;
- (void)sprintf(cp, " %d:", num);
+ (void)snprintf(cp, sizeof(buf) - (cp - buf), " %d:", num);
cp = buf + strlen(buf);
size = ihp->ird_addrsiz;
if (size != 2) {
- (void)sprintf(cp, " [size %d]", size);
+ (void)snprintf(cp, sizeof(buf) - (cp - buf),
+ " [size %d]", size);
break;
}
idp = (struct id_rdiscovery *)&dp->icmp_data;
while (num-- > 0) {
TCHECK(*idp);
- (void)sprintf(cp, " {%s %u}",
+ (void)snprintf(cp, sizeof(buf) - (cp - buf), " {%s %u}",
ipaddr_string(&idp->ird_addr),
EXTRACT_32BITS(&idp->ird_pref));
cp = buf + strlen(buf);
break;
default:
- (void)sprintf(buf, "time exceeded-#%d", dp->icmp_code);
+ (void)snprintf(buf, sizeof(buf), "time exceeded-#%d",
+ dp->icmp_code);
break;
}
break;
case ICMP_PARAMPROB:
if (dp->icmp_code)
- (void)sprintf(buf, "parameter problem - code %d",
- dp->icmp_code);
+ (void)snprintf(buf, sizeof(buf),
+ "parameter problem - code %d", dp->icmp_code);
else {
TCHECK(dp->icmp_pptr);
- (void)sprintf(buf, "parameter problem - octet %d",
- dp->icmp_pptr);
+ (void)snprintf(buf, sizeof(buf),
+ "parameter problem - octet %d", dp->icmp_pptr);
}
break;
case ICMP_MASKREPLY:
TCHECK(dp->icmp_mask);
- (void)sprintf(buf, "address mask is 0x%08x",
+ (void)snprintf(buf, sizeof(buf), "address mask is 0x%08x",
(u_int32_t)ntohl(dp->icmp_mask));
break;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.22 1999-11-21 09:36:54 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ipx.c,v 1.23 2000-01-17 06:24:25 itojun Exp $";
#endif
#ifdef HAVE_CONFIG_H
{
static char line[256];
- sprintf(line, "%x.%02x:%02x:%02x:%02x:%02x:%02x",
+ snprintf(line, sizeof(line), "%x.%02x:%02x:%02x:%02x:%02x:%02x",
net, node[0], node[1], node[2], node[3], node[4], node[5]);
return line;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.9 2000-01-07 14:09:02 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-isakmp.c,v 1.10 2000-01-17 06:24:25 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
numstr(int x)
{
static char buf[20];
- sprintf(buf, "#%d", x);
+ snprintf(buf, sizeof(buf), "#%d", x);
return buf;
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.33 1999-12-22 06:27:22 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-ppp.c,v 1.34 2000-01-17 06:24:26 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
case PPP_CHAP: return "CHAP";
#endif
default:
- sprintf(buf, "unknown-0x%04x\n", proto);
+ snprintf(buf, sizeof(buf), "unknown-0x%04x\n", proto);
return buf;
}
}
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.39 1999-12-22 06:27:22 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-snmp.c,v 1.40 2000-01-17 06:24:26 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
};
#define DECODE_ErrorStatus(e) \
( e >= 0 && e < sizeof(ErrorStatus)/sizeof(ErrorStatus[0]) \
- ? ErrorStatus[e] : (sprintf(errbuf, "err=%u", e), errbuf))
+ ? ErrorStatus[e] \
+ : (snprintf(errbuf, sizeof(errbuf), "err=%u", e), errbuf))
/*
* generic-trap values in the SNMP Trap-PDU
};
#define DECODE_GenericTrap(t) \
( t >= 0 && t < sizeof(GenericTrap)/sizeof(GenericTrap[0]) \
- ? GenericTrap[t] : (sprintf(buf, "gt=%d", t), buf))
+ ? GenericTrap[t] \
+ : (snprintf(buf, sizeof(buf), "gt=%d", t), buf))
/*
* ASN.1 type class table
}
d += (elem->data.uns64.low & 0xfffff000);
#if 0 /*is looks illegal, but what is the intention???*/
- sprintf(first, "%.f", d);
+ snprintf(first, sizeof(first), "%.f", d);
#else
- sprintf(first, "%f", d);
+ snprintf(first, sizeof(first), "%f", d);
#endif
- sprintf(last, "%5.5d", elem->data.uns64.low & 0xfff);
+ snprintf(last, sizeof(last), "%5.5d",
+ elem->data.uns64.low & 0xfff);
for (carry = 0, cpf = first+strlen(first)-1, cpl = last+4;
cpl >= last;
cpf--, cpl--) {
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.29 1999-11-21 09:37:02 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-sunrpc.c,v 1.30 2000-01-17 06:24:26 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
return (buf);
rp = getrpcbynumber(prog);
if (rp == NULL)
- (void) sprintf(buf, "#%u", prog);
+ (void) snprintf(buf, sizeof(buf), "#%u", prog);
else
strcpy(buf, rp->r_name);
return (buf);
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.5 2000-01-09 21:34:20 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/print-telnet.c,v 1.6 2000-01-17 06:24:26 itojun Exp $";
#endif
#include <sys/param.h>
x = *sp++; /* option */
length--;
if (x >= 0 && x < NTELOPTS) {
- (void)sprintf(tnet, "%s %s",
- telcmds[i], telopts[x]);
+ (void)snprintf(tnet, sizeof(tnet),
+ "%s %s", telcmds[i], telopts[x]);
} else {
- (void)sprintf(tnet, "%s %#x",
- telcmds[i], x);
+ (void)snprintf(tnet, sizeof(tnet),
+ "%s %#x", telcmds[i], x);
}
break;
default:
- (void)strcpy(tnet, telcmds[i]);
+ (void)snprintf(tnet, sizeof(tnet), "%s",
+ telcmds[i]);
}
if (c == SB) {
c = *sp++;
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.5 2000-01-09 21:34:20 fenner Exp $";
+ "@(#) $Header: /tcpdump/master/tcpdump/smbutil.c,v 1.6 2000-01-17 06:24:27 itojun Exp $";
#endif
#include <sys/param.h>
for (j=0;err[j].name;j++)
if (num == err[j].code)
{
- sprintf(ret,"%s - %s (%s)",err_classes[i].class,
+ snprintf(ret,sizeof(ret),"%s - %s (%s)",err_classes[i].class,
err[j].name,err[j].message);
return ret;
}
}
- sprintf(ret,"%s - %d",err_classes[i].class,num);
+ snprintf(ret,sizeof(ret),"%s - %d",err_classes[i].class,num);
return ret;
}
- sprintf(ret,"ERROR: Unknown error (%d,%d)",class,num);
+ snprintf(ret,sizeof(ret),"ERROR: Unknown error (%d,%d)",class,num);
return(ret);
}
"@(#) Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997\n\
The Regents of the University of California. All rights reserved.\n";
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.141 2000-01-15 07:42:32 itojun Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/tcpdump.c,v 1.142 2000-01-17 06:24:27 itojun Exp $ (LBL)";
#endif
/*
else
program_name = argv[0];
- if (abort_on_misalignment(ebuf) < 0)
+ if (abort_on_misalignment(ebuf, sizeof(ebuf)) < 0)
error("%s", ebuf);
#ifdef LIBSMI
#ifndef lint
static const char rcsid[] =
- "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.62 1999-12-15 06:58:03 fenner Exp $ (LBL)";
+ "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.63 2000-01-17 06:24:27 itojun Exp $ (LBL)";
#endif
#ifdef HAVE_CONFIG_H
}
if (fmt == NULL)
fmt = "#%d";
- (void)sprintf(buf, fmt, v);
+ (void)snprintf(buf, sizeof(buf), fmt, v);
return (buf);
}