1 #ifndef _raw_ethernet_packet
2 #define _raw_ethernet_packet
9 #include <sys/socket.h>
10 #include <netinet/in.h>
20 #define OPENSSL_NO_KRB5
21 #include <openssl/ssl.h>
30 #define ETHERNET_HEADER_LEN 14
31 #define ETHERNET_DATA_MIN 46
32 #define ETHERNET_DATA_MAX 1500
34 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN+ETHERNET_DATA_MAX)
37 #define SERIALIZATION_CLOSED -1
38 #define SERIALIZATION_ERROR -2
40 struct RawEthernetPacket {
42 char pkt[2 + 4 + ETHERNET_PACKET_LEN];
47 size_t get_size() const;
48 void set_size(size_t new_size);
51 void set_type(const char * new_type);
55 int length() const { return sizeof(pkt);}
59 RawEthernetPacket(const RawEthernetPacket &rhs);
60 RawEthernetPacket(const char *data, const size_t size);
61 const RawEthernetPacket & operator= (const RawEthernetPacket &rhs);
62 virtual ~RawEthernetPacket();
64 int SerializeToBuf(char ** buf) const;
65 void UnserializeFromBuf(char * buf);
68 int Serialize(const SOCK fd, SSL *ssl) const;
69 int Unserialize(const SOCK fd, SSL *ssl);
71 int Serialize(const SOCK fd) const;
72 int Unserialize(const SOCK fd);
74 int UdpSerialize(const SOCK fd,struct sockaddr *serveraddr) const;
75 int UdpUnserialize(const SOCK fd);
77 int VtpSerialize(const SOCK fd, struct in_addr * serveraddr) const;
78 int VtpUnserialize(const SOCK fd, struct in_addr * serveraddr);
83 void Print(unsigned size=ETHERNET_PACKET_LEN, FILE *out=stdout) const;
84 ostream & Print(ostream &os) const;
87 inline ostream & operator<<(ostream &os, const RawEthernetPacket &p) {