Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added network server files
[palacios.git] / misc / network_servers / vtl / raw_ethernet_packet.h
1 #ifndef _raw_ethernet_packet
2 #define _raw_ethernet_packet
3 #include <iostream>
4 #include <stdio.h>
5
6 #include "socks.h"
7
8 #ifdef linux
9 #include <sys/socket.h>
10 #include <netinet/in.h>
11 #elif defined(WIN32)
12
13
14 #endif
15
16
17
18 #ifdef USE_SSL
19 extern "C" {
20 #define OPENSSL_NO_KRB5
21 #include <openssl/ssl.h>
22 }
23 #endif
24
25 class Packet;
26
27 using namespace std;
28
29
30 #define ETHERNET_HEADER_LEN 14
31 #define ETHERNET_DATA_MIN   46
32 #define ETHERNET_DATA_MAX   1500
33
34 #define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN+ETHERNET_DATA_MAX)
35
36
37 #define SERIALIZATION_CLOSED -1
38 #define SERIALIZATION_ERROR -2
39
40 struct RawEthernetPacket {
41   
42   char pkt[2 + 4 + ETHERNET_PACKET_LEN];
43   char * type;
44   size_t * size;
45   char * data;
46
47   size_t get_size() const;
48   void set_size(size_t new_size);
49   
50   char * get_type();
51   void set_type(const char * new_type);
52
53   char * get_data();
54   
55   int length() const { return sizeof(pkt);}
56
57
58   RawEthernetPacket();
59   RawEthernetPacket(const RawEthernetPacket &rhs);
60   RawEthernetPacket(const char *data, const size_t size);
61   const RawEthernetPacket & operator= (const RawEthernetPacket &rhs);
62   virtual ~RawEthernetPacket();
63
64   int SerializeToBuf(char ** buf) const;
65   void UnserializeFromBuf(char * buf);
66
67 #ifdef USE_SSL
68   int Serialize(const SOCK fd, SSL *ssl) const;
69   int Unserialize(const SOCK fd, SSL *ssl);
70 #endif
71   int Serialize(const SOCK fd) const;
72   int Unserialize(const SOCK fd);
73
74   int UdpSerialize(const SOCK fd,struct sockaddr *serveraddr) const;
75   int UdpUnserialize(const SOCK fd);
76   
77   int VtpSerialize(const SOCK fd, struct in_addr * serveraddr) const;
78   int VtpUnserialize(const SOCK fd, struct in_addr * serveraddr);
79
80
81
82
83   void Print(unsigned size=ETHERNET_PACKET_LEN, FILE *out=stdout) const;
84   ostream & Print(ostream &os) const;
85 };
86
87 inline ostream & operator<<(ostream &os, const RawEthernetPacket &p) {
88   return p.Print(os);
89 }
90 #endif