3 Functions Utils
Watersrc-stack edited this page 2026-10-14 04:00:21 +02:00

Utils

OS-neutral helpers: output (my_write), strings, the interface list, the LZ compressor.

Generated by make docs from the source and GCC's call graph. Back to the Function explorer.

libs/utils/if_tab.c

The NULL-terminated interface list, filled by the OS backends

if_tab_append

interface_t *if_tab_append(interface_t **if_tab, const char *append, enum PACKET_SRC iftype, const char *desc)

libs/utils/if_tab.c:15 · non-static · both builds

iftype comes from the OS backend (Wi-Fi detection is OS-specific), and desc too (NULL for none). The new interface, NULL on error (the list is left unchanged).

Called by: set_interfaces, append_device
Calls: str_dup
Library and system calls: free, malloc

if_tab_delete

void if_tab_delete(interface_t **if_tab)

libs/utils/if_tab.c:42 · non-static · both builds

The backends free their os_data before

Called by: common_lib_terminate, common_lib_terminate
Library and system calls: free

if_tab_display

void if_tab_display(interface_t **if_tab, int output_buffer, int1 numbers)

libs/utils/if_tab.c:54 · non-static · both builds

Called by: run_interactive, netotter
Calls: my_putunbr, my_putstr, my_strlen, my_write

libs/utils/lz_compress.c

The payload compressor: LZ77 matches found with hash chains and lazy matching, coded by the range coder (lz_range.c)

hash3

static uint32_t hash3(const lz_finder_t *f, int pos)

libs/utils/lz_compress.c:44 · static · both builds

Called by: finder_insert, finder_best

finder_init

static int finder_init(lz_finder_t *f, const uint8_t *src, int len)

libs/utils/lz_compress.c:54 · static · both builds

Enough hash bits for len positions, without clearing a big table for a small packet

Called by: lz_compress
Library and system calls: malloc

finder_insert

static void finder_insert(lz_finder_t *f, int pos)

libs/utils/lz_compress.c:73 · static · both builds

Called by: choose_token, lz_compress
Calls: hash3

common_len

static int common_len(const uint8_t *src, int from, int pos, int max)

libs/utils/lz_compress.c:84 · static · both builds

Called by: finder_best, choose_token

max_len

static int max_len(const lz_finder_t *f, int pos)

libs/utils/lz_compress.c:93 · static · both builds

Called by: finder_best, choose_token

finder_best

static int finder_best(const lz_finder_t *f, int pos, uint32_t *dist)

libs/utils/lz_compress.c:102 · static · both builds

The longest earlier match of pos (pos itself not inserted yet): its length, 0 under LZ_NEW_MATCH_MIN, and its distance in *dist

Called by: choose_token
Calls: hash3, common_len, max_len

choose_token

static lz_token_t choose_token(lz_finder_t *f, int pos, uint32_t rep0)

libs/utils/lz_compress.c:128 · static · both builds

The token at pos: the last distance again if it's about as long as the best match, the best match unless the next byte starts a longer one (lazy matching), else a literal. Inserts pos.

Called by: lz_compress
Calls: finder_insert, common_len, max_len, finder_best

encode_len

static void encode_len(lz_enc_t *rc, lz_len_model_t *m, int len)

libs/utils/lz_compress.c:147 · static · both builds

Called by: encode_token
Calls: lz_enc_bit, lz_enc_tree

encode_dist

static void encode_dist(lz_encoder_t *e, uint32_t dist, int len)

libs/utils/lz_compress.c:166 · static · both builds

A distance: its slot in the context of the match length, then the slot's extra bits

Called by: encode_token
Calls: lz_dist_slot, lz_slot_extra, lz_slot_base, lz_enc_direct, lz_enc_tree

encode_token

static void encode_token(lz_encoder_t *e, const uint8_t *src, int pos, lz_token_t *t)

libs/utils/lz_compress.c:186 · static · both builds

Called by: lz_compress
Calls: encode_len, encode_dist, lz_enc_bit, lz_enc_tree

hopeless

static int hopeless(lz_enc_t *rc, int pos)

libs/utils/lz_compress.c:208 · static · both builds

1 if the first pos input bytes barely shrank: random-looking data

Called by: lz_compress

lz_compress

int lz_compress(const uint8_t *src, uint16_t len, uint8_t *dst)

libs/utils/lz_compress.c:213 · non-static · both builds

Compresses len bytes of src into dst (len bytes). Returns the compressed length, 0 when it wouldn't be smaller than len (store src as is then). (from libs/utils/lz_compress.h)

