diff options
author | Mats O Jansson <maja@cvs.openbsd.org> | 2006-04-17 13:17:08 +0000 |
---|---|---|
committer | Mats O Jansson <maja@cvs.openbsd.org> | 2006-04-17 13:17:08 +0000 |
commit | 27a592414832adb9ca18f73d3d83d5f3ffbd7df1 (patch) | |
tree | ec4afa1365308c2328799ea3876d6c27feec8130 /usr.sbin/mopd/common/put.c | |
parent | d9dd8fdfbcb5d6d007ea75c71abcf49764bc9c90 (diff) |
Make the code lint friendly. -moj
Diffstat (limited to 'usr.sbin/mopd/common/put.c')
-rw-r--r-- | usr.sbin/mopd/common/put.c | 118 |
1 files changed, 56 insertions, 62 deletions
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; } - } - - - |