⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 net.h

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 H
📖 第 1 页 / 共 2 页
字号:

#define bzero(s, n)			memset(s, 0, n)

#define EXIT(u)				netpanic("Net");



#define PRINTMSG(m, l)	{ m[l] = '\0'; trace(LOG_INFO, "Remote message: %Z", m); }



/*

 * MAKEHEADER - Add PPP Header fields to a packet.

 */

#define MAKEHEADER(p, t) { \
    PUTCHAR(PPP_ALLSTATIONS, p); \
    PUTCHAR(PPP_UI, p); \
    PUTSHORT(t, p); }



/*

 * Definitions of bits in internet address integers.

 * On subnets, the decomposition of addresses to host and net parts

 * is done according to subnet mask, not the masks here.

 */

#define	IN_CLASSA(i)		(((long)(i) & 0x80000000) == 0)

#define	IN_CLASSA_NET		0xff000000

#define	IN_CLASSA_NSHIFT	24

#define	IN_CLASSA_HOST		0x00ffffff

#define	IN_CLASSA_MAX		128



#define	IN_CLASSB(i)		(((long)(i) & 0xc0000000) == 0x80000000)

#define	IN_CLASSB_NET		0xffff0000

#define	IN_CLASSB_NSHIFT	16

#define	IN_CLASSB_HOST		0x0000ffff

#define	IN_CLASSB_MAX		65536



#define	IN_CLASSC(i)		(((long)(i) & 0xe0000000) == 0xc0000000)

#define	IN_CLASSC_NET		0xffffff00

#define	IN_CLASSC_NSHIFT	8

#define	IN_CLASSC_HOST		0x000000ff



#define	IN_CLASSD(i)		(((long)(i) & 0xf0000000) == 0xe0000000)

#define	IN_CLASSD_NET		0xf0000000	/* These ones aren't really */

#define	IN_CLASSD_NSHIFT	28		/* net and host fields, but */

#define	IN_CLASSD_HOST		0x0fffffff	/* routing needn't know.    */

#define	IN_MULTICAST(i)		IN_CLASSD(i)



#define	IN_EXPERIMENTAL(i)	(((long)(i) & 0xf0000000) == 0xf0000000)

#define	IN_BADCLASS(i)		(((long)(i) & 0xf0000000) == 0xf0000000)



#define	INADDR_ANY		    (u_long)0x00000000

#define	INADDR_BROADCAST	(u_long)0xffffffff	/* must be masked */

#ifndef KERNEL

#define	INADDR_NONE		    0xffffffff		/* -1 return */

#endif



#define	INADDR_UNSPEC_GROUP	    (u_long)0xe0000000	/* 224.0.0.0 */

#define	INADDR_ALLHOSTS_GROUP	(u_long)0xe0000001	/* 224.0.0.1 */

#define	INADDR_MAX_LOCAL_GROUP	(u_long)0xe00000ff	/* 224.0.0.255 */



#define	IN_LOOPBACKNET		127			/* official! */



/*

 * Error return codes from gethostbyname() and gethostbyaddr()

 * (left in extern int h_errno).

 */



#define	HOST_NOT_FOUND	1 /* Authoritative Answer Host not found */

#define	TRY_AGAIN	2 /* Non-Authoritive Host not found, or SERVERFAIL */

#define	NO_RECOVERY	3 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */

#define	NO_DATA		4 /* Valid name, no data record of requested type */

#define	NO_ADDRESS	NO_DATA		/* no address, look for MX record */



/*

 * Definitions for IP type of service (ip_tos)

 */

#define	IPTOS_LOWDELAY		0x10

#define	IPTOS_THROUGHPUT	0x08

#define	IPTOS_RELIABILITY	0x04



/* Allow function prototyping in BSD code. */

#define __P(c) c





/************************

*** PUBLIC DATA TYPES ***

************************/

/*

 * Structure used to store most network protocol addresses.

 */

typedef struct sockaddr {

    u_char  na_len;             /* total length */

    u_char  na_family;          /* address family */

	char	na_data[14];		/* actually longer; address value */

} NetAddr;



