summaryrefslogtreecommitdiffstats
path: root/usr.sbin/mopd
diff options
context:
space:
mode:
authormaja <maja@openbsd.org>2006-04-17 13:17:07 +0000
committermaja <maja@openbsd.org>2006-04-17 13:17:07 +0000
commit3cd9cd145e767344467ea5012bc216df08415188 (patch)
treee57ee1ede2eb8f04ead17ec1317e264de3eece47 /usr.sbin/mopd
parentplug memory leak; OK ray@. (diff)
downloadwireguard-openbsd-3cd9cd145e767344467ea5012bc216df08415188.tar.xz
wireguard-openbsd-3cd9cd145e767344467ea5012bc216df08415188.zip
Make the code lint friendly. -moj
Diffstat (limited to 'usr.sbin/mopd')
-rw-r--r--usr.sbin/mopd/common/cmp.c6
-rw-r--r--usr.sbin/mopd/common/dl.c102
-rw-r--r--usr.sbin/mopd/common/get.c73
-rw-r--r--usr.sbin/mopd/common/mopdef.c6
-rw-r--r--usr.sbin/mopd/common/nma.c6
-rw-r--r--usr.sbin/mopd/common/put.c118
-rw-r--r--usr.sbin/mopd/common/rc.c99
7 files changed, 193 insertions, 217 deletions
diff --git a/usr.sbin/mopd/common/cmp.c b/usr.sbin/mopd/common/cmp.c
index 7f504637b45..6942cb29dd5 100644
--- a/usr.sbin/mopd/common/cmp.c
+++ b/usr.sbin/mopd/common/cmp.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: cmp.c,v 1.7 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: cmp.c,v 1.8 2006/04/17 13:17:07 maja Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: cmp.c,v 1.7 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: cmp.c,v 1.8 2006/04/17 13:17:07 maja Exp $";
#endif
#include "os.h"
diff --git a/usr.sbin/mopd/common/dl.c b/usr.sbin/mopd/common/dl.c
index ee283043913..b9562916fb4 100644
--- a/usr.sbin/mopd/common/dl.c
+++ b/usr.sbin/mopd/common/dl.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: dl.c,v 1.6 2006/04/15 11:55:48 maja Exp $ */
+/* $OpenBSD: dl.c,v 1.7 2006/04/17 13:17:07 maja Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: dl.c,v 1.6 2006/04/15 11:55:48 maja Exp $";
+ "$OpenBSD: dl.c,v 1.7 2006/04/17 13:17:07 maja Exp $";
#endif
#include "os.h"
@@ -37,7 +37,7 @@ static const char rcsid[] =
void
mopDumpDL(FILE *fd, u_char *pkt, int trans)
{
- int i, index = 0;
+ int i, idx = 0;
long tmpl;
u_char tmpc, c, program[17], code, *ucp;
u_short len, tmps, moplen;
@@ -46,27 +46,26 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
switch (trans) {
case TRANS_8023:
- index = 22;
+ idx = 22;
moplen = len - 8;
break;
default:
- index = 16;
+ idx = 16;
moplen = len;
}
- code = mopGetChar(pkt, &index);
+ code = mopGetChar(pkt, &idx);
switch (code) {
case MOP_K_CODE_MLT:
- tmpc = mopGetChar(pkt, &index); /* Load Number */
+ tmpc = mopGetChar(pkt, &idx); /* Load Number */
fprintf(fd, "Load Number : %02x\n", tmpc);
if (moplen > 6) {
- tmpl = mopGetLong(pkt, &index);/* Load Address */
+ tmpl = mopGetLong(pkt, &idx);/* Load Address */
fprintf(fd, "Load Address : %08lx\n", tmpl);
}
if (moplen > 10) {
-#ifndef SHORT_PRINT
for (i = 0; i < (moplen - 10); i++) {
if ((i % 16) == 0) {
if ((i / 16) == 0)
@@ -78,33 +77,29 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
" ");
}
- fprintf(fd, "%02x ", mopGetChar(pkt, &index));
+ fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
if ((i % 16) == 15)
fprintf(fd, "\n");
}
if ((i % 16) != 15)
fprintf(fd, "\n");
-#else
- index = index + moplen - 10;
-#endif
}
- tmpl = mopGetLong(pkt, &index); /* Load Address */
+ tmpl = mopGetLong(pkt, &idx); /* Load Address */
fprintf(fd, "Xfer Address : %08lx\n", tmpl);
break;
case MOP_K_CODE_DCM:
/* Empty Message */
break;
case MOP_K_CODE_MLD:
- tmpc = mopGetChar(pkt, &index); /* Load Number */
+ tmpc = mopGetChar(pkt, &idx); /* Load Number */
fprintf(fd, "Load Number : %02x\n", tmpc);
- tmpl = mopGetLong(pkt, &index); /* Load Address */
+ tmpl = mopGetLong(pkt, &idx); /* Load Address */
fprintf(fd, "Load Address : %08lx\n", tmpl);
if (moplen > 6) {
-#ifndef SHORT_PRINT
for (i = 0; i < (moplen - 6); i++) {
if ((i % 16) == 0)
if ((i / 16) == 0)
@@ -115,65 +110,62 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
fprintf(fd,
" ");
- fprintf(fd, "%02x ", mopGetChar(pkt, &index));
+ fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
if ((i % 16) == 15)
fprintf(fd, "\n");
}
if ((i % 16) != 15)
fprintf(fd, "\n");
-#else
- index = index + moplen - 6;
-#endif
}
break;
case MOP_K_CODE_ASV:
/* Empty Message */
break;
case MOP_K_CODE_RMD:
- tmpl = mopGetLong(pkt, &index); /* Memory Address */
+ tmpl = mopGetLong(pkt, &idx); /* Memory Address */
fprintf(fd, "Mem Address : %08lx\n", tmpl);
- tmps = mopGetShort(pkt, &index); /* Count */
+ tmps = mopGetShort(pkt, &idx); /* Count */
fprintf(fd, "Count : %04x (%d)\n", tmps, tmps);
break;
case MOP_K_CODE_RPR:
- tmpc = mopGetChar(pkt, &index); /* Device Type */
+ tmpc = mopGetChar(pkt, &idx); /* Device Type */
fprintf(fd, "Device Type : %02x ", tmpc);
mopPrintDevice(fd, tmpc);
fprintf(fd, "\n");
- tmpc = mopGetChar(pkt, &index); /* Format Version */
+ tmpc = mopGetChar(pkt, &idx); /* Format Version */
fprintf(fd, "Format : %02x\n", tmpc);
- tmpc = mopGetChar(pkt, &index); /* Program Type */
+ tmpc = mopGetChar(pkt, &idx); /* Program Type */
fprintf(fd, "Program Type : %02x ", tmpc);
mopPrintPGTY(fd, tmpc);
fprintf(fd, "\n");
program[0] = 0;
- tmpc = mopGetChar(pkt, &index); /* Software ID Len */
+ tmpc = mopGetChar(pkt, &idx); /* Software ID Len */
for (i = 0; i < tmpc; i++) {
- program[i] = mopGetChar(pkt, &index);
+ program[i] = mopGetChar(pkt, &idx);
program[i + 1] = '\0';
}
fprintf(fd, "Software : %02x '%s'\n", tmpc, program);
- tmpc = mopGetChar(pkt, &index); /* Processor */
+ tmpc = mopGetChar(pkt, &idx); /* Processor */
fprintf(fd, "Processor : %02x ", tmpc);
mopPrintBPTY(fd, tmpc);
fprintf(fd, "\n");
- mopPrintInfo(fd, pkt, &index, moplen, code, trans);
+ mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
break;
case MOP_K_CODE_RML:
- tmpc = mopGetChar(pkt, &index); /* Load Number */
+ tmpc = mopGetChar(pkt, &idx); /* Load Number */
fprintf(fd, "Load Number : %02x\n", tmpc);
- tmpc = mopGetChar(pkt, &index); /* Error */
- (void)fprintf(fd, "Error : %02x (", tmpc);
+ tmpc = mopGetChar(pkt, &idx); /* Error */
+ fprintf(fd, "Error : %02x (", tmpc);
if ((tmpc == 0))
fprintf(fd, "no error)\n");
else
@@ -182,30 +174,29 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
break;
case MOP_K_CODE_RDS:
- tmpc = mopGetChar(pkt, &index); /* Device Type */
+ tmpc = mopGetChar(pkt, &idx); /* Device Type */
fprintf(fd, "Device Type : %02x ", tmpc);
mopPrintDevice(fd, tmpc);
fprintf(fd, "\n");
- tmpc = mopGetChar(pkt, &index); /* Format Version */
+ tmpc = mopGetChar(pkt, &idx); /* Format Version */
fprintf(fd, "Format : %02x\n", tmpc);
- tmpl = mopGetLong(pkt, &index); /* Memory Size */
+ tmpl = mopGetLong(pkt, &idx); /* Memory Size */
fprintf(fd, "Memory Size : %08lx\n", tmpl);
- tmpc = mopGetChar(pkt, &index); /* Bits */
+ tmpc = mopGetChar(pkt, &idx); /* Bits */
fprintf(fd, "Bits : %02x\n", tmpc);
- mopPrintInfo(fd, pkt, &index, moplen, code, trans);
+ mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
break;
case MOP_K_CODE_MDD:
- tmpl = mopGetLong(pkt, &index); /* Memory Address */
+ tmpl = mopGetLong(pkt, &idx); /* Memory Address */
fprintf(fd, "Mem Address : %08lx\n", tmpl);
if (moplen > 5) {
-#ifndef SHORT_PRINT
for (i = 0; i < (moplen - 5); i++) {
if ((i % 16) == 0) {
if ((i / 16) == 0)
@@ -216,57 +207,54 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
fprintf(fd,
" ");
}
- fprintf(fd, "%02x ", mopGetChar(pkt, &index));
+ fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
if ((i % 16) == 15)
fprintf(fd, "\n");
}
if ((i % 16) != 15)
fprintf(fd, "\n");
-#else
- index = index + moplen - 5;
-#endif
}
break;
case MOP_K_CODE_PLT:
- tmpc = mopGetChar(pkt, &index); /* Load Number */
+ tmpc = mopGetChar(pkt, &idx); /* Load Number */
fprintf(fd, "Load Number : %02x\n", tmpc);
- tmpc = mopGetChar(pkt, &index); /* Parameter Type */
+ tmpc = mopGetChar(pkt, &idx); /* Parameter Type */
while (tmpc != MOP_K_PLTP_END) {
- c = mopGetChar(pkt, &index); /* Parameter Length */
+ c = mopGetChar(pkt, &idx); /* Parameter Length */
switch (tmpc) {
case MOP_K_PLTP_TSN: /* Target Name */
fprintf(fd, "Target Name : %02x '", c);
for (i = 0; i < c; i++)
fprintf(fd, "%c",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "'\n");
break;
case MOP_K_PLTP_TSA: /* Target Address */
fprintf(fd, "Target Addr : %02x ", c);
for (i = 0; i < c; i++)
fprintf(fd, "%02x ",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "\n");
break;
case MOP_K_PLTP_HSN: /* Host Name */
fprintf(fd, "Host Name : %02x '", c);
for (i = 0; i < c; i++)
fprintf(fd, "%c",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "'\n");
break;
case MOP_K_PLTP_HSA: /* Host Address */
fprintf(fd, "Host Addr : %02x ", c);
for (i = 0; i < c; i++)
fprintf(fd, "%02x ",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "\n");
break;
case MOP_K_PLTP_HST: /* Host Time */
- ucp = pkt + index; index = index + 10;
+ ucp = pkt + idx; idx = idx + 10;
fprintf(fd, "Host Time : ");
mopPrintTime(fd, ucp);
fprintf(fd, "\n");
@@ -274,16 +262,14 @@ mopDumpDL(FILE *fd, u_char *pkt, int trans)
default:
break;
}
- tmpc = mopGetChar(pkt, &index); /* Parameter Type */
+ tmpc = mopGetChar(pkt, &idx); /* Parameter Type */
}
- tmpl = mopGetLong(pkt, &index); /* Transfer Address */
- (void)fprintf(fd, "Transfer Addr: %08lx\n", tmpl);
+ tmpl = mopGetLong(pkt, &idx); /* Transfer Address */
+ fprintf(fd, "Transfer Addr: %08lx\n", tmpl);
break;
default:
break;
}
}
-
-
diff --git a/usr.sbin/mopd/common/get.c b/usr.sbin/mopd/common/get.c
index 55f1d75f50d..c3398fc46cb 100644
--- a/usr.sbin/mopd/common/get.c
+++ b/usr.sbin/mopd/common/get.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: get.c,v 1.6 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: get.c,v 1.7 2006/04/17 13:17:07 maja Exp $ */
/*
- * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
+ * Copyright (c) 1993-2006 Mats O Jansson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,63 +24,73 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: get.c,v 1.6 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: get.c,v 1.7 2006/04/17 13:17:07 maja Exp $";
#endif
#include <sys/types.h>
#include "common/mopdef.h"
u_char
-mopGetChar(u_char *pkt, int *index)
+mopGetChar(u_char *pkt, int *idx)
{
u_char ret;
- ret = pkt[*index];
- *index = *index + 1;
+ ret = pkt[*idx];
+ *idx = *idx + 1;
return (ret);
}
u_short
-mopGetShort(u_char *pkt, int *index)
+mopGetShort(u_char *pkt, int *idx)
{
u_short ret;
- ret = pkt[*index] + pkt[*index+1]*256;
- *index = *index + 2;
+ ret = pkt[*idx] + pkt[*idx+1]*256;
+ *idx = *idx + 2;
+ return (ret);
+}
+
+u_short
+mopGetNShort(u_char *pkt, int *idx)
+{
+ u_short ret;
+
+ ret = pkt[*idx]*256 + pkt[*idx+1];
+ *idx = *idx + 2;
return (ret);
}
u_long
-mopGetLong(u_char *pkt, int *index)
+mopGetLong(u_char *pkt, int *idx)
{
u_long ret;
- ret = pkt[*index] + pkt[*index+1]*0x100 + pkt[*index+2]*0x10000 +
- pkt[*index+3]*0x1000000;
- *index = *index + 4;
+ ret = pkt[*idx] + pkt[*idx+1]*0x100 + pkt[*idx+2]*0x10000 +
+ pkt[*idx+3]*0x1000000;
+ *idx = *idx + 4;
return (ret);
}
void
-mopGetMulti(u_char *pkt, int *index, u_char *dest, int size)
+mopGetMulti(u_char *pkt, int *idx, u_char *dest, int size)
{
int i;
for (i = 0; i < size; i++)
- dest[i] = pkt[*index+i];
- *index = *index + size;
+ dest[i] = pkt[*idx+i];
+ *idx = *idx + size;
}
int
mopGetTrans(u_char *pkt, int trans)
{
- u_short *ptype;
+ u_short ptype;
if (trans == 0) {
- ptype = (u_short *)(pkt+12);
- if (ntohs(*ptype) < 1600)
+ ptype = pkt[12]*256 + pkt[13];
+ if (ptype < 1600)
trans = TRANS_8023;
else
trans = TRANS_ETHER;
@@ -89,25 +99,22 @@ mopGetTrans(u_char *pkt, int trans)
}
void
-mopGetHeader(u_char *pkt, int *index, u_char **dst, u_char **src,
+mopGetHeader(u_char *pkt, int *idx, u_char **dst, u_char **src,
u_short *proto, int *len, int trans)
{
*dst = pkt;
*src = pkt + 6;
- *index = *index + 12;
+ *idx = *idx + 12;
switch (trans) {
case TRANS_ETHER:
- *proto = (u_short)(pkt[*index] * 256 + pkt[*index + 1]);
- *index = *index + 2;
- *len = (int)(pkt[*index + 1] * 256 + pkt[*index]);
- *index = *index + 2;
+ *proto = mopGetNShort(pkt, idx);
+ *len = (int)mopGetShort(pkt, idx);
break;
case TRANS_8023:
- *len = (int)(pkt[*index] * 256 + pkt[*index + 1]);
- *index = *index + 8;
- *proto = (u_short)(pkt[*index] * 256 + pkt[*index + 1]);
- *index = *index + 2;
+ *len = (int)mopGetNShort(pkt, idx);
+ *idx = *idx + 6;
+ *proto = mopGetNShort(pkt, idx);
break;
}
}
@@ -117,11 +124,9 @@ mopGetLength(u_char *pkt, int trans)
{
switch (trans) {
case TRANS_ETHER:
- return (pkt[15] * 256 + pkt[14]);
- break;
+ return (pkt[14] + pkt[15]*256);
case TRANS_8023:
- return (pkt[12] * 256 + pkt[13]);
- break;
+ return (pkt[12]*256 + pkt[13]);
}
return (0);
}
diff --git a/usr.sbin/mopd/common/mopdef.c b/usr.sbin/mopd/common/mopdef.c
index f54855ed827..d6850597428 100644
--- a/usr.sbin/mopd/common/mopdef.c
+++ b/usr.sbin/mopd/common/mopdef.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mopdef.c,v 1.6 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: mopdef.c,v 1.7 2006/04/17 13:17:07 maja Exp $ */
/*
* Copyright (c) 1995 Mats O Jansson. All rights reserved.
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: mopdef.c,v 1.6 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: mopdef.c,v 1.7 2006/04/17 13:17:07 maja Exp $";
#endif
#include <sys/types.h>
diff --git a/usr.sbin/mopd/common/nma.c b/usr.sbin/mopd/common/nma.c
index 4b9359b84b7..2e89bce5026 100644
--- a/usr.sbin/mopd/common/nma.c
+++ b/usr.sbin/mopd/common/nma.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: nma.c,v 1.5 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: nma.c,v 1.6 2006/04/17 13:17:07 maja Exp $ */
/*
* Copyright (c) 1995 Mats O Jansson. All rights reserved.
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: nma.c,v 1.5 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: nma.c,v 1.6 2006/04/17 13:17:07 maja Exp $";
#endif
#include <stddef.h>
diff --git a/usr.sbin/mopd/common/put.c b/usr.sbin/mopd/common/put.c
index 01431278008..693fe3e646a 100644
--- a/usr.sbin/mopd/common/put.c
+++ b/usr.sbin/mopd/common/put.c
@@ -1,7 +1,7 @@
-/* $OpenBSD: put.c,v 1.6 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: put.c,v 1.7 2006/04/17 13:17:07 maja Exp $ */
/*
- * Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
+ * Copyright (c) 1993-2006 Mats O Jansson. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: put.c,v 1.6 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: put.c,v 1.7 2006/04/17 13:17:07 maja Exp $";
#endif
#include <stddef.h>
@@ -35,48 +35,52 @@ static const char rcsid[] =
#include "common/mopdef.h"
void
-mopPutChar(u_char *pkt, int *index, u_char value)
+mopPutChar(u_char *pkt, int *idx, u_char value)
{
- pkt[*index] = value;
- (*index)++;
+ pkt[*idx] = value;
+ (*idx)++;
}
void
-mopPutShort(u_char *pkt, int *index, u_short value)
+mopPutShort(u_char *pkt, int *idx, u_short value)
{
- int i;
+ pkt[*idx] = value % 256;
+ pkt[*idx+1] = value / 256;
+ *idx += 2;
+}
- for (i = 0; i < 2; i++) {
- pkt[*index + i] = value % 256;
- value /= 256;
- }
- *index += 2;
+void
+mopPutNShort(u_char *pkt, int *idx, u_short value)
+{
+ pkt[*idx] = value / 256;
+ pkt[*idx+1] = value % 256;
+ *idx += 2;
}
void
-mopPutLong(u_char *pkt, int *index, u_long value)
+mopPutLong(u_char *pkt, int *idx, u_long value)
{
int i;
for (i = 0; i < 4; i++) {
- pkt[*index + i] = value % 256;
+ pkt[*idx+i] = (u_char)(value % 256);
value /= 256;
}
- *index += 4;
+ *idx += 4;
}
void
-mopPutMulti(u_char *pkt, int *index, u_char *value, int size)
+mopPutMulti(u_char *pkt, int *idx, u_char *value, int size)
{
int i;
for (i = 0; i < size; i++)
- pkt[*index + i] = value[i];
- *index += size;
+ pkt[*idx+i] = value[i];
+ *idx += size;
}
void
-mopPutTime(u_char *pkt, int *index, time_t value)
+mopPutTime(u_char *pkt, int *idx, time_t value)
{
time_t tnow;
struct tm *timenow;
@@ -88,75 +92,65 @@ mopPutTime(u_char *pkt, int *index, time_t value)
timenow = localtime(&tnow);
- mopPutChar(pkt, index, 10);
- mopPutChar(pkt, index, (timenow->tm_year / 100) + 19);
- mopPutChar(pkt, index, (timenow->tm_year % 100));
- mopPutChar(pkt, index, (timenow->tm_mon + 1));
- mopPutChar(pkt, index, (timenow->tm_mday));
- mopPutChar(pkt, index, (timenow->tm_hour));
- mopPutChar(pkt, index, (timenow->tm_min));
- mopPutChar(pkt, index, (timenow->tm_sec));
- mopPutChar(pkt, index, 0x00);
- mopPutChar(pkt, index, 0x00);
- mopPutChar(pkt, index, 0x00);
+ mopPutChar(pkt, idx, 10);
+ mopPutChar(pkt, idx, (timenow->tm_year / 100) + 19);
+ mopPutChar(pkt, idx, (timenow->tm_year % 100));
+ mopPutChar(pkt, idx, (timenow->tm_mon + 1));
+ mopPutChar(pkt, idx, (timenow->tm_mday));
+ mopPutChar(pkt, idx, (timenow->tm_hour));
+ mopPutChar(pkt, idx, (timenow->tm_min));
+ mopPutChar(pkt, idx, (timenow->tm_sec));
+ mopPutChar(pkt, idx, 0x00);
+ mopPutChar(pkt, idx, 0x00);
+ mopPutChar(pkt, idx, 0x00);
}
void
-mopPutHeader(u_char *pkt, int *index, char dst[], char src[], u_short proto,
+mopPutHeader(u_char *pkt, int *idx, u_char *dst, u_char *src, u_short proto,
int trans)
{
- mopPutMulti(pkt, index, dst, 6);
- mopPutMulti(pkt, index, src, 6);
+ mopPutMulti(pkt, idx, dst, 6);
+ mopPutMulti(pkt, idx, src, 6);
if (trans == TRANS_8023) {
- mopPutShort(pkt, index, 0);
- mopPutChar(pkt, index, MOP_K_PROTO_802_DSAP);
- mopPutChar(pkt, index, MOP_K_PROTO_802_SSAP);
- mopPutChar(pkt, index, MOP_K_PROTO_802_CNTL);
- mopPutChar(pkt, index, 0x08);
- mopPutChar(pkt, index, 0x00);
- mopPutChar(pkt, index, 0x2b);
+ mopPutShort(pkt, idx, 0);
+ mopPutChar(pkt, idx, MOP_K_PROTO_802_DSAP);
+ mopPutChar(pkt, idx, MOP_K_PROTO_802_SSAP);
+ mopPutChar(pkt, idx, MOP_K_PROTO_802_CNTL);
+ mopPutChar(pkt, idx, 0x08);
+ mopPutChar(pkt, idx, 0x00);
+ mopPutChar(pkt, idx, 0x2b);
}
#if !defined(__FreeBSD__)
- mopPutChar(pkt, index, (proto / 256));
- mopPutChar(pkt, index, (proto % 256));
+ mopPutNShort(pkt, idx, proto);
#else
if (trans == TRANS_8023) {
- mopPutChar(pkt, index, (proto / 256));
- mopPutChar(pkt, index, (proto % 256));
+ mopPutNShort(pkt, idx, proto);
} else {
- mopPutChar(pkt, index, (proto % 256));
- mopPutChar(pkt, index, (proto / 256));
+ mopPutShort(pkt, idx, proto);
}
#endif
if (trans == TRANS_ETHER)
- mopPutShort(pkt, index, 0);
+ mopPutShort(pkt, idx, 0);
}
void
mopPutLength(u_char *pkt, int trans, u_short len)
{
- int index = 0;
+ int idx;
switch (trans) {
case TRANS_ETHER:
- index = 14;
- mopPutChar(pkt, &index, ((len - 16) % 256));
- mopPutChar(pkt, &index, ((len - 16) / 256));
+ idx = 14;
+ mopPutShort(pkt, &idx, len-16);
break;
case TRANS_8023:
- index = 12;
+ idx = 12;
#if !defined(__FreeBSD__)
- mopPutChar(pkt, &index, ((len - 14) / 256));
- mopPutChar(pkt, &index, ((len - 14) % 256));
+ mopPutNShort(pkt, &idx, len-14);
#else
- mopPutChar(pkt, &index, ((len - 14) % 256));
- mopPutChar(pkt, &index, ((len - 14) / 256));
+ mopPutShort(pkt, &idx, len-14);
#endif
break;
}
-
}
-
-
-
diff --git a/usr.sbin/mopd/common/rc.c b/usr.sbin/mopd/common/rc.c
index 3c412741961..6c4af909d35 100644
--- a/usr.sbin/mopd/common/rc.c
+++ b/usr.sbin/mopd/common/rc.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: rc.c,v 1.5 2004/04/14 20:37:28 henning Exp $ */
+/* $OpenBSD: rc.c,v 1.6 2006/04/17 13:17:07 maja Exp $ */
/*
* Copyright (c) 1993-95 Mats O Jansson. All rights reserved.
@@ -24,9 +24,9 @@
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
-#ifndef LINT
+#ifndef lint
static const char rcsid[] =
- "$OpenBSD: rc.c,v 1.5 2004/04/14 20:37:28 henning Exp $";
+ "$OpenBSD: rc.c,v 1.6 2006/04/17 13:17:07 maja Exp $";
#endif
#include "os.h"
@@ -37,7 +37,7 @@ static const char rcsid[] =
void
mopDumpRC(FILE *fd, u_char *pkt, int trans)
{
- int i, index = 0;
+ int i, idx = 0;
long tmpl;
u_char tmpc, code, control;
u_short len, tmps, moplen;
@@ -46,40 +46,40 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
switch (trans) {
case TRANS_8023:
- index = 22;
+ idx = 22;
moplen = len - 8;
break;
default:
- index = 16;
+ idx = 16;
moplen = len;
}
- code = mopGetChar(pkt, &index);
+ code = mopGetChar(pkt, &idx);
switch (code) {
case MOP_K_CODE_RID:
- tmpc = mopGetChar(pkt, &index);
+ tmpc = mopGetChar(pkt, &idx);
fprintf(fd, "Reserved : %02x\n", tmpc);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Receipt Nbr : %04x\n", tmps);
break;
case MOP_K_CODE_BOT:
if ((moplen == 5)) {
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Verification : %04x\n", tmps);
} else {
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Verification : %08lx\n", tmpl);
- tmpc = mopGetChar(pkt, &index); /* Processor */
+ tmpc = mopGetChar(pkt, &idx); /* Processor */
fprintf(fd, "Processor : %02x ", tmpc);
mopPrintBPTY(fd, tmpc); fprintf(fd, "\n");
- control = mopGetChar(pkt, &index); /* Control */
+ control = mopGetChar(pkt, &idx); /* Control */
fprintf(fd, "Control : %02x ", control);
if ((control & (1>>MOP_K_BOT_CNTL_SERVER)))
fprintf(fd, "Bootserver Requesting system ");
@@ -92,15 +92,15 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd, "\n");
if ((control & (1>>MOP_K_BOT_CNTL_DEVICE))) {
- tmpc = mopGetChar(pkt, &index);/* Device ID */
+ tmpc = mopGetChar(pkt, &idx);/* Device ID */
fprintf(fd, "Device ID : %02x '", tmpc);
for (i = 0; i < ((int) tmpc); i++)
fprintf(fd, "%c",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "'\n");
}
- tmpc = mopGetChar(pkt, &index); /* Software ID */
+ tmpc = mopGetChar(pkt, &idx); /* Software ID */
fprintf(fd, "Software ID : %02x ", tmpc);
if ((tmpc == 0))
fprintf(fd, "No software id");
@@ -116,7 +116,7 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd, "'");
for (i = 0; i < ((int) tmpc); i++)
fprintf(fd, "%c",
- mopGetChar(pkt, &index));
+ mopGetChar(pkt, &idx));
fprintf(fd, "'");
}
fprintf(fd, "'\n");
@@ -125,60 +125,60 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
break;
case MOP_K_CODE_SID:
- tmpc = mopGetChar(pkt, &index); /* Reserved */
+ tmpc = mopGetChar(pkt, &idx); /* Reserved */
fprintf(fd, "Reserved : %02x\n", tmpc);
- tmps = mopGetShort(pkt, &index); /* Receipt # */
+ tmps = mopGetShort(pkt, &idx); /* Receipt # */
fprintf(fd, "Receipt Nbr : %04x\n", tmpc);
- mopPrintInfo(fd, pkt, &index, moplen, code, trans);
+ mopPrintInfo(fd, pkt, &idx, moplen, code, trans);
break;
case MOP_K_CODE_RQC:
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Receipt Nbr : %04x\n", tmps);
break;
case MOP_K_CODE_CNT:
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Receipt Nbr : %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Last Zeroed : %04x %d\n", tmps, tmps);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Bytes rec : %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Bytes snd : %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Frames rec : %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Frames snd : %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Mcst Bytes re: %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Mcst Frame re: %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Frame snd, def: %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Frame snd, col: %08lx %ld\n", tmpl, tmpl);
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Frame snd, mcl: %08lx %ld\n", tmpl, tmpl);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Snd failure : %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Snd fail reas: %04x ", tmps);
if (tmps & 1)
fprintf(fd, "Excess col ");
@@ -194,10 +194,10 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd, "Rem fail to defer ");
fprintf(fd, "\n");
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Rec failure : %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Rec fail reas: %04x ", tmps);
if (tmps & 1)
fprintf(fd, "Block chk err ");
@@ -207,22 +207,22 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd, "Frm to long ");
fprintf(fd, "\n");
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Unrec frm dst: %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Data overrun : %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Sys Buf Unava: %04x %d\n", tmps, tmps);
- tmps = mopGetShort(pkt, &index);
+ tmps = mopGetShort(pkt, &idx);
fprintf(fd, "Usr Buf Unava: %04x %d\n", tmps, tmps);
break;
case MOP_K_CODE_RVC:
- tmpl = mopGetLong(pkt, &index);
+ tmpl = mopGetLong(pkt, &idx);
fprintf(fd, "Verification : %08lx\n", tmpl);
break;
@@ -232,14 +232,13 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
break;
case MOP_K_CODE_CCP:
- tmpc = mopGetChar(pkt, &index);
+ tmpc = mopGetChar(pkt, &idx);
fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
if (tmpc & 2)
fprintf(fd, "Break");
fprintf(fd, "\n");
if (moplen > 2) {
-#ifndef SHORT_PRINT
for (i = 0; i < (moplen - 2); i++) {
if ((i % 16) == 0) {
if ((i / 16) == 0)
@@ -250,21 +249,18 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd,
" ");
}
- fprintf(fd, "%02x ", mopGetChar(pkt, &index));
+ fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
if ((i % 16) == 15)
fprintf(fd, "\n");
}
if ((i % 16) != 15)
fprintf(fd, "\n");
-#else
- index = index + moplen - 2;
-#endif
}
break;
case MOP_K_CODE_CRA:
- tmpc = mopGetChar(pkt, &index);
+ tmpc = mopGetChar(pkt, &idx);
fprintf(fd, "Control Flags: %02x Message %d ", tmpc, tmpc & 1);
if (tmpc & 2)
fprintf(fd, "Cmd Data Lost ");
@@ -273,7 +269,6 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd, "\n");
if (moplen > 2) {
-#ifndef SHORT_PRINT
for (i = 0; i < (moplen - 2); i++) {
if ((i % 16) == 0) {
if ((i / 16) == 0)
@@ -284,15 +279,12 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
fprintf(fd,
" ");
}
- fprintf(fd, "%02x ", mopGetChar(pkt, &index));
+ fprintf(fd, "%02x ", mopGetChar(pkt, &idx));
if ((i % 16) == 15)
fprintf(fd, "\n");
}
if ((i % 16) != 15)
fprintf(fd, "\n");
-#else
- index = index + moplen - 2;
-#endif
}
break;
@@ -300,4 +292,3 @@ mopDumpRC(FILE *fd, u_char *pkt, int trans)
break;
}
}
-