1

I'm trying to simulate the corruption of a packet transfer in a way that the checksum recognizes that the received packet is invalid.

Is there a function that allows me to change one single byte of the content of my packet?

EDIT: Ok, I'm trying to use XOR, that was a great idea, but now the problem persists. How can I change one single byte of my packet if the content I'm trying to corrupt is char*? How can i force it to work like a simple char and move my way around with a for cycle or something like that?

EDIT 2:

int main() {
    packet* pkt = pkt_init(0,PKT,"Test Pkt 0",5);
    int length = 10;
    char content[length];
    char xor[length];

    content[length] = (char) pkt->content;

    for(int i = 0; i<length; ++i)
        xor[i] = ~content[i];
    printf("Content: %s, Xor: %s\n", content, xor);

    return 0;
}

How to i check if the "damaging" went well? The console returns this:

Content: �~p��, Xor: O��x���!
  • What is `packet->content`? Is it a pointer to some memory? Then yes you can set a valid byte to some other value. – Some programmer dude Apr 09 '18 at 16:46
  • This answer may be useful: https://stackoverflow.com/questions/4439078/how-do-you-set-only-certain-bits-of-a-byte-in-c-without-affecting-the-rest – cluskii Apr 09 '18 at 16:47
  • 3
    Better than overwriting a byte would be to invert it - or invert a single bit. It might already be `0`. – Weather Vane Apr 09 '18 at 16:49
  • What @WeatherVane says. XOR is your friend.. – Martin James Apr 09 '18 at 16:52
  • Right, xor could be better, cause the byte I'm change is it possibile to be 00000000. To answer @Someprogrammerdude packet->content is a variable of my struct packet where is allocated the data that i have to change –  Apr 09 '18 at 17:00
  • `content[length] = (char) pkt->content;` That doesn't look right. Use `memcpy` instead. Or `char *content = pkt->content;`. – 001 Apr 09 '18 at 17:58

0 Answers0