Blame view

Juliusz Chroboczek committed
1
/*
Juliusz Chroboczek committed
2
Copyright (c) 2007, 2008 by Juliusz Chroboczek
Juliusz Chroboczek committed
3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22

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.
*/

Juliusz Chroboczek committed
23
int seqno_compare(unsigned short s1, unsigned short s2)
Juliusz Chroboczek committed
24
    ATTRIBUTE ((const));
Juliusz Chroboczek committed
25
int seqno_minus(unsigned short s1, unsigned short s2)
Juliusz Chroboczek committed
26
    ATTRIBUTE ((const));
Juliusz Chroboczek committed
27 28
unsigned short seqno_plus(unsigned short s, int plus)
    ATTRIBUTE ((const));
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));
Juliusz Chroboczek committed
33 34
void timeval_plus_msec(struct timeval *d,
                       const struct timeval *s, int msecs);
Juliusz Chroboczek committed
35 36 37
int timeval_compare(const struct timeval *s1, const struct timeval *s2)
    ATTRIBUTE ((pure));
void timeval_min(struct timeval *d, const struct timeval *s);
Juliusz Chroboczek committed
38
void timeval_min_sec(struct timeval *d, time_t secs);
Juliusz Chroboczek committed
39
int parse_msec(const char *string);
Juliusz Chroboczek committed
40 41
void do_debugf(int leve, const char *format, ...)
    ATTRIBUTE ((format (printf, 2, 3)));
Juliusz Chroboczek committed
42 43 44
int in_prefix(const unsigned char *address,
              const unsigned char *prefix, unsigned char plen)
    ATTRIBUTE ((pure));
Juliusz Chroboczek committed
45 46
const unsigned char *mask_prefix(unsigned char *ret,
                                 const unsigned char *prefix,
Juliusz Chroboczek committed
47
                                 unsigned char plen);
Juliusz Chroboczek committed
48
const char *format_address(const unsigned char *address);
Juliusz Chroboczek committed
49
const char *format_prefix(const unsigned char *address, unsigned char prefix);
Juliusz Chroboczek committed
50 51 52
int parse_address(const char *address, unsigned char *addr_r, int *af_r);
int parse_net(const char *net, unsigned char *prefix_r, unsigned char *plen_r,
              int *af_r);
Juliusz Chroboczek committed
53
int wait_for_fd(int direction, int fd, int msecs);
Juliusz Chroboczek committed
54
int martian_prefix(const unsigned char *prefix, int plen);
Juliusz Chroboczek committed
55
int v4mapped(const unsigned char *address);
Juliusz Chroboczek committed
56
void v4tov6(unsigned char *dst, const unsigned char *src);
Julien Cristau committed
57
char *parse_ifflags(unsigned int flags);
Juliusz Chroboczek committed
58
int daemonise(void);
Juliusz Chroboczek committed
59 60 61

/* If debugging is disabled, we want to avoid calling format_address
   for every omitted debugging message.  So debug is a macro.  But
Juliusz Chroboczek committed
62
   vararg macros are not portable. */
Juliusz Chroboczek committed
63 64 65
#if defined __STDC_VERSION__ && __STDC_VERSION__ >= 199901L
#define debugf(...) \
    do { \
Juliusz Chroboczek committed
66 67 68 69 70
        if(debug >= 2) do_debugf(2, __VA_ARGS__);        \
    } while(0)
#define kdebugf(...) \
    do { \
        if(debug >= 3) do_debugf(3, __VA_ARGS__);        \
Juliusz Chroboczek committed
71 72 73 74
    } while(0)
#elif defined(__GNUC__)
#define debugf(_args...) \
    do { \
Juliusz Chroboczek committed
75 76 77 78 79
        if(debug >= 2) do_debugf(2, _args);      \
    } while(0)
#define kdebugf(_args...) \
    do { \
        if(debug >= 3) do_debugf(3, _args);      \
Juliusz Chroboczek committed
80 81 82 83 84
    } while(0)
#else
#define debugf do_debugf
#endif