56 lines
1.3 KiB
C++
56 lines
1.3 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);
|
|
void deserialize(const char* address);
|
|
const char* serialize();
|
|
};
|
|
|
|
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:
|
|
void setSrcAddress(IPv6Addr& address);
|
|
void setDstAddress(IPv6Addr& address);
|
|
void setNextHeader(uint8_t next_header);
|
|
void setPayload(char* payload, int len);
|
|
|
|
char* serialize();
|
|
void deserialize(const char*, int len);
|
|
|
|
void doAction();
|
|
};
|
|
|
|
/* Note: content of message may be changed */
|
|
void handleICMP(const char* src, const char* dst, char* message, int len);
|
|
|
|
uint16_t compute_checksum(const char* src_addr, const char* dst_addr, uint8_t next_header, const char* payload, int len);
|
|
}
|
|
|
|
#endif
|