70 lines
1.8 KiB
C++
70 lines
1.8 KiB
C++
#ifndef COPPINO_IPV6_H
|
|
#define COPPINO_IPV6_H
|
|
|
|
namespace ipv6 {
|
|
|
|
const uint8_t LEN = 128;
|
|
const uint8_t ICMP_ECHO_REQUEST_TYPE = 128;
|
|
const uint8_t ICMP_ECHO_REPLY_TYPE = 129;
|
|
|
|
const uint8_t NH_ICMP = 58;
|
|
const uint8_t NH_UDP = 17;
|
|
|
|
class IPv6Addr {
|
|
private:
|
|
char address[16];
|
|
public:
|
|
IPv6Addr();
|
|
IPv6Addr(const char* address);
|
|
};
|
|
|
|
extern const IPv6Addr ALL_NODES_ADDRESS;
|
|
|
|
struct ipv6_packet_header {
|
|
char field[4];
|
|
char len[2];
|
|
char next_header;
|
|
char hop_limit;
|
|
IPv6Addr src_addr;
|
|
IPv6Addr dst_addr;
|
|
}__attribute__((packed));
|
|
|
|
class IPv6Packet {
|
|
private:
|
|
char packet[LEN];
|
|
public:
|
|
IPv6Packet();
|
|
IPv6Packet(const char* buffer, int len);
|
|
void setLen(int len);
|
|
int getLen();
|
|
void setSrcAddress(const IPv6Addr* address);
|
|
const IPv6Addr* getSrcAddress();
|
|
void setDstAddress(const IPv6Addr* address);
|
|
const IPv6Addr* getDstAddress();
|
|
void setNextHeader(uint8_t next_header);
|
|
void setFlow(const char* flow);
|
|
void setPayload(char* payload, int len);
|
|
void send();
|
|
|
|
void doAction();
|
|
};
|
|
|
|
extern IPv6Packet packetin;
|
|
extern IPv6Packet packetout;
|
|
|
|
/* Note: content of message may be changed */
|
|
int handleICMP(char* output_buffer, const char* input_buffer, int len);
|
|
|
|
/* Compute internet checksum. Actually it is not so straightforward: */
|
|
uint16_t compute_checksum(
|
|
const IPv6Addr* src_addr, /* source IPv6 address */
|
|
const IPv6Addr* dst_addr, /* destination IPv6 address */
|
|
uint8_t next_header, /* IPv6 next header number */
|
|
int upper_len, /* length as found in the upper layer protocol */
|
|
const char* payload, /* IPv6 payload */
|
|
int len /* IPv6 payload length */
|
|
);
|
|
}
|
|
|
|
#endif
|