removed serialize/deserialize methods

it's everything already stored as serialized, just to save memory
(we only have 2k of memory)
This commit is contained in:
giomba 2019-12-23 22:30:58 +01:00
parent fb79e3d371
commit c07807fc86
4 changed files with 11 additions and 24 deletions

View File

@ -6,8 +6,7 @@ void setup() {
pinMode(13, OUTPUT); pinMode(13, OUTPUT);
Serial.begin(9600); Serial.begin(9600);
char addr[16] = { 0x20, 0x01, 0x04, 0x70, 0xc8, 0x44, 0x00, 0x31, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xca, 0xfe}; memcpy(&coppino::address, "\x20\x01\x04\x70\xc8\x44\x00\x31\x00\x00\x00\x00\x00\x00\xca\xfe", 16);
coppino::address.deserialize(addr);
} }
void loop() { void loop() {
@ -27,7 +26,7 @@ void loop() {
ip_packet.setNextHeader(17); // UDP ip_packet.setNextHeader(17); // UDP
// slip::send(ip_packet.serialize(), 18 + 40); // slip::send(&ip_packet, 18 + 40); // ??
coppino::handler(); coppino::handler();

View File

@ -9,8 +9,7 @@ namespace coppino {
int r; int r;
while ((r = slip::recv(buffer, LEN)) != -1) { while ((r = slip::recv(buffer, LEN)) != -1) {
ipv6::IPv6Packet packet; ipv6::IPv6Packet packet(buffer, r);
packet.deserialize(buffer, r);
packet.doAction(); packet.doAction();
} }

7
ipv6.h
View File

@ -16,8 +16,6 @@ namespace ipv6 {
public: public:
IPv6Addr(); IPv6Addr();
IPv6Addr(const char* address); IPv6Addr(const char* address);
void deserialize(const char* address);
const char* serialize();
}; };
extern const IPv6Addr ALL_NODES_ADDRESS; extern const IPv6Addr ALL_NODES_ADDRESS;
@ -35,14 +33,13 @@ namespace ipv6 {
private: private:
char packet[LEN]; char packet[LEN];
public: public:
IPv6Packet();
IPv6Packet(const char* buffer, int len);
void setSrcAddress(IPv6Addr& address); void setSrcAddress(IPv6Addr& address);
void setDstAddress(IPv6Addr& address); void setDstAddress(IPv6Addr& address);
void setNextHeader(uint8_t next_header); void setNextHeader(uint8_t next_header);
void setFlow(const char* flow); void setFlow(const char* flow);
void setPayload(char* payload, int len); void setPayload(char* payload, int len);
char* serialize();
void deserialize(const char*, int len);
void doAction(); void doAction();
}; };

View File

@ -48,24 +48,16 @@ uint16_t compute_checksum(const char* src_addr, const char* dst_addr, uint8_t ne
IPv6Addr::IPv6Addr() {;} IPv6Addr::IPv6Addr() {;}
IPv6Addr::IPv6Addr(const char* address) { IPv6Addr::IPv6Addr(const char* address) {
this->deserialize(address);
}
void IPv6Addr::deserialize(const char* address) {
memcpy(this->address, address, 16); memcpy(this->address, address, 16);
} }
const char* IPv6Addr::serialize() {
return this->address;
}
/******** IPv6Packet ********/ /******** IPv6Packet ********/
char* IPv6Packet::serialize() { /* do we actually need these function? everything is already store in a tokenized/serialized form */ IPv6Packet::IPv6Packet() {
return packet; ;
} }
void IPv6Packet::deserialize(const char* buffer, int len) { IPv6Packet::IPv6Packet(const char* buffer, int len) {
memcpy(packet, buffer, len); memcpy(this->packet, buffer, len);
} }
void IPv6Packet::setNextHeader(uint8_t next_header) { void IPv6Packet::setNextHeader(uint8_t next_header) {
@ -127,7 +119,7 @@ void handleICMP(const char* src_addr, const char* dst_addr, const char* flow, ch
memset(packet + 2, 0, 2); /* zero-checksum */ memset(packet + 2, 0, 2); /* zero-checksum */
uint16_t computed_checksum = compute_checksum(src_addr, dst_addr, NH_ICMP, packet, len); uint16_t computed_checksum = compute_checksum(src_addr, dst_addr, NH_ICMP, packet, len);
//if (memcmp(&computed_checksum, received_checksum, 2) == 0) { /* if checksum is valid, then... */ if (memcmp(&computed_checksum, received_checksum, 2) == 0) { /* if checksum is valid, then... */
/* Build an echo reply: /* Build an echo reply:
* the reply has the same exact format of the request, * the reply has the same exact format of the request,
* except for Type and Checksum */ * except for Type and Checksum */
@ -148,7 +140,7 @@ void handleICMP(const char* src_addr, const char* dst_addr, const char* flow, ch
reply_packet.setDstAddress(tmp_addr); reply_packet.setDstAddress(tmp_addr);
reply_packet.setNextHeader(NH_ICMP); reply_packet.setNextHeader(NH_ICMP);
slip::send((void*)&reply_packet, 40 + len); slip::send((void*)&reply_packet, 40 + len);
//} }
} }
return; return;
} }