1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
|
/*
This file is part of Kismet
Kismet 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 2 of the License, or
(at your option) any later version.
Kismet 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 Kismet; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __UTIL_H__
#define __UTIL_H__
#include "config.h"
#include <stdio.h>
#ifdef HAVE_STDINT_H
#include <stdint.h>
#endif
#ifdef HAVE_INTTYPES_H
#include <inttypes.h>
#endif
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <stdlib.h>
#include <pwd.h>
#include <ctype.h>
#include <math.h>
#include <string>
#include <map>
#include <vector>
// Munge a string to characters safe for calling in a shell
void MungeToShell(char *in_data, int max);
string MungeToShell(string in_data);
string StrLower(string in_str);
string StrStrip(string in_str);
int XtoI(char x);
int Hex2UChar(unsigned char *in_hex, unsigned char *in_chr);
vector<string> StrTokenize(string in_str, string in_split, int return_partial = 1);
// 'smart' tokenizeing with start/end positions
typedef struct smart_word_token {
string word;
size_t begin;
size_t end;
smart_word_token& operator= (const smart_word_token& op) {
word = op.word;
begin = op.begin;
end = op.end;
return *this;
}
};
vector<smart_word_token> SmartStrTokenize(string in_str, string in_split, int return_partial = 1);
vector<string> LineWrap(string in_txt, unsigned int in_hdr_len, unsigned int in_maxlen);
vector<int> Str2IntVec(string in_text);
void Float2Pair(float in_float, int16_t *primary, int64_t *mantissa);
float Pair2Float(int16_t primary, int64_t mantissa);
// Convert a float frequency to a channel number
int FloatChan2Int(float in_chan);
// Run a system command and return the error code. Caller is responsible for security.
// Does not fork out
int RunSysCmd(char *in_cmd);
// Fork and exec a syscmd, return the pid of the new process
pid_t ExecSysCmd(char *in_cmd);
#ifdef SYS_LINUX
int FetchSysLoadAvg(uint8_t *in_avgmaj, uint8_t *in_avgmin);
#endif
// Adler-32 checksum
uint32_t Adler32Checksum(char *buf1, int len);
// 802.11 checksum functions, extracted from the BBN USRP code
#define IEEE_802_3_CRC32_POLY 0xEDB88320
unsigned int update_crc32_80211(unsigned int crc, const unsigned char *data,
int len, unsigned int poly);
void crc32_init_table_80211(unsigned int *crc32_table);
unsigned int crc32_le_80211(unsigned int *crc32_table, const unsigned char *buf, int len);
#endif
|