diff options
author | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-03-27 04:37:15 +0000 |
---|---|---|
committer | Andreas Steffen <andreas.steffen@strongswan.org> | 2007-03-27 04:37:15 +0000 |
commit | ef49c3486a19368f444d55ed48dabb26751d8be9 (patch) | |
tree | bed58472db778d001235b3935398ff32e04ead3e /src | |
parent | 51ae94d77538cc2ce6337639713eaf5e839b8589 (diff) | |
download | strongswan-ef49c3486a19368f444d55ed48dabb26751d8be9.tar.bz2 strongswan-ef49c3486a19368f444d55ed48dabb26751d8be9.tar.xz |
added chunk_compare() which compares orders chunks
Diffstat (limited to 'src')
-rw-r--r-- | src/libstrongswan/chunk.c | 15 | ||||
-rw-r--r-- | src/libstrongswan/chunk.h | 6 |
2 files changed, 21 insertions, 0 deletions
diff --git a/src/libstrongswan/chunk.c b/src/libstrongswan/chunk.c index f2c8a3efb..1967b350a 100644 --- a/src/libstrongswan/chunk.c +++ b/src/libstrongswan/chunk.c @@ -233,6 +233,21 @@ chunk_t chunk_skip(chunk_t chunk, size_t bytes) /** * Described in header. */ +int chunk_compare(chunk_t a, chunk_t b) +{ + int compare_len = a.len - b.len; + int len = (compare_len < 0)? a.len : b.len; + + if (compare_len != 0 || len == 0) + { + return compare_len; + } + return memcmp(a.ptr, b.ptr, len); +}; + +/** + * Described in header. + */ bool chunk_equals(chunk_t a, chunk_t b) { return a.ptr != NULL && b.ptr != NULL && diff --git a/src/libstrongswan/chunk.h b/src/libstrongswan/chunk.h index 7fa257b00..9880ae20f 100644 --- a/src/libstrongswan/chunk.h +++ b/src/libstrongswan/chunk.h @@ -124,6 +124,12 @@ void chunk_free(chunk_t *chunk); chunk_t chunk_skip(chunk_t chunk, size_t bytes); /** + * Compare two chunks, returns zero if a equals b + * or negative/positive if a is small/greater than b + */ +int chunk_compare(chunk_t a, chunk_t b); + +/** * Compare two chunks for equality, * NULL chunks are never equal. */ |