OpenCores
URL https://opencores.org/ocsvn/1g_ethernet_dpi/1g_ethernet_dpi/trunk

Subversion Repositories 1g_ethernet_dpi

[/] [1g_ethernet_dpi/] [trunk/] [sw/] [dev/] [test_main/] [src/] [net/] [eth.h] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 4 kuzmi4
#ifndef _ETH_H_
2
#define _ETH_H_
3
 
4
#ifdef __cplusplus
5
extern "C"
6
{
7
#endif// __cplusplus
8
 
9
#include "xil_types.h"
10
 
11
// ??
12
#define _packed_struct  __attribute__ ((__packed__))
13
 
14
// eth hdr
15
struct ethhdr_ {
16
    u8   e_dst[6]; // ETH_DST_OFST
17
    u8   e_src[6]; // ETH_SRC_OFST
18
    u16  e_type;              // ETH_TYPE_OFST
19
} _packed_struct;
20
typedef struct ethhdr_ ethhdr_t;
21
 
22
// define Ethernet header size
23
#define ETH_HDR_SZ (sizeof(ethhdr_t))
24
 
25
// Offset of destination address within Ethernet header
26
#define ETH_DST_OFST      (0)
27
 
28
// Offset of source address within Ethernet header
29
#define ETH_SRC_OFST      (6)
30
 
31
// Offset of Ethernet type within Ethernet header
32
#define ETH_TYPE_OFST     (12)
33
 
34
/* Get Ethernet type from Ethernet header pointed by char * e
35
 * !!!returned Ethernet type is in host order!!!
36
 */
37
#define ETH_TYPE_GET(e)  \
38
        (((unsigned)(*((e) + ETH_TYPE_OFST)) << 8) + \
39
         (*((e) + ETH_TYPE_OFST + 1) & 0xff))
40
 
41
/* Set Ethernet type in Ethernet header pointed by char * e to value (type)
42
 * !!!Ethernet type is value is expected to be in host order!!!
43
 */
44
#define ETH_TYPE_SET(e, type) \
45
        *((e) + ETH_TYPE_OFST) = (unsigned char)(((type) >> 8) & 0xff); \
46
        *((e) + ETH_TYPE_OFST + 1) = (unsigned char)((type) & 0xff);
47
 
48
// rfc1071 internet checksum
49
unsigned short cksum(void * ptr, int count);
50
 
51
#ifdef __cplusplus
52
}
53
#endif// __cplusplus
54
 
55
#endif   // _ETH_H_

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.