hlswmaster-ng/netpkt.h

57 lines
1.1 KiB
C
Raw Permalink Normal View History

2006-02-02 16:55:44 +01:00
#ifndef _NETPKT_H_
#define _NETPKT_H_
#include <net/if.h>
#include <netinet/in.h>
2006-04-15 19:55:07 +02:00
#include "list.h"
2006-02-20 12:31:34 +01:00
#define PARSE_ACCEPT 1
#define PARSE_ACCEPT_FREED 2
2006-03-06 20:13:26 +01:00
#define PARSE_ACCEPT_FAKE 3
#define PARSE_ACCEPT_QUIRK PARSE_ACCEPT
2006-02-20 12:31:34 +01:00
#define PARSE_REJECT 4
2006-02-02 16:55:44 +01:00
2006-03-05 02:28:19 +01:00
/* avoid cyclic deps */
class Socket;
2006-04-15 19:55:07 +02:00
class NetPkt : private ListEntry<NetPkt> {
2006-03-05 02:28:19 +01:00
friend class Socket;
2006-02-02 16:55:44 +01:00
public:
2006-03-05 02:28:19 +01:00
NetPkt(const char* data, int size);
2006-03-06 20:13:26 +01:00
NetPkt(int alloc);
2006-02-02 16:55:44 +01:00
~NetPkt();
int show(char* buf, int size);
2006-03-06 20:13:26 +01:00
char* showfull();
bool compare(unsigned int offset, const char* buf, unsigned int len);
int find(unsigned int offset, const char *buf, unsigned int len);
int parse_int(unsigned int offset, int *val);
int parse_ip(unsigned int offset, struct in_addr *ip);
2006-03-05 02:28:19 +01:00
void setAddress(struct sockaddr_in *addr);
struct sockaddr_in * getAddress();
2006-03-06 20:13:26 +01:00
bool sameAddress(NetPkt* pkt);
2006-04-15 19:55:07 +02:00
void merge(NetPkt* pkt);
bool append(const char* buf, unsigned int len);
2006-03-06 20:13:26 +01:00
int getPort();
int getSize();
2006-03-05 02:28:19 +01:00
2006-02-02 16:55:44 +01:00
protected:
NetPkt(const NetPkt& x);
NetPkt& operator=(const NetPkt& x);
struct sockaddr_in addr;
2006-03-05 02:28:19 +01:00
const char *data;
2006-03-06 20:13:26 +01:00
unsigned int size;
2006-03-05 02:28:19 +01:00
private:
2006-03-06 20:13:26 +01:00
unsigned int alloc;
2006-02-02 16:55:44 +01:00
};
#endif // _NETPKT_H_