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
diff --git a/misc/network_servers/vtl/raw_ethernet_packet.h b/misc/network_servers/vtl/raw_ethernet_packet.h
new file mode 100644 (file)
index 0000000..2775571
--- /dev/null
@@ -0,0 +1,90 @@
+#ifndef _raw_ethernet_packet
+#define _raw_ethernet_packet
+#include <iostream>
+#include <stdio.h>
+
+#include "socks.h"
+
+#ifdef linux
+#include <sys/socket.h>
+#include <netinet/in.h>
+#elif defined(WIN32)
+
+
+#endif
+
+
+
+#ifdef USE_SSL
+extern "C" {
+#define OPENSSL_NO_KRB5
+#include <openssl/ssl.h>
+}
+#endif
+
+class Packet;
+
+using namespace std;
+
+
+#define ETHERNET_HEADER_LEN 14
+#define ETHERNET_DATA_MIN   46
+#define ETHERNET_DATA_MAX   1500
+
+#define ETHERNET_PACKET_LEN (ETHERNET_HEADER_LEN+ETHERNET_DATA_MAX)
+
+
+#define SERIALIZATION_CLOSED -1
+#define SERIALIZATION_ERROR -2
+
+struct RawEthernetPacket {
+  
+  char pkt[2 + 4 + ETHERNET_PACKET_LEN];
+  char * type;
+  size_t * size;
+  char * data;
+
+  size_t get_size() const;
+  void set_size(size_t new_size);
+  
+  char * get_type();
+  void set_type(const char * new_type);
+
+  char * get_data();
+  
+  int length() const { return sizeof(pkt);}
+
+
+  RawEthernetPacket();
+  RawEthernetPacket(const RawEthernetPacket &rhs);
+  RawEthernetPacket(const char *data, const size_t size);
+  const RawEthernetPacket & operator= (const RawEthernetPacket &rhs);
+  virtual ~RawEthernetPacket();
+
+  int SerializeToBuf(char ** buf) const;
+  void UnserializeFromBuf(char * buf);
+
+#ifdef USE_SSL
+  int Serialize(const SOCK fd, SSL *ssl) const;
+  int Unserialize(const SOCK fd, SSL *ssl);
+#endif
+  int Serialize(const SOCK fd) const;
+  int Unserialize(const SOCK fd);
+
+  int UdpSerialize(const SOCK fd,struct sockaddr *serveraddr) const;
+  int UdpUnserialize(const SOCK fd);
+  
+  int VtpSerialize(const SOCK fd, struct in_addr * serveraddr) const;
+  int VtpUnserialize(const SOCK fd, struct in_addr * serveraddr);
+
+
+
+
+  void Print(unsigned size=ETHERNET_PACKET_LEN, FILE *out=stdout) const;
+  ostream & Print(ostream &os) const;
+};
+
+inline ostream & operator<<(ostream &os, const RawEthernetPacket &p) {
+  return p.Print(os);
+}
+#endif