Inital...
FossilOrigin-Name: 38b667c96b7c2a9382689af12981401357d0a0df0fa25a4614d6b260aa05381e
This commit is contained in:
parent
fb40c45300
commit
57cd0a11b1
67
src/capwap/bstr16cfgstr.c
Normal file
67
src/capwap/bstr16cfgstr.c
Normal file
@ -0,0 +1,67 @@
|
||||
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user