]> git.ipfire.org Git - thirdparty/nqptp.git/blob - general-utilities.h
Merge pull request #34 from heitbaum/patch-1
[thirdparty/nqptp.git] / general-utilities.h
1 /*
2 * This file is part of the nqptp distribution (https://github.com/mikebrady/nqptp).
3 * Copyright (c) 2021-2022 Mike Brady.
4 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, version 2.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
16 *
17 * Commercial licensing is also available.
18 */
19
20 #ifndef GENERAL_UTILITIES_H
21 #define GENERAL_UTILITIES_H
22
23 // functions that are pretty generic
24 // specialised stuff should go in the nqptp-utilities
25
26 #include <inttypes.h>
27 #include <sys/socket.h>
28 #include <time.h>
29
30 // struct sockaddr_in6 is bigger than struct sockaddr. derp
31 #ifdef AF_INET6
32 #define SOCKADDR struct sockaddr_storage
33 #define SAFAMILY ss_family
34 #else
35 #define SOCKADDR struct sockaddr
36 #define SAFAMILY sa_family
37 #endif
38
39 void hcton64(uint64_t num, uint8_t *p);
40
41 // these are designed to avoid aliasing check errors
42 uint64_t nctoh64(const uint8_t *p);
43 uint32_t nctohl(const uint8_t *p);
44 uint16_t nctohs(const uint8_t *p);
45 uint64_t timespec_to_ns(struct timespec *tn);
46 uint64_t get_time_now();
47
48 uint64_t ntoh64(const uint64_t n);
49
50 #endif