|
| 1 | +/* |
| 2 | + This file is part of Kismet |
| 3 | +
|
| 4 | + Kismet is free software; you can redistribute it and/or modify |
| 5 | + it under the terms of the GNU General Public License as published by |
| 6 | + the Free Software Foundation; either version 2 of the License, or |
| 7 | + (at your option) any later version. |
| 8 | +
|
| 9 | + Kismet is distributed in the hope that it will be useful, |
| 10 | + but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | + GNU General Public License for more details. |
| 13 | +
|
| 14 | + You should have received a copy of the GNU General Public License |
| 15 | + along with Kismet; if not, write to the Free Software |
| 16 | + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 17 | +*/ |
| 18 | + |
| 19 | +#include <stdlib.h> |
| 20 | +#include <string.h> |
| 21 | + |
| 22 | +#include "kis_external_packet.h" |
| 23 | + |
| 24 | +/* Blocks are always aligned to 32bit and start at a boundary, so |
| 25 | + * when calculating the padded lengths, they only need the total padded to |
| 26 | + * 32 bit */ |
| 27 | + |
| 28 | +/* Calculate the padded block size of a string block for specified |
| 29 | + * string length */ |
| 30 | +size_t ks_proto_v3_strblock_padlen(size_t str_length) { |
| 31 | + /* length(u16) + pad(u16) + string(pad 32) */ |
| 32 | + return 2 + 2 + str_length + (str_length % 4); |
| 33 | +} |
| 34 | + |
| 35 | +void ks_proto_v3_fill_strblock(void *block_buf, size_t length, char *data) { |
| 36 | + kismet_v3_sub_string *substr = (kismet_v3_sub_string *) block_buf; |
| 37 | + |
| 38 | + memset(substr, 0, sizeof(kismet_v3_sub_string) + ks_proto_v3_pad(length)); |
| 39 | + |
| 40 | + substr->length = (uint16_t) length; |
| 41 | + substr->pad0 = 0; |
| 42 | + memcpy(substr->data, data, length); |
| 43 | +} |
| 44 | + |
0 commit comments