i am creating a ethernet network monitoring tool

i need to know on how to sniff packet or capture packets at
interval from the local area network.
then how to differenciate tcp,udp, datagram packets from
the capture packets,
logic is i need to create a function, to do this
then i need to respresent the capture packets by chart form.

how do i do this?
any one got any ideas ?