File: util.h

package info (click to toggle)
zmap 4.3.4-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 1,628 kB
  • sloc: ansic: 15,033; python: 1,085; yacc: 125; sh: 120; lex: 28; makefile: 4
file content (75 lines) | stat: -rw-r--r-- 2,470 bytes parent folder | download
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
/*
 * Copyright 2021 Regents of the University of Michigan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#ifndef ZMAP_UTIL_H
#define ZMAP_UTIL_H

#include <stdio.h>
#include <stdint.h>
#include <sys/time.h>

#include "types.h"

int max_int(int a, int b);
int min_int(int a, int b);
uint64_t min_uint64_t(uint64_t a, uint64_t b);

uint64_t parse_max_targets(char *max_targets, int port_count);
void enforce_range(const char *name, int v, int min, int max);

// Splits comma delimited string into char*[]. Does not handle
// escaping or complicated setups - designed to process a set
// of fields that the user wants output
void split_string(const char *in, int *len, const char ***results);

// Print a string using w length long lines, attempting to break on
// spaces
void fprintw(FILE *f, const char *s, size_t w);

// pretty print elapsed (or estimated) number of seconds
void time_string(uint32_t time, int est, char *buf, size_t len);

// pretty print quantities
void number_string(uint32_t n, char *buf, size_t len);

// Convert a string representation of a MAC address to a byte array
int parse_mac(macaddr_t *out, char *in);

int check_range(int v, int min, int max);

int file_exists(char *name);

// If running as root, drops privileges to that of user "nobody".
// Otherwise, does nothing.
int drop_privs(void);

// Set CPU affinity to a single core
int set_cpu(uint32_t core);

// The number of seconds and microseconds since the Epoch.
double now(void);

// The number of seconds and nanoseconds since an unspecified point in time.
// On supported hosts, this value is guaranteed to never decrease.
//
// According to the POSIX specification the `clock_gettime` function is part
// of the Timers option and may not be available on all implementations.
//
// On hosts where a monotonic clock is not available, this falls back
// to `gettimeofday` which was ZMap's original implementation.
double steady_now(void);

#endif /* ZMAP_UTIL_H */