networking · beginner · ~15 min

Allocate a connection id

Hand out monotonically increasing ids.

Challenge

Implement int next_conn_id(int *counter) returning the current value of *counter and then incrementing it (post-increment), so each accepted connection gets a unique id.

Starter code

int next_conn_id(int *counter) {
    /* TODO */
    return 0;
}

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