/*

 * Internet address (a structure for historical reasons)

 */

struct in_addr {

	u_long s_addr;

};



/*

 * Socket address, internet style.

 */

struct sockaddr_in {

	u_char	sin_len;

	u_char	sin_family;

	u_short	sin_port;

	struct	in_addr sin_addr;

	char	sin_zero[8];

};

#define ipAddr sin_addr.s_addr



/* TCP/IP Connection structure. */

typedef struct {

	struct sockaddr_in local;

	struct sockaddr_in remote;

} Connection;

#define localIPAddr local.sin_addr.s_addr

#define localPort local.sin_port

#define remoteIPAddr remote.sin_addr.s_addr

#define remotePort remote.sin_port





/*

 * The following struct gives the addresses of procedures to call

 * for a particular protocol.

 */

struct protent {

    u_short protocol;		/* PPP protocol number */

    /* Initialization procedure */

    void (*init) __P((int unit));

    /* Process a received packet */

    void (*input) __P((int unit, u_char *pkt, int len));

    /* Process a received protocol-reject */

    void (*protrej) __P((int unit));

    /* Lower layer has come up */

    void (*lowerup) __P((int unit));

    /* Lower layer has gone down */

    void (*lowerdown) __P((int unit));

    /* Open the protocol */

    void (*open) __P((int unit));

    /* Close the protocol */

    void (*close) __P((int unit, char *reason));

    /* Print a packet in readable form */

    int  (*printpkt) __P((u_char *pkt, int len,

			  void (*printer) __P((void *, char *, ...)),

			  void *arg));

    /* Process a received data packet */

    void (*datainput) __P((int unit, u_char *pkt, int len));

    int  enabled_flag;		/* 0 iff protocol is disabled */

    char *name;			/* Text name of protocol */

    /* Check requested options, assign defaults */

    void (*check_options) __P((void));

    /* Configure interface for demand-dial */

    int  (*demand_conf) __P((int unit));

    /* Say whether to bring up link for this pkt */

    int  (*active_pkt) __P((u_char *pkt, int len));

};



/*

 * The following structure records the time in seconds since

 * the last NP packet was sent or received.

 */

struct ppp_idle {

    u_short xmit_idle;		/* seconds since last NP packet sent */

    u_short recv_idle;		/* seconds since last NP packet received */

};



/*

 * Structures returned by network

 * data base library.  All addresses

 * are supplied in host order, and

 * returned in network order (suitable

 * for use in system calls).

 */

struct	hostent {

	char	*h_name;		/* official name of host */

	char	**h_aliases;	/* alias list */

	int		h_addrtype;		/* host address type */

	int		h_length;		/* length of address */

	char	**h_addr_list;	/* list of addresses from name server */

#define	h_addr	h_addr_list[0]	/* address, for backward compatiblity */

};



/*

 * Assumption here is that a network number

 * fits in 32 bits -- probably a poor one.

 */

struct	netent {

	char	*n_name;		/* official name of net */

	char	**n_aliases;	/* alias list */

	int		n_addrtype;		/* net address type */

	u_long	n_net;			/* network # */

};



struct	servent {

	char	*s_name;		/* official service name */

	char	**s_aliases;	/* alias list */

	int		s_port;			/* port # */

	char	*s_proto;		/* protocol to use */

};



struct	protoent {

	char	*p_name;		/* official protocol name */

	char	**p_aliases;	/* alias list */

	int		p_proto;	    /* protocol # */

};



/*

 * Modified struct hostent from <netdb.h>

 *

 * "Structures returned by network data base library.  All addresses

 * are supplied in host order, and returned in network order (suitable

 * for use in system calls)."

 */



typedef struct	{

	char	*name;		/* official name of host */

	char	**domains;	/* domains it serves */

	char	**addrList;	/* list of addresses from name server */

} ServerInfo;



typedef struct	{

	char	*name;		/* official name of host */

	char	**aliases;	/* alias list */

	char	**addrList;	/* list of addresses from name server */

	int		addrType;	/* host address type */

	int		addrLen;	/* length of address */

	ServerInfo **servers;

} HostInfo;



typedef	char *		caddr_t;	/* core address */





