ip.h 1.12 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12
/*
 *	BIRD Internet Routing Daemon -- The Internet Protocol
 *
 *	(c) 1998 Martin Mares <mj@ucw.cz>
 *
 *	Can be freely distributed and used under the terms of the GNU GPL.
 */

#ifndef _BIRD_IP_H_
#define _BIRD_IP_H_

#ifndef IPV6
13
#include "ipv4.h"
14
#else
15
#include "ipv6.h"
16 17
#endif

18 19
#define ipa_in_net(x,n,p) (!ipa_nonzero(ipa_and(ipa_xor((n),(x)),ipa_mkmask(p))))

20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
/*
 *	ip_classify() returns either a negative number for invalid addresses
 *	or scope OR'ed together with address type.
 */

#define IADDR_INVALID		-1
#define IADDR_SCOPE_MASK       	0xfff
#define IADDR_HOST		0x1000
#define IADDR_BROADCAST		0x2000
#define IADDR_MULTICAST		0x4000

/*
 *	Address scope
 */

#define SCOPE_HOST 0
#define SCOPE_LINK 1
#define SCOPE_SITE 2
38 39
#define SCOPE_ORGANIZATION 3
#define SCOPE_UNIVERSE 4
40

41 42
char *ip_scope_text(unsigned);

43
/*
Martin Mareš's avatar
Martin Mareš committed
44
 *	Network prefixes
45 46
 */

Martin Mareš's avatar
Martin Mareš committed
47 48 49 50 51
struct prefix {
  ip_addr addr;
  int len;
};

52 53
#define ip_is_prefix(a,l) (!ipa_nonzero(ipa_and(a, ipa_not(ipa_mkmask(l)))))

54 55 56 57 58 59
/*
 *	Conversions between internal and string representation
 */

char *ip_ntop(ip_addr a, char *);
char *ip_ntox(ip_addr a, char *);
Martin Mareš's avatar
Martin Mareš committed
60
int ip_pton(char *a, ip_addr *o);
61

62
#endif