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

📄 net.h

📁 一个EP9315的redboot,希望对大家有用
💻 H
📖 第 1 页 / 共 2 页
字号:
//==========================================================================////      net/net.h////      Stand-alone networking support for RedBoot////==========================================================================//####ECOSGPLCOPYRIGHTBEGIN####// -------------------------------------------// This file is part of eCos, the Embedded Configurable Operating System.// Copyright (C) 1998, 1999, 2000, 2001, 2002 Red Hat, Inc.// Copyright (C) 2002 Gary Thomas//// eCos is free software; you can redistribute it and/or modify it under// the terms of the GNU General Public License as published by the Free// Software Foundation; either version 2 or (at your option) any later version.//// eCos is distributed in the hope that it will be useful, but WITHOUT ANY// WARRANTY; without even the implied warranty of MERCHANTABILITY or// FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License// for more details.//// You should have received a copy of the GNU General Public License along// with eCos; if not, write to the Free Software Foundation, Inc.,// 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.//// As a special exception, if other files instantiate templates or use macros// or inline functions from this file, or you compile this file and link it// with other works to produce a work based on this file, this file does not// by itself cause the resulting work to be covered by the GNU General Public// License. However the source code for this file must still be made available// in accordance with section (3) of the GNU General Public License.//// This exception does not invalidate any other reasons why a work based on// this file might be covered by the GNU General Public License.//// Alternative licenses for eCos may be arranged by contacting Red Hat, Inc.// at http://sources.redhat.com/ecos/ecos-license/// -------------------------------------------//####ECOSGPLCOPYRIGHTEND####//==========================================================================//#####DESCRIPTIONBEGIN####//// Author(s):    gthomas// Contributors: gthomas// Date:         2000-07-14// Purpose:      // Description:  //              // This code is part of RedBoot (tm).////####DESCRIPTIONEND####////==========================================================================#ifndef _NET_H_#define _NET_H_#include <pkgconf/system.h>#include <pkgconf/redboot.h>#include <cyg/hal/hal_arch.h>#include <cyg/hal/basetype.h>#include <string.h>extern bool net_debug;#ifdef CYGPKG_IO_ETH_DRIVERS#  include <pkgconf/io_eth_drivers.h># ifdef CYGDBG_IO_ETH_DRIVERS_DEBUGextern int cyg_io_eth_net_debug;# endif#endifextern unsigned long do_ms_tick(void);extern unsigned long get_ms_ticks(void);#define MS_TICKS() get_ms_ticks()#define MS_TICKS_DELAY() do_ms_tick()/* #define NET_SUPPORT_RARP  1 */#define NET_SUPPORT_ICMP 1#define NET_SUPPORT_UDP  1#define NET_SUPPORT_TCP  1#if (CYG_BYTEORDER == CYG_LSBFIRST)#ifndef __LITTLE_ENDIAN__#define __LITTLE_ENDIAN__#endifextern unsigned long  ntohl(unsigned long x);extern unsigned long  ntohs(unsigned short x);#else#define	ntohl(x)	(x)#define	ntohs(x)	(x)#endif#define	htonl(x)	ntohl(x)#define	htons(x)	ntohs(x)/* * Minimum ethernet packet length. */#define ETH_MIN_PKTLEN  60#define ETH_MAX_PKTLEN  (1540-14)#define ETH_HDR_SIZE    14typedef unsigned char enet_addr_t[6];typedef unsigned char ip_addr_t[4];typedef unsigned char  octet;typedef unsigned short word;typedef unsigned int   dword;#ifndef NULL#define NULL 0#endif// IPv4 supporttypedef struct in_addr {    unsigned long  s_addr;  // IPv4 address} in_addr_t;// Socket/connection informationstruct sockaddr_in {    struct in_addr sin_addr;    unsigned short sin_port;    unsigned short sin_family;    short          sin_len;};#define AF_INET      1#define INADDR_ANY   0struct timeval {    unsigned long tv_sec;    unsigned long tv_usec;};/* * Simple timer support structure. */typedef void (*tmr_handler_t)(void *user_data);/* * Timer structure. * When expiration time is met or exceeded, the handler is * called and the timer struct is removed from the list. */typedef struct _timer {    struct _timer *next;        /* next timer in list */    unsigned long delay;	/* expiration time relative to start time */    unsigned long start;	/* when the timer was set */    tmr_handler_t handler;      /* user procedure to call when timer 'fires' */    void          *user_data;   /* user pointer passed to above procedure */} timer_t;/* * Ethernet header. */typedef struct {    enet_addr_t   destination;    enet_addr_t   source;    word          type;#define ETH_TYPE_IP   0x800#define ETH_TYPE_ARP  0x806#define ETH_TYPE_RARP 0x8053} eth_header_t;/* * ARP/RARP header. */typedef struct {    word	hw_type;#define ARP_HW_ETHER 1#define ARP_HW_EXP_ETHER 2    word	protocol;    octet	hw_len;    octet	proto_len;    word	opcode;#define	ARP_REQUEST	1#define	ARP_REPLY	2#define	RARP_REQUEST	3#define	RARP_REPLY	4    enet_addr_t	sender_enet;    ip_addr_t	sender_ip;    enet_addr_t	target_enet;    ip_addr_t	target_ip;} arp_header_t;#define ARP_PKT_SIZE  (sizeof(arp_header_t) + ETH_HDR_SIZE)/* * Internet Protocol header. */typedef struct {#ifdef __LITTLE_ENDIAN__    octet       hdr_len:4,                version:4;#else    octet       version:4,                hdr_len:4;#endif    octet       tos;    word        length;    word        ident;    word        fragment;    octet       ttl;    octet       protocol;#define IP_PROTO_ICMP  1#define IP_PROTO_TCP   6#define IP_PROTO_UDP  17    word        checksum;    ip_addr_t   source;    ip_addr_t   destination;} ip_header_t;#define IP_PKT_SIZE (60 + ETH_HDR_SIZE)/* * A IP<->ethernet address mapping. */typedef struct {    ip_addr_t    ip_addr;    enet_addr_t  enet_addr;} ip_route_t;/* * UDP header. */typedef struct {    word	src_port;    word	dest_port;    word	length;    word	checksum;} udp_header_t;/* * TCP header. */typedef struct {    word	src_port;    word	dest_port;    dword	seqnum;    dword	acknum;#ifdef __LITTLE_ENDIAN__    octet       reserved:4,                hdr_len:4;#else    octet       hdr_len:4,                reserved:4;#endif    octet	flags;#define TCP_FLAG_FIN  1#define TCP_FLAG_SYN  2#define TCP_FLAG_RST  4#define TCP_FLAG_PSH  8#define TCP_FLAG_ACK 16#define TCP_FLAG_URG 32    word	window;    word	checksum;    word	urgent;} tcp_header_t;/* * ICMP header. */typedef struct {    octet	type;#define ICMP_TYPE_ECHOREPLY   0#define ICMP_TYPE_ECHOREQUEST 8    octet	code;    word	checksum;    word	ident;    word	seqnum;} icmp_header_t;typedef struct _pktbuf {    struct _pktbuf *next;    union {	ip_header_t *__iphdr;		/* pointer to IP header */	arp_header_t *__arphdr;		/* pointer to ARP header */    } u1;#define ip_hdr u1.__iphdr#define arp_hdr u1.__arphdr    union {	udp_header_t *__udphdr;		/* pointer to UDP header */	tcp_header_t *__tcphdr;		/* pointer to TCP header */	icmp_header_t *__icmphdr;	/* pointer to ICMP header */    } u2;#define udp_hdr u2.__udphdr#define tcp_hdr u2.__tcphdr#define icmp_hdr u2.__icmphdr    word	pkt_bytes;		/* number of data bytes in buf */    word        bufsize;                /* size of buf */    word	*buf;} pktbuf_t;/* protocol handler */typedef void (*pkt_handler_t)(pktbuf_t *pkt, eth_header_t *eth_hdr);/* ICMP fielder */typedef void (*icmp_handler_t)(pktbuf_t *pkt, ip_route_t *src_route);typedef struct _udp_socket {    struct _udp_socket	*next;    word		our_port;    word		pad;    void                (*handler)(struct _udp_socket *skt, char *buf, int len,				   ip_route_t *src_route, word src_port);} udp_socket_t;

⌨️ 快捷键说明

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