aboutsummaryrefslogtreecommitdiff
path: root/src/libip/ip.h
blob: aae565c0fc66ef9500b61fdfadc0810c2c4a28fd (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#pragma	src	"/sys/src/libip"
#pragma	lib	"libip.a"

enum 
{
	IPaddrlen=	16,
	IPv4addrlen=	4,
	IPv4off=	12,
	IPllen=		4,
};

/*
 *  for reading /net/ipifc
 */
typedef struct Ipifc Ipifc;
typedef struct Ipifcs Ipifcs;

struct Ipifc
{
	char	dev[64];
	uchar	ip[IPaddrlen];
	uchar	mask[IPaddrlen];
	uchar	net[IPaddrlen];		/* ip & mask */
	Ipifc	*next;
};

struct Ipifcs
{
	Ipifc *first;
	Ipifc *last;
};

/*
 *  user level udp headers
 */
enum 
{
	Udphdrsize=	36,	/* size of a Udphdr */
};

typedef struct Udphdr Udphdr;
struct Udphdr
{
	uchar	raddr[IPaddrlen];	/* remote address and port */
	uchar	laddr[IPaddrlen];	/* local address and port */
	uchar	rport[2];
	uchar	lport[2];
};

uchar*	defmask(uchar*);
void	maskip(uchar*, uchar*, uchar*);
int	eipconv(va_list*, Fconv*);
ulong	parseip(uchar*, char*);
ulong	parseipmask(uchar*, char*);
int	parseether(uchar*, char*);
int	myipaddr(uchar*, char*);
int	myetheraddr(uchar*, char*);

void	readipifc(char*, Ipifcs*);

void	hnputl(void*, uint);
void	hnputs(void*, ushort);
uint	nhgetl(void*);
ushort	nhgets(void*);

#define	ipcmp(x, y) memcmp(x, y, IPaddrlen)
#define	ipmove(x, y) memmove(x, y, IPaddrlen)

extern uchar IPv4bcast[IPaddrlen];
extern uchar IPv4bcastobs[IPaddrlen];
extern uchar IPv4allsys[IPaddrlen];
extern uchar IPv4allrouter[IPaddrlen];
extern uchar IPnoaddr[IPaddrlen];
extern uchar v4prefix[IPaddrlen];
extern uchar IPallbits[IPaddrlen];

#define CLASS(p) ((*(uchar*)(p))>>6)