Called by: store_payload
Calls: finder_init, finder_insert, choose_token, encode_token, hopeless, lz_model_init, lz_check, lz_enc_init, lz_enc_direct, lz_enc_flush
Library and system calls: free, malloc

libs/utils/lz_decompress.c

The payload decompressor (lz_compress.c in reverse). Its input may come from someone else's save file: every length and distance is checked against what's been written.

decode_len

static int decode_len(lz_dec_t *rc, lz_len_model_t *m)

libs/utils/lz_decompress.c:22 · static · both builds

Called by: decode_token
Calls: lz_dec_bit, lz_dec_tree

decode_dist

static uint32_t decode_dist(lz_decoder_t *d, int len)

libs/utils/lz_decompress.c:34 · static · both builds

Called by: decode_token
Calls: lz_slot_extra, lz_slot_base, lz_dec_direct, lz_dec_tree

copy_match

static int copy_match(lz_decoder_t *d, uint32_t dist, int len)

libs/utils/lz_decompress.c:55 · static · both builds

Copies len bytes from dist back. 1 if that's out of what's written.

Called by: decode_token

decode_token

static int decode_token(lz_decoder_t *d)

libs/utils/lz_decompress.c:65 · static · both builds

One token. 0 on success, 1 on malformed data.

Called by: lz_decompress
Calls: decode_len, decode_dist, copy_match, lz_dec_bit, lz_dec_tree

lz_decompress

int lz_decompress(const uint8_t *src, uint16_t len, uint8_t *dst, uint16_t out_len)

libs/utils/lz_decompress.c:87 · non-static · both builds

Decompresses len bytes of src into exactly out_len bytes of dst. 0 on success, 1 if src is malformed (it may come from a save file of someone else: nothing is ever read or written out of bounds). (from libs/utils/lz_compress.h)

Called by: store_read_payload
Calls: decode_token, lz_model_init, lz_check, lz_dec_init, lz_dec_direct, lz_dec_done
Library and system calls: free, malloc

libs/utils/lz_range.c

