From ee995b6992c8d503785c77e3d40ab7f2c772ce41 Mon Sep 17 00:00:00 2001 From: "7u83@mail.ru" <7u83@mail.ru@noemail.net> Date: Sun, 15 Mar 2015 13:32:19 +0000 Subject: [PATCH] Moved out from wtpinfo_print.c FossilOrigin-Name: 89518449f297661ca5de8b485154ad1c1dcda0cf343b1338466441791370a149 --- src/capwap/cw_format_version.c | 84 ++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 src/capwap/cw_format_version.c diff --git a/src/capwap/cw_format_version.c b/src/capwap/cw_format_version.c new file mode 100644 index 00000000..ac47d4c4 --- /dev/null +++ b/src/capwap/cw_format_version.c @@ -0,0 +1,84 @@ +/* + 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 . + +*/ + +#include + +#include "cw_util.h" + +/** + *@file + *@brief Implementation of cw_sprintf_version + */ + + +/** + * Converts a CAPWAP version string to readable format. + * @param s target where the formated string will be stored + * @param ver the CAPWAP version data + * @param vendor vendor id + * @param def default string will be printed if version is NULL + * @return the number bytes added to the output *s + * + * This function tries to determine if the bstr_t string version + * is human readable, and if not, it will put out a hexadecimal value + * or a dot-seaprated list of number for version elements used + * by Cisco. + */ +int cw_format_version(char *s, bstr_t ver, uint32_t vendor, char * def) +{ + uint8_t * version = bstr_data(ver); + int len = bstr_len(ver); + + + if (!version) + return sprintf(s,"%s",def); + + + int rs=0; + int i; + + + if ( cw_is_printable(version,len) ){ + if (len != 0 ) + rs+=sprintf(s+rs,"%s",version); + else + rs+=sprintf(s+rs,"''"); + } + else{ + for (i=0; i