lsquic_util.h revision a74702c6
1/* Copyright (c) 2017 - 2022 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 _MSC_VER 53char * 54lsquic_strndup(const char *s, size_t n); 55#define strndup lsquic_strndup 56#endif 57 58#ifdef __cplusplus 59} 60#endif 61 62 63#endif 64