- rename variable
- use strlcpy
- const'fy

Obtained from:	KAME
This commit is contained in:
Hajimu UMEMOTO 2003-10-17 11:43:44 +00:00
parent 77879b47b7
commit 2f4c5de968
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=121155
2 changed files with 56 additions and 50 deletions

View File

@ -53,7 +53,7 @@
#include "libpfkey.h" #include "libpfkey.h"
void Usage __P((void)); void usage __P((void));
int main __P((int, char **)); int main __P((int, char **));
int get_supported __P((void)); int get_supported __P((void));
void sendkeyshort __P((u_int)); void sendkeyshort __P((u_int));
@ -94,9 +94,9 @@ extern int lineno;
extern int parse __P((FILE **)); extern int parse __P((FILE **));
void void
Usage() usage()
{ {
printf("Usage:\t%s [-dv] -c\n", pname); printf("usage:\t%s [-dv] -c\n", pname);
printf("\t%s [-dv] -f (file)\n", pname); printf("\t%s [-dv] -f (file)\n", pname);
printf("\t%s [-Padlv] -D\n", pname); printf("\t%s [-Padlv] -D\n", pname);
printf("\t%s [-Pdv] -F\n", pname); printf("\t%s [-Pdv] -F\n", pname);
@ -115,7 +115,10 @@ main(ac, av)
pname = *av; pname = *av;
if (ac == 1) Usage(); if (ac == 1) {
usage();
/* NOTREACHED */
}
thiszone = gmt2local(0); thiszone = gmt2local(0);
@ -161,7 +164,7 @@ main(ac, av)
f_verbose = 1; f_verbose = 1;
break; break;
default: default:
Usage(); usage();
/*NOTREACHED*/ /*NOTREACHED*/
} }
} }
@ -186,7 +189,7 @@ main(ac, av)
promisc(); promisc();
/*NOTREACHED*/ /*NOTREACHED*/
default: default:
Usage(); usage();
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -243,7 +246,7 @@ promisc()
{ {
struct sadb_msg *m_msg = (struct sadb_msg *)m_buf; struct sadb_msg *m_msg = (struct sadb_msg *)m_buf;
u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */ u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
int so, len; int so, l;
m_len = sizeof(struct sadb_msg); m_len = sizeof(struct sadb_msg);
@ -261,7 +264,7 @@ promisc()
/*NOTREACHED*/ /*NOTREACHED*/
} }
if ((len = send(so, m_buf, m_len, 0)) < 0) { if ((l = send(so, m_buf, m_len, 0)) < 0) {
err(1, "send"); err(1, "send");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -269,16 +272,16 @@ promisc()
while (1) { while (1) {
struct sadb_msg *base; struct sadb_msg *base;
if ((len = recv(so, rbuf, sizeof(*base), MSG_PEEK)) < 0) { if ((l = recv(so, rbuf, sizeof(*base), MSG_PEEK)) < 0) {
err(1, "recv"); err(1, "recv");
/*NOTREACHED*/ /*NOTREACHED*/
} }
if (len != sizeof(*base)) if (l != sizeof(*base))
continue; continue;
base = (struct sadb_msg *)rbuf; base = (struct sadb_msg *)rbuf;
if ((len = recv(so, rbuf, PFKEY_UNUNIT64(base->sadb_msg_len), if ((l = recv(so, rbuf, PFKEY_UNUNIT64(base->sadb_msg_len),
0)) < 0) { 0)) < 0) {
err(1, "recv"); err(1, "recv");
/*NOTREACHED*/ /*NOTREACHED*/
@ -286,19 +289,19 @@ promisc()
printdate(); printdate();
if (f_hexdump) { if (f_hexdump) {
int i; int i;
for (i = 0; i < len; i++) { for (i = 0; i < l; i++) {
if (i % 16 == 0) if (i % 16 == 0)
printf("%08x: ", i); printf("%08x: ", i);
printf("%02x ", rbuf[i] & 0xff); printf("%02x ", rbuf[i] & 0xff);
if (i % 16 == 15) if (i % 16 == 15)
printf("\n"); printf("\n");
} }
if (len % 16) if (l % 16)
printf("\n"); printf("\n");
} }
/* adjust base pointer for promisc mode */ /* adjust base pointer for promisc mode */
if (base->sadb_msg_type == SADB_X_PROMISC) { if (base->sadb_msg_type == SADB_X_PROMISC) {
if (sizeof(*base) < len) if (sizeof(*base) < l)
base++; base++;
else else
base = NULL; base = NULL;
@ -317,7 +320,7 @@ sendkeymsg()
int so; int so;
u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */ u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
int len; int l;
struct sadb_msg *msg; struct sadb_msg *msg;
if ((so = pfkey_open()) < 0) { if ((so = pfkey_open()) < 0) {
@ -343,19 +346,19 @@ sendkeymsg()
printf("\n"); printf("\n");
} }
if ((len = send(so, m_buf, m_len, 0)) < 0) { if ((l = send(so, m_buf, m_len, 0)) < 0) {
perror("send"); perror("send");
goto end; goto end;
} }
msg = (struct sadb_msg *)rbuf; msg = (struct sadb_msg *)rbuf;
do { do {
if ((len = recv(so, rbuf, sizeof(rbuf), 0)) < 0) { if ((l = recv(so, rbuf, sizeof(rbuf), 0)) < 0) {
perror("recv"); perror("recv");
goto end; goto end;
} }
if (PFKEY_UNUNIT64(msg->sadb_msg_len) != len) { if (PFKEY_UNUNIT64(msg->sadb_msg_len) != l) {
warnx("invalid keymsg length"); warnx("invalid keymsg length");
break; break;
} }
@ -364,7 +367,7 @@ sendkeymsg()
kdebug_sadb((struct sadb_msg *)rbuf); kdebug_sadb((struct sadb_msg *)rbuf);
printf("\n"); printf("\n");
} }
if (postproc(msg, len) < 0) if (postproc(msg, l) < 0)
break; break;
} while (msg->sadb_msg_errno || msg->sadb_msg_seq); } while (msg->sadb_msg_errno || msg->sadb_msg_seq);
@ -387,7 +390,7 @@ postproc(msg, len)
if (msg->sadb_msg_errno != 0) { if (msg->sadb_msg_errno != 0) {
char inf[80]; char inf[80];
char *errmsg = NULL; const char *errmsg = NULL;
if (f_mode == MODE_SCRIPT) if (f_mode == MODE_SCRIPT)
snprintf(inf, sizeof(inf), "The result of line %d: ", lineno); snprintf(inf, sizeof(inf), "The result of line %d: ", lineno);
@ -462,13 +465,13 @@ postproc(msg, len)
} }
/*------------------------------------------------------------*/ /*------------------------------------------------------------*/
static char *satype[] = { static const char *satype[] = {
NULL, NULL, "ah", "esp" NULL, NULL, "ah", "esp"
}; };
static char *sastate[] = { static const char *sastate[] = {
"L", "M", "D", "d" "L", "M", "D", "d"
}; };
static char *ipproto[] = { static const char *ipproto[] = {
/*0*/ "ip", "icmp", "igmp", "ggp", "ip4", /*0*/ "ip", "icmp", "igmp", "ggp", "ip4",
NULL, "tcp", NULL, "egp", NULL, NULL, "tcp", NULL, "egp", NULL,
/*10*/ NULL, NULL, NULL, NULL, NULL, /*10*/ NULL, NULL, NULL, NULL, NULL,
@ -538,14 +541,14 @@ shortdump(msg)
else else
t = (u_long)(cur - ltc->sadb_lifetime_addtime); t = (u_long)(cur - ltc->sadb_lifetime_addtime);
if (t >= 1000) if (t >= 1000)
strcpy(buf, " big/"); strlcpy(buf, " big/", sizeof(buf));
else else
snprintf(buf, sizeof(buf), " %3lu/", (u_long)t); snprintf(buf, sizeof(buf), " %3lu/", (u_long)t);
printf("%s", buf); printf("%s", buf);
t = (u_long)lth->sadb_lifetime_addtime; t = (u_long)lth->sadb_lifetime_addtime;
if (t >= 1000) if (t >= 1000)
strcpy(buf, "big"); strlcpy(buf, "big", sizeof(buf));
else else
snprintf(buf, sizeof(buf), "%-3lu", (u_long)t); snprintf(buf, sizeof(buf), "%-3lu", (u_long)t);
printf("%s", buf); printf("%s", buf);

View File

@ -53,7 +53,7 @@
#include "libpfkey.h" #include "libpfkey.h"
void Usage __P((void)); void usage __P((void));
int main __P((int, char **)); int main __P((int, char **));
int get_supported __P((void)); int get_supported __P((void));
void sendkeyshort __P((u_int)); void sendkeyshort __P((u_int));
@ -94,9 +94,9 @@ extern int lineno;
extern int parse __P((FILE **)); extern int parse __P((FILE **));
void void
Usage() usage()
{ {
printf("Usage:\t%s [-dv] -c\n", pname); printf("usage:\t%s [-dv] -c\n", pname);
printf("\t%s [-dv] -f (file)\n", pname); printf("\t%s [-dv] -f (file)\n", pname);
printf("\t%s [-Padlv] -D\n", pname); printf("\t%s [-Padlv] -D\n", pname);
printf("\t%s [-Pdv] -F\n", pname); printf("\t%s [-Pdv] -F\n", pname);
@ -115,7 +115,10 @@ main(ac, av)
pname = *av; pname = *av;
if (ac == 1) Usage(); if (ac == 1) {
usage();
/* NOTREACHED */
}
thiszone = gmt2local(0); thiszone = gmt2local(0);
@ -161,7 +164,7 @@ main(ac, av)
f_verbose = 1; f_verbose = 1;
break; break;
default: default:
Usage(); usage();
/*NOTREACHED*/ /*NOTREACHED*/
} }
} }
@ -186,7 +189,7 @@ main(ac, av)
promisc(); promisc();
/*NOTREACHED*/ /*NOTREACHED*/
default: default:
Usage(); usage();
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -243,7 +246,7 @@ promisc()
{ {
struct sadb_msg *m_msg = (struct sadb_msg *)m_buf; struct sadb_msg *m_msg = (struct sadb_msg *)m_buf;
u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */ u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
int so, len; int so, l;
m_len = sizeof(struct sadb_msg); m_len = sizeof(struct sadb_msg);
@ -261,7 +264,7 @@ promisc()
/*NOTREACHED*/ /*NOTREACHED*/
} }
if ((len = send(so, m_buf, m_len, 0)) < 0) { if ((l = send(so, m_buf, m_len, 0)) < 0) {
err(1, "send"); err(1, "send");
/*NOTREACHED*/ /*NOTREACHED*/
} }
@ -269,16 +272,16 @@ promisc()
while (1) { while (1) {
struct sadb_msg *base; struct sadb_msg *base;
if ((len = recv(so, rbuf, sizeof(*base), MSG_PEEK)) < 0) { if ((l = recv(so, rbuf, sizeof(*base), MSG_PEEK)) < 0) {
err(1, "recv"); err(1, "recv");
/*NOTREACHED*/ /*NOTREACHED*/
} }
if (len != sizeof(*base)) if (l != sizeof(*base))
continue; continue;
base = (struct sadb_msg *)rbuf; base = (struct sadb_msg *)rbuf;
if ((len = recv(so, rbuf, PFKEY_UNUNIT64(base->sadb_msg_len), if ((l = recv(so, rbuf, PFKEY_UNUNIT64(base->sadb_msg_len),
0)) < 0) { 0)) < 0) {
err(1, "recv"); err(1, "recv");
/*NOTREACHED*/ /*NOTREACHED*/
@ -286,19 +289,19 @@ promisc()
printdate(); printdate();
if (f_hexdump) { if (f_hexdump) {
int i; int i;
for (i = 0; i < len; i++) { for (i = 0; i < l; i++) {
if (i % 16 == 0) if (i % 16 == 0)
printf("%08x: ", i); printf("%08x: ", i);
printf("%02x ", rbuf[i] & 0xff); printf("%02x ", rbuf[i] & 0xff);
if (i % 16 == 15) if (i % 16 == 15)
printf("\n"); printf("\n");
} }
if (len % 16) if (l % 16)
printf("\n"); printf("\n");
} }
/* adjust base pointer for promisc mode */ /* adjust base pointer for promisc mode */
if (base->sadb_msg_type == SADB_X_PROMISC) { if (base->sadb_msg_type == SADB_X_PROMISC) {
if (sizeof(*base) < len) if (sizeof(*base) < l)
base++; base++;
else else
base = NULL; base = NULL;
@ -317,7 +320,7 @@ sendkeymsg()
int so; int so;
u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */ u_char rbuf[1024 * 32]; /* XXX: Enough ? Should I do MSG_PEEK ? */
int len; int l;
struct sadb_msg *msg; struct sadb_msg *msg;
if ((so = pfkey_open()) < 0) { if ((so = pfkey_open()) < 0) {
@ -343,19 +346,19 @@ sendkeymsg()
printf("\n"); printf("\n");
} }
if ((len = send(so, m_buf, m_len, 0)) < 0) { if ((l = send(so, m_buf, m_len, 0)) < 0) {
perror("send"); perror("send");
goto end; goto end;
} }
msg = (struct sadb_msg *)rbuf; msg = (struct sadb_msg *)rbuf;
do { do {
if ((len = recv(so, rbuf, sizeof(rbuf), 0)) < 0) { if ((l = recv(so, rbuf, sizeof(rbuf), 0)) < 0) {
perror("recv"); perror("recv");
goto end; goto end;
} }
if (PFKEY_UNUNIT64(msg->sadb_msg_len) != len) { if (PFKEY_UNUNIT64(msg->sadb_msg_len) != l) {
warnx("invalid keymsg length"); warnx("invalid keymsg length");
break; break;
} }
@ -364,7 +367,7 @@ sendkeymsg()
kdebug_sadb((struct sadb_msg *)rbuf); kdebug_sadb((struct sadb_msg *)rbuf);
printf("\n"); printf("\n");
} }
if (postproc(msg, len) < 0) if (postproc(msg, l) < 0)
break; break;
} while (msg->sadb_msg_errno || msg->sadb_msg_seq); } while (msg->sadb_msg_errno || msg->sadb_msg_seq);
@ -387,7 +390,7 @@ postproc(msg, len)
if (msg->sadb_msg_errno != 0) { if (msg->sadb_msg_errno != 0) {
char inf[80]; char inf[80];
char *errmsg = NULL; const char *errmsg = NULL;
if (f_mode == MODE_SCRIPT) if (f_mode == MODE_SCRIPT)
snprintf(inf, sizeof(inf), "The result of line %d: ", lineno); snprintf(inf, sizeof(inf), "The result of line %d: ", lineno);
@ -462,13 +465,13 @@ postproc(msg, len)
} }
/*------------------------------------------------------------*/ /*------------------------------------------------------------*/
static char *satype[] = { static const char *satype[] = {
NULL, NULL, "ah", "esp" NULL, NULL, "ah", "esp"
}; };
static char *sastate[] = { static const char *sastate[] = {
"L", "M", "D", "d" "L", "M", "D", "d"
}; };
static char *ipproto[] = { static const char *ipproto[] = {
/*0*/ "ip", "icmp", "igmp", "ggp", "ip4", /*0*/ "ip", "icmp", "igmp", "ggp", "ip4",
NULL, "tcp", NULL, "egp", NULL, NULL, "tcp", NULL, "egp", NULL,
/*10*/ NULL, NULL, NULL, NULL, NULL, /*10*/ NULL, NULL, NULL, NULL, NULL,
@ -538,14 +541,14 @@ shortdump(msg)
else else
t = (u_long)(cur - ltc->sadb_lifetime_addtime); t = (u_long)(cur - ltc->sadb_lifetime_addtime);
if (t >= 1000) if (t >= 1000)
strcpy(buf, " big/"); strlcpy(buf, " big/", sizeof(buf));
else else
snprintf(buf, sizeof(buf), " %3lu/", (u_long)t); snprintf(buf, sizeof(buf), " %3lu/", (u_long)t);
printf("%s", buf); printf("%s", buf);
t = (u_long)lth->sadb_lifetime_addtime; t = (u_long)lth->sadb_lifetime_addtime;
if (t >= 1000) if (t >= 1000)
strcpy(buf, "big"); strlcpy(buf, "big", sizeof(buf));
else else
snprintf(buf, sizeof(buf), "%-3lu", (u_long)t); snprintf(buf, sizeof(buf), "%-3lu", (u_long)t);
printf("%s", buf); printf("%s", buf);