TRIP Routing Daemon
TRIP (RFC 3219) Location Server Implementation
Loading...
Searching...
No Matches
util.h
1/*
2
3 trip: Modern TRIP LS implementation
4 Copyright (C) 2025 arf20 (Ángel Ruiz Fernandez)
5
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <https://www.gnu.org/licenses/>.
18
19*/
20
21#ifndef _UTIL_H
22#define _UTIL_H
23
24#include <sys/socket.h>
25#include <netinet/in.h>
26
27
33#define SOCK_TRY_SEND(o, a) \
34 if (o < 0) { \
35 ERROR("send(): %s", strerror(errno)); \
36 a; \
37 }
38
46#define SOCK_TRY_RECV(fd, buff, type, action) \
47 toread = sizeof(type); \
48 while (1) { \
49 res = recv(fd, buff, toread, 0); \
50 if (res < 0) { \
51 ERROR("recv(): %s", strerror(errno)); \
52 action; break; \
53 } else if (res == 0) { \
54 DEBUG("connection closed by peer"); \
55 action; break; \
56 } else if (res < sizeof(type)) { \
57 buff += res; break; \
58 toread -= res; \
59 continue; \
60 } \
61 toread -= res; \
62 buff += res; break; \
63 }
64
65
66void map_addr_inet_inet6(struct sockaddr_in6 *sin6,
67 const struct sockaddr_in *sin);
68
74int normalize_str_addr(struct sockaddr_in6 *sin6, const char *str);
75
76const char *sockaddr_str(const struct sockaddr *sa);
77
78const char *inaddr_str(uint32_t addr);
79const char *sockaddr6_str(const struct sockaddr_in6 *sa);
80
81#endif /* _UTIL_H */
82