-
Notifications
You must be signed in to change notification settings - Fork 1
/
build.rs
53 lines (41 loc) · 1.47 KB
/
build.rs
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
extern crate itertools;
use std::env;
use std::fs::File;
use std::io::{self, BufReader, Write};
use std::path::Path;
include!("src/parse.rs");
#[cfg(feature = "latest")]
fn manuf() -> Result<BufReader<io::Cursor<String>>, anyhow::Error> {
const LATEST_MANUF_URL: &str =
"https://code.wireshark.org/review/gitweb?p=wireshark.git;a=blob_plain;f=manuf;hb=HEAD";
let text = reqwest::blocking::get(LATEST_MANUF_URL)?.text()?;
Ok(BufReader::new(io::Cursor::new(text)))
}
#[cfg(not(feature = "latest"))]
fn manuf() -> Result<BufReader<File>, io::Error> {
File::open("src/manuf").map(BufReader::new)
}
fn main() -> Result<(), anyhow::Error> {
let manuf = manuf()?;
let out_dir = env::var("OUT_DIR")?;
let dest_path = Path::new(&out_dir).join("vendors.rs");
let mut out = File::create(&dest_path)?;
out.write_all(
b"#[doc(hidden)]
#[allow(clippy::unreadable_literal, clippy::type_complexity)]
pub const VENDORS: &[((EtherAddr, u64), (&str, &str))] = &[\n",
)?;
for ((prefix, prefix_len), (name, desc)) in parse(manuf) {
let prefix_str = itertools::join(prefix.iter().map(|n| format!("0x{:02x}", n)), ", ");
let prefix_mask = ((1u64 << prefix_len) - 1) << (48 - prefix_len);
out.write_all(
format!(
"\t(([{}], 0x{:x}), ({:?}, {:?})),\n",
prefix_str, prefix_mask, name, desc
)
.as_bytes(),
)?;
}
out.write_all(b"];\n")?;
Ok(())
}