/*****************************

*** PUBLIC DATA STRUCTURES ***

*****************************/

extern int	auth_required;		/* Peer is required to authenticate */

extern u_short idle_time_limit;	/* Shut down link if idle for this long */

extern int	maxconnect;			/* Maximum connect time (seconds) */

extern int	refuse_pap;			/* Don't wanna auth. ourselves with PAP */

extern int	refuse_chap;		/* Don't wanna auth. ourselves with CHAP */



//#if PPP_SUPPORT > 0			/* A LOT MORE COULD HAVE BEEN REMOVED WITH PPP_SUPPORT */

extern char user[];				/* Username for PAP */

extern char	passwd[];			/* Password for PAP */

extern char	our_name[];			/* Our name for authentication purposes */

extern char	hostname[];			/* Our hostname */

extern char	remote_name[];		/* Peer's name for authentication */

extern int	explicit_remote;	/* remote_name specified with remotename opt */

extern int	usehostname;		/* Use hostname for our_name */

//#endif



extern u_int32_t	netMask;	/* IP netmask to set on interface */

extern u_int32_t	localHost;	/* Our IP address in */



extern struct protent *protocols[];/* Table of pointers to supported protocols */





/***********************

*** PUBLIC FUNCTIONS ***

************************/

/*

 * netInit - Initialize the network communications subsystem.

 */

void netInit(void);

void debugInit(void);

/*

 * Set the login user name and password for login and authentication

 *	purposes.  Using globals this way is rather hokey but until we

 *	fix some other things (like implementing a 2 step PPP open),

 *	this will do for now.

 */

void netSetLogin(const char *luser, const char *lpassword);



/* Convert a host long to a network long.  */

#define HTONL(n) (n = htonl(n))

extern u_long htonl (u_long __arg);



/* Convert a host short to a network short.  */

#define HTONS(n) (n = htons(n))

extern u_short htons (u_short __arg);



/* Convert a network long to a host long.  */

/* Note: We assume here that these are reversable. */

#define NTOHL(n) (n = htonl(n))

#define ntohl(n) htonl(n)



/* Convert a network short to a host short.  */

/* Note: We assume here that these are reversable. */

#define NTOHS(n) (n = htons(n))

#define ntohs(n) htons(n)



/*

 * print_string - print a readable representation of a string using

 * printer.

 */

void print_string(

	char *p,

	int len,

	void (*printer) __P((void *, char *, ...)),

	void *arg

);



void			endhostent __P((void));

void			endnetent __P((void));

void			endprotoent __P((void));

void			endservent __P((void));

struct hostent	*gethostbyaddr __P((const char *, int, int));

struct hostent	*gethostbyname __P((const char *));

struct hostent	*gethostent __P((void));

struct netent	*getnetbyaddr __P((long, int)); /* u_long? */

struct netent	*getnetbyname __P((const char *));

struct netent	*getnetent __P((void));

struct protoent	*getprotobyname __P((const char *));

struct protoent	*getprotobynumber __P((int));

struct protoent	*getprotoent __P((void));

struct servent	*getservbyname __P((const char *, const char *));

struct servent	*getservbyport __P((int, const char *));

struct servent	*getservent __P((void));

void			herror __P((const char *));

char			*hstrerror __P((int));

void			sethostent __P((int));

/* void			sethostfile __P((const char *)); */

void			setnetent __P((int));

void			setprotoent __P((int));

void			setservent __P((int));



u_int32_t GetMask __P((u_int32_t)); /* Get appropriate netmask for address */



/* in_canforward() - Dummy always succeeds. */

#define in_canforward(d) !0





#if HAVE_ANSI_TIME==0

#define _TIME_H_

struct tm

{ 

	int	tm_sec;

	int	tm_min;

	int	tm_hour;

	int	tm_mday;

	int	tm_mon;

	int	tm_year;

	int	tm_wday;

	int	tm_yday;

	int	tm_isdst;

	int tm_gmtoff;

	char *tm_zone;

};



ULONG time(ULONG *arg); 		/* placeholder for standard ANSI C time */

#endif





#endif // NET_H

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -