networking · beginner · ~15 min

Datagrams needed

Split a payload into MTU-sized datagrams.

Challenge

Implement int datagrams_needed(int total_bytes, int mtu) returning how many datagrams of at most mtu bytes are needed (ceiling division), 0 if mtu <= 0.

Starter code

int datagrams_needed(int total_bytes, int mtu) {
    /* TODO */
    return 0;
}

Solve this exercise in the browser editor — compile and run against the test harness, no setup required.