79 lines
1.8 KiB
C++
79 lines
1.8 KiB
C++
//
|
|
// Socket
|
|
//
|
|
|
|
/* prevent multiple inclusions */
|
|
#ifndef __RawSocket__
|
|
#define __RawSocket__
|
|
|
|
/* includes *****************************************************************/
|
|
|
|
#include "Socket.h"
|
|
|
|
#include<netinet/ip_icmp.h> //Provides declarations for icmp header
|
|
#include<netinet/udp.h> //Provides declarations for udp header
|
|
#include<netinet/tcp.h> //Provides declarations for tcp header
|
|
#include<netinet/ip.h> //Provides declarations for ip header
|
|
#include<sys/socket.h>
|
|
#include<arpa/inet.h>
|
|
|
|
/* defines ******************************************************************/
|
|
|
|
/* macros *******************************************************************/
|
|
|
|
/* structs & typedefs *******************************************************/
|
|
|
|
/* c class definitions ******************************************************/
|
|
|
|
class RawSocket : public Socket {
|
|
// public data
|
|
public:
|
|
struct sockaddr_storage sock_addr;
|
|
socklen_t sock_len;
|
|
|
|
// protected data
|
|
protected:
|
|
|
|
// private data
|
|
private:
|
|
|
|
// static data
|
|
|
|
// public methods
|
|
public:
|
|
// constructors
|
|
RawSocket();
|
|
|
|
// destructor
|
|
virtual ~RawSocket();
|
|
|
|
// copy constructor
|
|
RawSocket( const RawSocket &src ) ;
|
|
const RawSocket& operator=( const RawSocket &src );
|
|
|
|
// public methods
|
|
int Socket();
|
|
int RecvFrom( void *buf, int max );
|
|
|
|
// control
|
|
|
|
// status
|
|
int GetIPHdrLen( const void *buf );
|
|
int GetProtocol( const void *buf );
|
|
struct iphdr *GetIPHeader( const void *buf ) {return (struct iphdr*)buf;};
|
|
struct tcphdr *GetTcpHeader( const void *buf );
|
|
struct udphdr *GetUdpHeader( const void *buf );
|
|
unsigned char *GetData( const void *buf, int *length, int proto=0 );
|
|
|
|
// virtual functions
|
|
|
|
// exceptions
|
|
|
|
// static methods
|
|
|
|
// private methods
|
|
private:
|
|
};
|
|
|
|
#endif
|