1a74702c6SGeorge Wang/* Copyright (c) 2017 - 2022 LiteSpeed Technologies Inc.  See LICENSE. */
250aadb33SDmitri Tikhonov/*
350aadb33SDmitri Tikhonov * lsquic_util.h -- Utility functions
450aadb33SDmitri Tikhonov */
550aadb33SDmitri Tikhonov
650aadb33SDmitri Tikhonov#ifndef LSQUIC_UTIL_H
750aadb33SDmitri Tikhonov#define LSQUIC_UTIL_H 1
850aadb33SDmitri Tikhonov
950aadb33SDmitri Tikhonov#ifdef __cplusplus
1050aadb33SDmitri Tikhonovextern "C" {
1150aadb33SDmitri Tikhonov#endif
1250aadb33SDmitri Tikhonov
138c1565cbSDmitri Tikhonovstruct sockaddr;
148c1565cbSDmitri Tikhonov
1550aadb33SDmitri Tikhonovlsquic_time_t
1650aadb33SDmitri Tikhonovlsquic_time_now (void);
1750aadb33SDmitri Tikhonov
1883287402SDmitri Tikhonovvoid
1983287402SDmitri Tikhonovlsquic_init_timers (void);
2083287402SDmitri Tikhonov
2150aadb33SDmitri Tikhonov/* Returns 1 if `buf' contains only zero bytes, 0 otherwise.
2250aadb33SDmitri Tikhonov */
2350aadb33SDmitri Tikhonovint
2450aadb33SDmitri Tikhonovlsquic_is_zero (const void *buf, size_t bufsz);
2550aadb33SDmitri Tikhonov
2650aadb33SDmitri Tikhonov
2750aadb33SDmitri Tikhonov
28a5fa05f9SDmitri Tikhonovchar *
29a5fa05f9SDmitri Tikhonovlsquic_get_bin_str (const void *s, size_t len, size_t max_display_len);
3050aadb33SDmitri Tikhonov
3155cd0b38SDmitri Tikhonovsize_t
3255cd0b38SDmitri Tikhonovlsquic_hex_encode (const void *src, size_t src_sz, void *dst, size_t dst_sz);
3350aadb33SDmitri Tikhonov
3450aadb33SDmitri Tikhonov/* `out_sz' is assumed to be at least 1.  `out' is always NUL-terminated. */
3550aadb33SDmitri Tikhonovsize_t
365392f7a3SLiteSpeed Techlsquic_hexdump (const void *src, size_t src_sz, char *out, size_t out_sz);
375392f7a3SLiteSpeed Tech
385392f7a3SLiteSpeed Techvoid
395392f7a3SLiteSpeed Techlsquic_hexstr (const unsigned char *buf, size_t bufsz, char *out, size_t outsz);
405392f7a3SLiteSpeed Tech
415392f7a3SLiteSpeed Tech#define HEXSTR(buf, bufsz, out) \
425392f7a3SLiteSpeed Tech    (lsquic_hexstr(buf, bufsz, out, sizeof(out)), out)
4350aadb33SDmitri Tikhonov
448c1565cbSDmitri Tikhonovint
458c1565cbSDmitri Tikhonovlsquic_sockaddr_eq (const struct sockaddr *a, const struct sockaddr *b);
468c1565cbSDmitri Tikhonov
47f2a7fa84SDmitri Tikhonovvoid
48f2a7fa84SDmitri Tikhonovlsquic_sockaddr2str (const struct sockaddr *addr, char *buf, size_t sz);
49f2a7fa84SDmitri Tikhonov
50f2a7fa84SDmitri Tikhonov#define SA2STR(sa_, buf_) (lsquic_sockaddr2str(sa_, buf_, sizeof(buf_)), buf_)
51f2a7fa84SDmitri Tikhonov
52a500a209SDmitri Tikhonov#ifdef _MSC_VER
53a500a209SDmitri Tikhonovchar *
54a500a209SDmitri Tikhonovlsquic_strndup(const char *s, size_t n);
55a500a209SDmitri Tikhonov#define strndup lsquic_strndup
56a500a209SDmitri Tikhonov#endif
57a500a209SDmitri Tikhonov
5850aadb33SDmitri Tikhonov#ifdef __cplusplus
5950aadb33SDmitri Tikhonov}
6050aadb33SDmitri Tikhonov#endif
6150aadb33SDmitri Tikhonov
6250aadb33SDmitri Tikhonov
6350aadb33SDmitri Tikhonov#endif
64