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

View File

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

7
ipv6.h
View File

@ -16,8 +16,6 @@ namespace ipv6 {
public:
IPv6Addr();
IPv6Addr(const char* address);
void deserialize(const char* address);
const char* serialize();
};
extern const IPv6Addr ALL_NODES_ADDRESS;
@ -35,14 +33,13 @@ namespace ipv6 {
private:
char packet[LEN];
public:
IPv6Packet();
IPv6Packet(const char* buffer, int len);
void setSrcAddress(IPv6Addr& address);
void setDstAddress(IPv6Addr& address);
void setNextHeader(uint8_t next_header);
void setFlow(const char* flow);
void setPayload(char* payload, int len);
char* serialize();
void deserialize(const char*, int len);
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(const char* address) {
this->deserialize(address);
}
void IPv6Addr::deserialize(const char* address) {
memcpy(this->address, address, 16);
}
const char* IPv6Addr::serialize() {
return this->address;
}
/******** IPv6Packet ********/
char* IPv6Packet::serialize() { /* do we actually need these function? everything is already store in a tokenized/serialized form */
return packet;
IPv6Packet::IPv6Packet() {
;
}
void IPv6Packet::deserialize(const char* buffer, int len) {
memcpy(packet, buffer, len);
IPv6Packet::IPv6Packet(const char* buffer, int len) {
memcpy(this->packet, buffer, len);
}
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 */
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:
* the reply has the same exact format of the request,
* 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.setNextHeader(NH_ICMP);
slip::send((void*)&reply_packet, 40 + len);
//}
}
}
return;
}