lsquic_util.h revision a5fa05f9
1/* Copyright (c) 2017 - 2020 LiteSpeed Technologies Inc. See LICENSE. */ 2/* 3 * lsquic_util.h -- Utility functions 4 */ 5 6#ifndef LSQUIC_UTIL_H 7#define LSQUIC_UTIL_H 1 8 9#ifdef __cplusplus 10extern "C" { 11#endif 12 13struct sockaddr; 14 15lsquic_time_t 16lsquic_time_now (void); 17 18void 19lsquic_init_timers (void); 20 21/* Returns 1 if `buf' contains only zero bytes, 0 otherwise. 22 */ 23int 24lsquic_is_zero (const void *buf, size_t bufsz); 25 26 27 28char * 29lsquic_get_bin_str (const void *s, size_t len, size_t max_display_len); 30 31size_t 32lsquic_hex_encode (const void *src, size_t src_sz, void *dst, size_t dst_sz); 33 34/* `out_sz' is assumed to be at least 1. `out' is always NUL-terminated. */ 35size_t 36lsquic_hexdump (const void *src, size_t src_sz, char *out, size_t out_sz); 37 38void 39lsquic_hexstr (const unsigned char *buf, size_t bufsz, char *out, size_t outsz); 40 41#define HEXSTR(buf, bufsz, out) \ 42 (lsquic_hexstr(buf, bufsz, out, sizeof(out)), out) 43 44int 45lsquic_sockaddr_eq (const struct sockaddr *a, const struct sockaddr *b); 46 47void 48lsquic_sockaddr2str (const struct sockaddr *addr, char *buf, size_t sz); 49 50#define SA2STR(sa_, buf_) (lsquic_sockaddr2str(sa_, buf_, sizeof(buf_)), buf_) 51 52#ifdef __cplusplus 53} 54#endif 55 56 57#endif 58