From 57cd0a11b10a68de24e64cad8aa18e7d1bb4c699 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Tue, 14 Apr 2015 05:49:43 +0000 Subject: [PATCH] Inital... FossilOrigin-Name: 38b667c96b7c2a9382689af12981401357d0a0df0fa25a4614d6b260aa05381e --- src/capwap/bstr16cfgstr.c | 67 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 src/capwap/bstr16cfgstr.c diff --git a/src/capwap/bstr16cfgstr.c b/src/capwap/bstr16cfgstr.c new file mode 100644 index 00000000..51aa8cc8 --- /dev/null +++ b/src/capwap/bstr16cfgstr.c @@ -0,0 +1,67 @@ + +#include +#include +#include + +#include "bstr.h" + + +/** + * Create a bstr1616_t string from a string read from config file. + * + * @param s String from config file. + * @return The create bstr16_t string. + * + * The string from config file is an ASCII-text which is interpreted + * as hexadecimal string if it starts with ".x" + * + * @see bstr16_t + */ +uint8_t * bstr16cfgstr(const char * s) +{ + int l = strlen(s); + + + if (s[0]!='.') + return bstr16_create((uint8_t*)s,l); + + if (l<=2) + return bstr16_create((uint8_t*)s,l); + + if (s[1]=='.') + return bstr16_create((uint8_t*)s+1,l-1); + + if (s[1]=='x'){ + uint8_t * ns=0; + int len=0; + + int ch,cl; + const char *ss = s+2; + int rc ; + do { + rc = sscanf(ss,"%01X",&ch); + if (rc!=1) + break; + ss++; + rc = sscanf(ss,"%01X",&cl); + if (rc!=1) + cl=0; + ss++; + int c=(ch<<4) | cl; + + len++; + ns = realloc(ns,len); + ns[len-1]=c; + + + }while (rc==1); + + + return bstr16_create(ns,len); + + + } + return NULL; +} + +