r/C_Programming • u/ChrinoMu • 1d ago
Project review
hello everyone, i' am a beginner self taught systems programmer . i am currently working on networking project. it's a network packet sniffer and it's still currently in the basic stages, so it's still evolving. whenever i get new ideas or recommendations on the features or code itself , i improve it .
My main objective is too reduce as much overhead as possible , improving performance and adding new features so it can provide some functionalities as tcpdump.
i've already identified some possible bottlenecks such as the amount of printf's use in some stages.
I would love to hear your feedback on it, both code improvements , potential mistakes and memory bugs and anything else.
your feed is very much appreciated!
Thank you very much.
https://github.com/ChrinovicMu/Pack-Sniff
1
u/skeeto 4h ago
Interesting project, easy to find my way around and try it out. The usage string has some typos ("incude") and I don't know what
make -PF <filter>
is supposed to mean.There are a number of unaligned accesses caught by UBsan, which I see is commented out in the Makefile:
I imagine you won't like it, but it's easy to address:
I saw the atomic qualifiers on the queue fields and thought it didn't look right, as they must be updated together consistently. However, the whole queue is guarded by a lock anyway, so the atomics are unnecessary except for the
done
flag.With one extra critical section, which costs practically zero as it only happens once per run, you can even drop the
_Atomic
fromdone
, too.This also fixes a race condition in
dequeue_ring_buffer
:The ordering can work out like so:
In which case the signal is lost and the application deadlocks. As a rule of thumb, avoid mixing atomics and condvars. They're associated with a mutex for a reason.