Quick answer:
If your AP run Linux, you may want to have a look at the various files in:
/sys/class/net/<some interface>/statistics/
BUT: your question is unclear.
Since my computer will play the role of a routeur (WiFi acces point to
be precise) it won't generate packet by itself.
Wrong: your computer and it's interface will generate a lot of packets by itself - though not only TCP/IP. To begin with, "beacon frames" (typically one every 100ms) to signal the presence of your AP. These will be send whether or not a STA(tion) is connected.
There there will also be "management" stuff packets send by your AP as response to STA demands:
- The "probe responses" you'll send as a reply to "probe requests" send
by potential STAs intereted in your AP.
- Then connection and authentication frames (ex WPA2) exchanged between
your AP (hostapd maybe?) and STAs.
Then and only then we enter the world of TCP/IP packets. But we're not done yet with the plumbing: after that, since you're a router, I guess it also run a DHCP server, so there will be the DHCP offers as response to DHCP requests.
And then after that, yes, there will be the actual say "applicatives" packets carried between STAs (all passing through your router AP).
If that's these one packets that you're actually interested in counting, your first problem would be to distinguish them from all the other "infrastructure" packets (not only in the 802.11 infrastructure mode meaning of the term) that I mentioned above carried by the interface. So there is an inherent contradiction in your requirement between a low level info ("number of packet contained in the TX buffer at any time") and a high level wrong presupposition ("since my computer will play the role of a routeur (WiFi acces point to be precise) it won't generate packet by itself").
It's a whole different problem then just packet accounting per interface, and you'll need some kind of DPI (Deep Packet Inspection), pcap can be used here, or sorting and couting at the TCP/IP level per interface or IP (sub)networks, netfilter/iptables can help. But I hope I made it clear that the deeper you go down (at the kernel/interface/interface driver you go), the more "noise" of packets you do not seem to be interested into you'll get.
I know you want it in C but just as a proof of concept I tried it in Python and it worked.
– Ravi Feb 26 '16 at 09:23