From c3d9cf15538dc2c6ae0a56d0e4a15631eeded9be Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Mon, 4 May 2015 05:52:04 +0000 Subject: [PATCH] Init vendorstr from string. FossilOrigin-Name: 7d0839bd15278e7c04d3ff632ff772bc9107c6a809699f03ce1dde7823b2261e --- src/capwap/vendorstr_create_from_str.c | 37 ++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/capwap/vendorstr_create_from_str.c diff --git a/src/capwap/vendorstr_create_from_str.c b/src/capwap/vendorstr_create_from_str.c new file mode 100644 index 00000000..5877331a --- /dev/null +++ b/src/capwap/vendorstr_create_from_str.c @@ -0,0 +1,37 @@ +#include "bstr.h" +#include "format.h" + + +uint8_t * vendorstr_create_from_str(uint32_t vendor_id,const char *s) +{ + int l = strlen(s); + if (s[0]!='.') + return vendorstr_create(vendor_id,(uint8_t*)s,l); + + if (l<=2) + return vendorstr_create(vendor_id,(uint8_t*)s,l); + + if (s[1]=='.') + return vendorstr_create(vendor_id,(uint8_t*)s+1,l-1); + + if (s[1]!='x') + return vendorstr_create(vendor_id,(uint8_t*)s,l); + + /* the string starts with ".x" - read hexbytes */ + l-=2; + int msize=l/2; + if(l&1) + msize++; + + + uint8_t * mem = malloc(vendorstr_size(msize)); + if(!mem) + return NULL; + vendorstr_set_vendor_id(mem,vendor_id); + vendorstr_set_len(mem,msize); + + cw_format_scan_hex_bytes(vendorstr_data(mem),s+2,l); + return mem; +} + +