util.h 3.12 KB
Newer Older
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
Copyright (c) 2007 by Juliusz Chroboczek

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/

23
int seqno_compare(unsigned short s1, unsigned short s2)
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
24
    ATTRIBUTE ((const));
25
int seqno_minus(unsigned short s1, unsigned short s2)
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
26
    ATTRIBUTE ((const));
27 28
unsigned short seqno_plus(unsigned short s, int plus)
    ATTRIBUTE ((const));
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
29 30 31 32
void timeval_minus(struct timeval *d,
                   const struct timeval *s1, const struct timeval *s2);
int timeval_minus_msec(const struct timeval *s1, const struct timeval *s2)
    ATTRIBUTE ((pure));
33 34
void timeval_plus_msec(struct timeval *d,
                       const struct timeval *s, int msecs);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
35 36 37 38 39
int timeval_compare(const struct timeval *s1, const struct timeval *s2)
    ATTRIBUTE ((pure));
void timeval_min(struct timeval *d, const struct timeval *s);
void timeval_min_sec(struct timeval *d, int secs);
void do_debugf(const char *format, ...) ATTRIBUTE ((format (printf, 1, 2)));
40 41 42
int in_prefix(const unsigned char *address,
              const unsigned char *prefix, unsigned char plen)
    ATTRIBUTE ((pure));
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
43 44
const unsigned char *mask_prefix(unsigned char *ret,
                                 const unsigned char *prefix,
45
                                 unsigned char plen);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
46
const char *format_address(const unsigned char *address);
47
const char *format_prefix(const unsigned char *address, unsigned char prefix);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
48
int parse_address(const char *address, unsigned char *addr_r);
49
int parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r);
50
int wait_for_fd(int direction, int fd, int msecs);
51
int martian_prefix(const unsigned char *prefix, int plen);
52
int v4mapped(const unsigned char *address);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
53
void v4tov6(unsigned char *dst, const unsigned char *src);
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
54 55 56

/* If debugging is disabled, we want to avoid calling format_address
   for every omitted debugging message.  So debug is a macro.  But
57
   vararg macros are not portable. */
Juliusz Chroboczek's avatar
Juliusz Chroboczek committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
#define debugf(...) \
    do { \
        if(debug >= 2) do_debugf(__VA_ARGS__); \
    } while(0)
#elif defined(__GNUC__)
#define debugf(_args...) \
    do { \
        if(debug >= 2) do_debugf(_args); \
    } while(0)
#else
#define debugf do_debugf
#endif