The adaptive binary range coder of the payload compression (LZMA's scheme), and the distance slots

lz_model_init

void lz_model_init(lz_model_t *model)

libs/utils/lz_range.c:10 · non-static · both builds

libs/utils/lz_range.c (from libs/utils/lz_compress.h)

Called by: lz_compress, lz_decompress

lz_check

uint32_t lz_check(const uint8_t *data, int len)

libs/utils/lz_range.c:20 · non-static · both builds

The LZ_CHECK_BITS check of len bytes (FNV-1a, folded) (from libs/utils/lz_compress.h)

Called by: lz_compress, lz_decompress

lz_dist_slot

int lz_dist_slot(uint32_t dist0)

libs/utils/lz_range.c:31 · non-static · both builds

Distances - 1 below 4 are their own slot, then 2 slots per power of two: 2 * log2 + the bit after the top one

Called by: encode_dist

lz_slot_extra

int lz_slot_extra(int slot)

libs/utils/lz_range.c:42 · non-static · both builds

Called by: encode_dist, decode_dist, lz_slot_base

lz_slot_base

uint32_t lz_slot_base(int slot)

libs/utils/lz_range.c:47 · non-static · both builds

Called by: encode_dist, decode_dist
Calls: lz_slot_extra

lz_enc_init

void lz_enc_init(lz_enc_t *rc, uint8_t *out, int cap)

libs/utils/lz_range.c:54 · non-static · both builds

Called by: lz_compress

enc_put

static void enc_put(lz_enc_t *rc, uint8_t byte)

libs/utils/lz_range.c:67 · static · both builds

Called by: enc_shift_low

enc_shift_low

static void enc_shift_low(lz_enc_t *rc)

libs/utils/lz_range.c:81 · static · both builds

Writes the top byte of low, once no carry can change it anymore

Called by: enc_normalize, lz_enc_flush
Calls: enc_put

enc_normalize

static void enc_normalize(lz_enc_t *rc)

libs/utils/lz_range.c:97 · static · both builds

Called by: lz_enc_bit, lz_enc_direct
Calls: enc_shift_low

lz_enc_bit

void lz_enc_bit(lz_enc_t *rc, uint16_t *prob, int bit)

libs/utils/lz_range.c:105 · non-static · both builds

Called by: encode_len, encode_token, lz_enc_tree
Calls: enc_normalize

lz_enc_direct

void lz_enc_direct(lz_enc_t *rc, uint32_t value, int bits)

libs/utils/lz_range.c:120 · non-static · both builds

Called by: encode_dist, lz_compress
Calls: enc_normalize

lz_enc_tree

void lz_enc_tree(lz_enc_t *rc, uint16_t *probs, int bits, uint32_t value)

libs/utils/lz_range.c:130 · non-static · both builds

value on bits bits, most significant first, probs[1 .. 2^bits - 1] (from libs/utils/lz_compress.h)

Called by: encode_len, encode_dist, encode_token
Calls: lz_enc_bit

lz_enc_flush

int lz_enc_flush(lz_enc_t *rc)

libs/utils/lz_range.c:142 · non-static · both builds

The final bytes. Returns the output length, 0 if it reached cap. (from libs/utils/lz_compress.h)

Called by: lz_compress
Calls: enc_shift_low

dec_next

static uint8_t dec_next(lz_dec_t *rc)

libs/utils/lz_range.c:158 · static · both builds

Called by: lz_dec_init, dec_normalize

lz_dec_init

void lz_dec_init(lz_dec_t *rc, const uint8_t *in, int len)

libs/utils/lz_range.c:166 · non-static · both builds

Called by: lz_decompress
Calls: dec_next

dec_normalize

static void dec_normalize(lz_dec_t *rc)

libs/utils/lz_range.c:179 · static · both builds

Called by: lz_dec_bit, lz_dec_direct
Calls: dec_next

lz_dec_bit

int lz_dec_bit(lz_dec_t *rc, uint16_t *prob)

libs/utils/lz_range.c:187 · non-static · both builds

Called by: decode_len, decode_token, lz_dec_tree
Calls: dec_normalize

lz_dec_direct

uint32_t lz_dec_direct(lz_dec_t *rc, int bits)

libs/utils/lz_range.c:204 · non-static · both builds

Called by: decode_dist, lz_decompress
Calls: dec_normalize

lz_dec_tree

uint32_t lz_dec_tree(lz_dec_t *rc, uint16_t *probs, int bits)

libs/utils/lz_range.c:220 · non-static · both builds

Called by: decode_len, decode_dist, decode_token
Calls: lz_dec_bit

lz_dec_done

int lz_dec_done(lz_dec_t *rc)

libs/utils/lz_range.c:229 · non-static · both builds

1 if the whole input was read, with at most LZ_TRIM_MAX padding zeros (from libs/utils/lz_compress.h)

Called by: lz_decompress

libs/utils/my_puts.c

Printing strings (PSTR) and unsigned numbers (PNBR) through my_write

my_putunbr

void my_putunbr(uint32_t nbr, int output_buffer)

libs/utils/my_puts.c:11 · non-static · both builds

my_puts.c (from libs/utils/my_utils.h)

Called by: parse_version, print_endpoint_port, print_port_info, print_ipv4_raw, print_padded, print_rel_time, print_tcp_header, print_udp_header, print_ipv4_info, print_ipv6_info, print_arp_info, print_packet_info, print_dns_type, print_rcode, print_inner_dst, print_icmp_tag, print_l7_tag, print_l7_info, print_arp_op, print_ipv4_line, print_ipv6_line, print_packet_line, display_enabled_itrf, print_count, print_mcast_info, print_proto_value, filter_print, filters_print_numbered, send_query, reverse_tick, log_print, print_loaded, anomaly_load_summary, anom_trusted_print, print_proto_suffix, print_service, print_count, print_ratio, print_error_subject, print_ms, print_timing_subject, print_content_subject, print_subject, print_totals (anom_report.c), anomaly_report, print_size, print_endpoint, print_totals (anom_stats.c), print_talkers, print_services, print_flows, print_outside, anom_chart_print, load_records, load_content, print_extra_counts, save_packets, display_packets, if_tab_display, my_putunbr, nw_tick_report, nw_tick_report
Calls: my_putunbr, my_write

my_putstr

void my_putstr(char *start, char *str, char *end, int output_buffer)

libs/utils/my_puts.c:20 · non-static · both builds

Called by: enable_from_list, run_cli, run_interactive, netotter, view_command, rename_rm, rename_command, online_command, list_command, info_command, print_commands, filter_command, filters_command, clear_command, remove_command, mode_command, save_command, process_keybind, handle_key, print_help, open_save_file_err, open_save_file, parse_version, parse_i_list, parse_arg, parse_args, pattern_to_arg, filter_args_from_text, parse_filter_option, print_host_info, print_app_info, print_ethertype, print_tcp_flags, print_tcp_header, print_udp_header, print_link_info, print_ipv4_info, print_ipv6_info, print_arp_party, print_arp_info, print_capture_time, print_packet_info, print_dns_type, print_rcode, print_inner_dst, print_icmp_tag, print_l7_tag, print_qname, print_l7_info, print_arp_op, print_ipv4_line, print_ipv6_line, print_packet_line, display_enabled_itrf, print_group, print_count, print_query_op, print_group_op, print_mcast_record, print_mcast_info, filters_print_names, filter_lookup, filter_parse_value, print_etype_value, filter_print, filters_print, filters_print_numbered, filter_add, local_print, renames_print, renames_write, send_query, open_resolver, reverse_tick, log_print, reverse_log_print, reverse_log_print_all, cache_disable, cache_create, print_loaded, print_origin, print_severity, anomaly_tick, anomaly_load_summary, trusted_error, trusted_parse, anom_trusted_load, anom_trusted_print, print_proto_suffix, print_service, print_count, print_label, print_ratio, print_error_subject, print_ms, print_timing_subject, print_content_subject, print_arp_subject, print_subject, anomaly_print, print_totals (anom_report.c), print_kind_names, anomaly_report, anomaly_print_packet, print_size, print_endpoint, print_totals (anom_stats.c), print_talkers, print_services, print_flows, print_outside, anom_chart_print, load_error, load_records, load_content, save_error, save_open, print_extra_counts, save_packets, print_alert, capture_full_check, display_packets, store_init, store_flush, if_tab_display, get_iftype, nw_open_socket, nw_close_socket, set_interfaces, nw_open_error, nw_open_socket, nw_close_socket
Calls: my_strlen, my_write

libs/utils/my_strtok.c

Splits a string on a separator char into a NULL-terminated array of allocated strings

count_tokens

static int count_tokens(char *str, char delim, int1 skip_empty)

libs/utils/my_strtok.c:16 · static · both builds

How many tokens str splits into. With skip_empty, the empty ones (two delims in a row, or one at either end) don't count.

Called by: my_strtok

token_dup

static char *token_dup(char *start, int len)

libs/utils/my_strtok.c:34 · static · both builds

The len chars at start, allocated and '\0'-terminated. NULL if the allocation fails.

Called by: my_strtok
Calls: my_strncpy
Library and system calls: malloc

my_strtok

char **my_strtok(char *str, char delim, int1 skip_empty)

libs/utils/my_strtok.c:45 · non-static · both builds

my_strtok.c Splits str on delim into a NULL-terminated array of allocated strings (free it with tab_free). Without skip_empty, two delims in a row (or one at either end) give an empty string, so "a,,b" is "a", "", "b"; with it, empty strings are left out: "a", "b" (",," gives none). NULL if an allocation fails. (from libs/utils/my_utils.h)

Called by: enable_from_list, pattern_to_arg, filter_args_from_text, trusted_parse
Calls: count_tokens, token_dup, tab_free
Library and system calls: malloc

tab_free

void tab_free(char **tab)

libs/utils/my_strtok.c:75 · non-static · both builds

Called by: enable_from_list, pattern_to_arg, filter_args_from_text, trusted_parse, my_strtok
Library and system calls: free

libs/utils/my_utils.c

String helpers: length, copies, number length, append

my_strlen

int my_strlen(const char *str)

libs/utils/my_utils.c:11 · non-static · both builds

my_utils.c (from libs/utils/my_utils.h)

Called by: parse_i_list, parse_args, append_token, qname_facts, parse_http, expand_label, print_ethertype, parse_ifname, proto_name_is, local_print, app_lookup, longest_match, renames_write, reverse_record_put, reverse_answer_add, line_trim, print_label, endpoint_len, print_endpoint, put_host, put_record, put_filter, put_renames, put_local, with_save_ext, write_save, fpacket_new, fpacket_footprint, print_alert, if_tab_display, my_putstr, my_strcpy, my_strappend, str_dup, nw_tick_report, fallback_name, nw_tick_report

my_strncpy

int1 my_strncpy(const char *src, char *dest, int n)

libs/utils/my_utils.c:19 · non-static · both builds

Called by: token_dup, my_strcpy, init_common_struct, init_common_struct, fallback_name

my_strcpy

int1 my_strcpy(const char *src, char *dest)

libs/utils/my_utils.c:32 · non-static · both builds

Called by: parse_i_list, append_token, with_save_ext, fpacket_new, str_dup
Calls: my_strlen, my_strncpy

my_nlen

int my_nlen(int n)

libs/utils/my_utils.c:39 · non-static · both builds

Called by: print_endpoint_port, print_ipv4_raw, print_ipv4_line, print_ipv6_line, print_packet_line, endpoint_len, print_endpoint

my_strappend

int my_strappend(char *dest, int size, const char *src)

libs/utils/my_utils.c:52 · non-static · both builds

Appends src to dest (size bytes, '\0'-terminated). -1 if it doesn't fit (dest is then unchanged). (from libs/utils/my_utils.h)

Called by: anomaly_print_tags, limit_message, cache_file_path, open_named, cache_file_path, spool_name
Calls: my_strlen

libs/utils/my_write.c

write() that can also collect the output in memory (OUT_MEMORY), to rework it before printing it

out_append

static int out_append(const void *buf, int len)

libs/utils/my_write.c:20 · static · both builds

Appends len bytes to the memory output, growing it as needed. len on success, -1 if the allocation fails.

Called by: my_write
Library and system calls: memcpy, realloc

my_write

int my_write(int fd, const void *buf, int len)

libs/utils/my_write.c:39 · non-static · both builds

my_write.c: write() to a fd, or to memory with OUT_MEMORY (collected until my_out_take() hands it over, allocated, to free by the caller) (from libs/utils/my_utils.h)

Called by: run_cli, start_program, rename_command, print_endpoint_port, print_port_info, print_ipv4_raw, print_ipv4, print_ipv6_raw, print_proto, print_hex, print_mac, print_ethertype, print_hexdump, print_tcp_flags, print_padded, print_rel_time, print_tcp_header, print_udp_header, print_link_info, print_ipv4_info, print_ipv6_info, print_arp_party, print_capture_time, print_endpoint, print_endpoint6, print_ipv4_line, print_ipv6_line, print_mac_line, print_packet_line, print_sources, print_query_op, print_mcast_info, print_proto_value, filters_print, filters_print_numbered, local_print, renames_write, anomaly_tick, trusted_error, print_label, print_ms, print_timing_subject, print_size, pad_to, print_endpoint, anom_chart_print, if_tab_display, my_putunbr, my_putstr, toggle_ifname, get_ifname_state, nw_open_socket, nw_recv_one, nw_tick_report, find_itrf, nw_recv_one, nw_tick_report
Calls: out_append
Library and system calls: write

my_out_take

void my_out_take(char **data, int *len)

libs/utils/my_write.c:46 · non-static · both builds

Called by: view_end

my_out_free

void my_out_free(void)

libs/utils/my_write.c:55 · non-static · both builds

Called by: netotter_delete
Library and system calls: free

libs/utils/ut_core.c

Core helpers: ids and lines from text, str_dup, big-endian reads, the FNV-1a hash of an address

str_to_id

int str_to_id(const char *str)

libs/utils/ut_core.c:15 · non-static · both builds

Id typed by the user (interface or packet): digits only, 1 to 65535. -1 otherwise.

Called by: enable_from_list, info_command, remove_command

read_line

int read_line(char *buf, int size)

libs/utils/ut_core.c:33 · non-static · both builds

Reads stdin up to the next '\n' into buf (cut to size - 1 chars, the rest of the line is dropped). -1 if stdin closed before any char.

Called by: info_command, filter_command, filters_command, remove_command, save_command, handle_key
Library and system calls: read

str_dup

char *str_dup(const char *str)

libs/utils/ut_core.c:46 · non-static · both builds

Called by: filter_args_add, hostmap_set, rename_append, rename_set, log_entry_new, if_tab_append
Calls: my_strlen, my_strcpy
Library and system calls: malloc

get16

uint16_t get16(const uint8_t *p)

libs/utils/ut_core.c:60 · non-static · both builds

Called by: dns_learn, sni_from_extension, skip_field, sni_from_client_hello, sni_learn, handle_answer, ptr_answer_name

get32

uint32_t get32(const uint8_t *p)

libs/utils/ut_core.c:65 · non-static · both builds

Called by: quic_packet, in_v4

fnv1a

uint32_t fnv1a(const void *data, int len)

libs/utils/ut_core.c:70 · non-static · both builds

32-bit FNV-1a hash of len bytes (from libs/utils/my_utils.h)

Called by: qname_facts, detect_sweep, anom_table_find, anom_table_get

ip_fnv1a

uint32_t ip_fnv1a(int1 v6, const uint8_t *ip)

libs/utils/ut_core.c:80 · non-static · both builds

32-bit FNV-1a hash of an address (4 bytes, 16 with v6), for the hash maps: take it modulo their bucket count (from libs/utils/my_utils.h)

Called by: ip_hash, answer_bucket