2003-11-25 01:40:27 +00:00
|
|
|
#ifndef _IP_H_
|
|
|
|
#define _IP_H_ 1
|
|
|
|
#if defined(__cplusplus)
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2004-12-27 00:14:43 +00:00
|
|
|
|
2005-01-04 21:18:08 +00:00
|
|
|
AUTOLIB(ip)
|
2003-11-23 18:25:35 +00:00
|
|
|
/*
|
|
|
|
#pragma src "/sys/src/libip"
|
|
|
|
#pragma lib "libip.a"
|
|
|
|
#pragma varargck type "I" uchar*
|
|
|
|
#pragma varargck type "V" uchar*
|
|
|
|
#pragma varargck type "E" uchar*
|
|
|
|
#pragma varargck type "M" uchar*
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
|
|
|
IPaddrlen= 16,
|
|
|
|
IPv4addrlen= 4,
|
|
|
|
IPv4off= 12,
|
2006-04-01 19:24:03 +00:00
|
|
|
IPllen= 4
|
2003-11-23 18:25:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* for reading /net/ipifc
|
|
|
|
*/
|
|
|
|
typedef struct Ipifc Ipifc;
|
|
|
|
typedef struct Iplifc Iplifc;
|
|
|
|
typedef struct Ipv6rp Ipv6rp;
|
|
|
|
|
|
|
|
/* local address */
|
|
|
|
struct Iplifc
|
|
|
|
{
|
|
|
|
Iplifc *next;
|
|
|
|
|
|
|
|
/* per address on the ip interface */
|
|
|
|
uchar ip[IPaddrlen];
|
|
|
|
uchar mask[IPaddrlen];
|
|
|
|
uchar net[IPaddrlen]; /* ip & mask */
|
|
|
|
ulong preflt; /* preferred lifetime */
|
|
|
|
ulong validlt; /* valid lifetime */
|
|
|
|
};
|
|
|
|
|
|
|
|
/* default values, one per stack */
|
|
|
|
struct Ipv6rp
|
|
|
|
{
|
|
|
|
int mflag;
|
|
|
|
int oflag;
|
|
|
|
int maxraint;
|
|
|
|
int minraint;
|
|
|
|
int linkmtu;
|
|
|
|
int reachtime;
|
|
|
|
int rxmitra;
|
|
|
|
int ttl;
|
|
|
|
int routerlt;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* actual interface */
|
|
|
|
struct Ipifc
|
|
|
|
{
|
|
|
|
Ipifc *next;
|
|
|
|
Iplifc *lifc;
|
|
|
|
|
|
|
|
/* per ip interface */
|
|
|
|
int index; /* number of interface in ipifc dir */
|
|
|
|
char dev[64];
|
2005-12-31 19:34:53 +00:00
|
|
|
uchar ether[6];
|
2003-11-23 18:25:35 +00:00
|
|
|
uchar sendra6; /* on == send router adv */
|
|
|
|
uchar recvra6; /* on == rcv router adv */
|
|
|
|
int mtu;
|
|
|
|
ulong pktin;
|
|
|
|
ulong pktout;
|
|
|
|
ulong errin;
|
|
|
|
ulong errout;
|
|
|
|
Ipv6rp rp;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
* user level udp headers
|
|
|
|
*/
|
|
|
|
enum
|
|
|
|
{
|
2006-04-01 19:24:03 +00:00
|
|
|
Udphdrsize= 52 /* size of a Udphdr */
|
2003-11-23 18:25:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
typedef struct Udphdr Udphdr;
|
|
|
|
struct Udphdr
|
|
|
|
{
|
|
|
|
uchar raddr[IPaddrlen]; /* remote address and port */
|
|
|
|
uchar laddr[IPaddrlen]; /* local address and port */
|
2005-12-31 19:34:53 +00:00
|
|
|
uchar ifcaddr[IPaddrlen]; /* address of ifc message was received from */
|
2003-11-23 18:25:35 +00:00
|
|
|
uchar rport[2];
|
|
|
|
uchar lport[2];
|
|
|
|
};
|
|
|
|
|
|
|
|
uchar* defmask(uchar*);
|
|
|
|
void maskip(uchar*, uchar*, uchar*);
|
|
|
|
int eipfmt(Fmt*);
|
|
|
|
int isv4(uchar*);
|
|
|
|
ulong parseip(uchar*, char*);
|
|
|
|
ulong parseipmask(uchar*, char*);
|
|
|
|
char* v4parseip(uchar*, char*);
|
|
|
|
char* v4parsecidr(uchar*, uchar*, char*);
|
|
|
|
int parseether(uchar*, char*);
|
|
|
|
int myipaddr(uchar*, char*);
|
|
|
|
int myetheraddr(uchar*, char*);
|
|
|
|
int equivip(uchar*, uchar*);
|
2004-03-15 01:58:31 +00:00
|
|
|
long udpread(int, Udphdr*, void*, long);
|
|
|
|
long udpwrite(int, Udphdr*, void*, long);
|
2003-11-23 18:25:35 +00:00
|
|
|
|
|
|
|
Ipifc* readipifc(char*, Ipifc*, int);
|
2005-12-31 19:34:53 +00:00
|
|
|
void freeipifc(Ipifc*);
|
2003-11-23 18:25:35 +00:00
|
|
|
|
2004-12-27 00:14:43 +00:00
|
|
|
void hnputv(void*, uvlong);
|
2003-11-23 18:25:35 +00:00
|
|
|
void hnputl(void*, uint);
|
|
|
|
void hnputs(void*, ushort);
|
|
|
|
uint nhgetl(void*);
|
2004-12-27 00:14:43 +00:00
|
|
|
uvlong nhgetv(void*);
|
2003-11-23 18:25:35 +00:00
|
|
|
ushort nhgets(void*);
|
|
|
|
ushort ptclbsum(uchar*, int);
|
|
|
|
|
|
|
|
int v6tov4(uchar*, uchar*);
|
|
|
|
void v4tov6(uchar*, uchar*);
|
|
|
|
|
|
|
|
#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)
|
|
|
|
|
2003-11-25 01:40:27 +00:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
#endif
|