Information

Author(s) Mathieu Xhonneux & Maxime Mawait & Cyril Pletinckx
Deadline No deadline
Submission limit 12 submissions
every 1 hour(s)
Category tags s3, category_malloc, level2

Tags

Sign in

[S3] Reading from the wire

For your (possibly) future network's course, you will have to detect and analyse the data that are exchanged between two computers through the network (for example using the WiFi). In this exercise, we give you a function modem_read, to read the data exchanged thanks to the network, with the following prototype :

void modem_read(void *buffer, int *buf_len);

This function fills the supplied buffer with the data captured (an array of char), and writes the number of bytes written to this buffer in the variable pointed by buf_len. It can catch up to maximum 256 bytes in a single call. This function is guaranteed to return.


42

You want to analyse your network to see if a certain virus infected it or not. This virus consists of changing some bytes to an other byte whose numerical value is 42. Hence, you will use the function modem_read to catch some data passing through your network and process it to detect the "42 byte". Write the body of the function has_42, this function has to use malloc to create the buffer before calling modem_read.

NB : you know that in your network the byte whose numerical value is 42 is forbidden in normal circumstances so if you detect such a byte, it is inevitably because your network is infected.

/*
 * @return: 1 if your network is infected
 *         else 0, -1 if an error has happened.
 */
int has_42() {