* [PATCH 2/11]: Increase the scope of variable-length htonl/ntohl functions
@ 2007-10-01 14:18 Gerrit Renker
2007-10-01 20:16 ` Ian McDonald
0 siblings, 1 reply; 2+ messages in thread
From: Gerrit Renker @ 2007-10-01 14:18 UTC (permalink / raw)
To: dccp
[DCCP]: Increase the scope of variable-length htonl/ntohl functions
This extends the scope of two available functions, encode|decode_value_var,
to work up to 6 (8) bytes, to match maximum requirements in the RFC.
These functions are going to be used both by general option processing and
feature negotiation code, hence declarations have been put into feat.h.
Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
---
net/dccp/feat.h | 2 ++
net/dccp/options.c | 21 ++++++++++++++-------
2 files changed, 16 insertions(+), 7 deletions(-)
--- a/net/dccp/feat.h
+++ b/net/dccp/feat.h
@@ -120,4 +120,6 @@ static inline u8 dccp_bytes_per_value(co
return value > 0xFFFF? 4 : (value > 0xFF? 2 : 1);
}
+extern void dccp_encode_value_var(const u64 value, u8 *to, const u8 len);
+extern u64 dccp_decode_value_var(const u8 *bf, const u8 len);
#endif /* _DCCP_FEAT_H */
--- a/net/dccp/options.c
+++ b/net/dccp/options.c
@@ -23,16 +23,20 @@
#include "dccp.h"
#include "feat.h"
-static u32 dccp_decode_value_var(const unsigned char *bf, const u8 len)
+u64 dccp_decode_value_var(const u8 *bf, const u8 len)
{
- u32 value = 0;
+ u64 value = 0;
+ if (len > 5)
+ value += ((u64)*bf++) << 40;
+ if (len > 4)
+ value += ((u64)*bf++) << 32;
if (len > 3)
- value += *bf++ << 24;
+ value += ((u64)*bf++) << 24;
if (len > 2)
- value += *bf++ << 16;
+ value += ((u64)*bf++) << 16;
if (len > 1)
- value += *bf++ << 8;
+ value += ((u64)*bf++) << 8;
if (len > 0)
value += *bf;
@@ -286,9 +290,12 @@ out_invalid_option:
EXPORT_SYMBOL_GPL(dccp_parse_options);
-static void dccp_encode_value_var(const u32 value, unsigned char *to,
- const unsigned int len)
+void dccp_encode_value_var(const u64 value, u8 *to, const u8 len)
{
+ if (len > 5)
+ *to++ = (value & 0xFF0000000000ull) >> 40;
+ if (len > 4)
+ *to++ = (value & 0xFF00000000ull) >> 32;
if (len > 3)
*to++ = (value & 0xFF000000) >> 24;
if (len > 2)
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [PATCH 2/11]: Increase the scope of variable-length htonl/ntohl functions
2007-10-01 14:18 [PATCH 2/11]: Increase the scope of variable-length htonl/ntohl functions Gerrit Renker
@ 2007-10-01 20:16 ` Ian McDonald
0 siblings, 0 replies; 2+ messages in thread
From: Ian McDonald @ 2007-10-01 20:16 UTC (permalink / raw)
To: dccp
On 10/2/07, Gerrit Renker <gerrit@erg.abdn.ac.uk> wrote:
> [DCCP]: Increase the scope of variable-length htonl/ntohl functions
>
> This extends the scope of two available functions, encode|decode_value_var,
> to work up to 6 (8) bytes, to match maximum requirements in the RFC.
>
> These functions are going to be used both by general option processing and
> feature negotiation code, hence declarations have been put into feat.h.
>
> Signed-off-by: Gerrit Renker <gerrit@erg.abdn.ac.uk>
Acked-by: Ian McDonald <ian.mcdonald@jandi.co.nz>
--
Web1: http://wand.net.nz/~iam4/
Web2: http://www.jandi.co.nz
Blog: http://iansblog.jandi.co.nz
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2007-10-01 20:16 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2007-10-01 14:18 [PATCH 2/11]: Increase the scope of variable-length htonl/ntohl functions Gerrit Renker
2007-10-01 20:16 ` Ian McDonald
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.