/
usbnames.h
82 lines (68 loc) · 2.16 KB
/
usbnames.h
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
/*****************************************************************************/
/*
* names.h -- USB name database manipulation routines
*
* Copyright (C) 1999, 2000 Thomas Sailer (sailer@ife.ee.ethz.ch)
*
* This program 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.
*
* This program 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.
*
*
*/
/*****************************************************************************/
#ifndef _NAMES_H
#define _NAMES_H
#include <sys/types.h>
#include <cstdint>
#ifndef __UCLIBCXX_MAJOR__
#include <map>
#endif
#include "libldetect.h"
/* ---------------------------------------------------------------------- */
namespace ldetect {
#ifdef __UCLIBCXX_MAJOR__
#define HASHSZ 16
struct vendor {
struct vendor *next;
uint16_t vendorid;
char name[1];
};
struct product {
struct product *next;
uint16_t vendorid, productid;
char name[1];
};
#endif
class usbNames {
public:
#ifdef __UCLIBCXX_MAJOR__
const char *getVendor(uint16_t vendorid);
const char *getProduct(uint16_t vendorid, uint16_t productid);
#else
const std::string& getVendor(uint16_t vendorid);
const std::string& getProduct(uint16_t vendorid, uint16_t productid);
#endif
usbNames(std::string &&n);
~usbNames();
private:
#ifdef __UCLIBCXX_MAJOR__
int newVendor(const char *name, uint16_t vendorid);
int newProduct(const char *name, uint16_t vendorid, uint16_t productid);
struct vendor *_vendors[HASHSZ] = { nullptr, };
struct product *_products[HASHSZ] = { nullptr, };
#else
std::map<uint16_t, std::string> _vendors;
std::map<std::pair<uint16_t, uint16_t>, std::string> _products;
#endif
void parse(instream &f);
};
}
/* ---------------------------------------------------------------------- */
#endif /* _NAMES_H */