2015-04-06 14:32:37 +02:00
|
|
|
/*
|
|
|
|
This file is part of libcapwap.
|
|
|
|
|
|
|
|
libcapwap is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
libcapwap is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Foobar. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
*/
|
|
|
|
/**
|
|
|
|
*@file
|
|
|
|
*@brief prototypes for format-functions
|
2015-05-02 10:45:16 +02:00
|
|
|
*@defgroup FormatFunctions FORMAT Functions
|
|
|
|
*@{
|
2015-04-06 14:32:37 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __CW_FORMAT_H
|
|
|
|
#define __CW_FORMAT_H
|
|
|
|
|
2015-04-19 23:27:44 +02:00
|
|
|
#include "capwap.h"
|
|
|
|
|
2015-04-06 14:32:37 +02:00
|
|
|
|
|
|
|
extern int cw_format_hex_bytes(char *dst, const char *format, const char *delim,
|
|
|
|
const uint8_t * src, int len);
|
2015-05-04 07:39:13 +02:00
|
|
|
extern int cw_format_scan_hex_bytes(uint8_t *dst,const char *s, int len);
|
|
|
|
|
2015-04-06 14:32:37 +02:00
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format bytes as a hex string. Hexadecimal letters are lower-case.
|
|
|
|
* @param dst destination buffer
|
|
|
|
* @param bytes bytes to format
|
|
|
|
* @param len number of bytes to format
|
|
|
|
* @return number of characters written to the destination buffer
|
|
|
|
*
|
|
|
|
* Make sure, the destination buffer can hold at least len * 2 characters + the trailing
|
|
|
|
* zero for strings.
|
|
|
|
*/
|
|
|
|
#define cw_format_hexl(dst,bytes,len)\
|
|
|
|
cw_format_hex_bytes(dst,"%02x","",bytes,len)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Format bytes as hex string. Same as #cw_format_hexl, but
|
|
|
|
* hexadecimal letters are upper-case.
|
|
|
|
*/
|
2016-03-05 13:41:11 +01:00
|
|
|
#define cw_format_hexu(dst,bytes,len)\
|
2015-04-06 14:32:37 +02:00
|
|
|
cw_format_hex_bytes(dst,"%02X","",bytes,len)
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Alias for #cw_format_hexl.
|
|
|
|
*/
|
|
|
|
#define cw_format_hex cw_format_hexl
|
|
|
|
|
2015-04-12 19:19:29 +02:00
|
|
|
/**
|
|
|
|
* Format MAC Address.
|
|
|
|
*/
|
|
|
|
#define cw_format_mac(dst,src,len)\
|
|
|
|
cw_format_hex_bytes(dst,"%02x",":",src,len)
|
2015-04-10 17:14:55 +02:00
|
|
|
|
2015-04-11 19:00:51 +02:00
|
|
|
/*#define cw_format_hdr_flags(s,th) \
|
|
|
|
sprintf(s,"(T=%d,F=%d,L=%d,W=%d,M=%d,K=%d)",\
|
|
|
|
cw_get_hdr_flag_t(packet),\
|
|
|
|
cw_get_hdr_flag_f(packet),\
|
|
|
|
cw_get_hdr_flag_l(packet),\
|
|
|
|
cw_get_hdr_flag_w(packet),\
|
|
|
|
cw_get_hdr_flag_m(packet),\
|
|
|
|
cw_get_hdr_flag_k(packet)\
|
|
|
|
);
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline int cw_format_hdr_flags(char *dst,uint8_t *th)
|
|
|
|
{
|
|
|
|
char * s = dst;
|
|
|
|
s+=sprintf(s,"%s", "(");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_t(th) ? "T":"");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_f(th) ? "F":"");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_l(th) ? "L":"");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_w(th) ? "W":"");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_m(th) ? "M":"");
|
|
|
|
s+=sprintf(s,"%s", cw_get_hdr_flag_k(th) ? "K":"");
|
|
|
|
s+=sprintf(s,"%s", ")");
|
|
|
|
return s-dst;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2015-05-02 10:45:16 +02:00
|
|
|
|
|
|
|
int cw_is_utf8(unsigned char *str, size_t len);
|
|
|
|
|
|
|
|
/**@}*/
|
|
|
|
|
2015-04-06 14:32:37 +02:00
|
|
|
#endif
|