PDA

View Full Version : Network Interface Card Traffic



hosseinyounesi
09-03-2009, 01:28 PM
Hi,
I want to get send/receive of my PC NICs in Linux?! For windows I can use "GetIfTable" and process the output. And about linux?! UI have to install some software ?!

Thanks everyone

Kennedy
09-03-2009, 02:33 PM
Translating. . .

How do I get my IP addresses on all of my network cards in Linux?
Easy, at the command prompt type:
ifconfigIn windows you can do about the same thing from the cmd prompt (Start->run-> Then type cmd and click okay)
ipconfig /all

If this ain't wha'jer lookin fer, I ain't got no clue.

hosseinyounesi
09-03-2009, 02:44 PM
Thanks,
I have to use a program to do that!!! What is "ifstat" ?!

Kennedy
09-03-2009, 03:54 PM
EDIT: What do you mean you have to use a program to do that???? ifconfig IS a program.



fd = socket(AF_INET, SOCK_DGRAM, 0);
strcpy(ifr.ifr_name, devname);
ifr.ifr_addr.sa_family = AF_INET;
ioctl(fd, SIOCGIFADDR, &ifr);
sin = (struct sockaddr_in *) &ifr.ifr_addr;
I dug this out of the vault.

You'll have to figure it out from there.

hosseinyounesi
09-03-2009, 05:04 PM
Thanks,
I mean that I have to write a software and I need to get nic traffic!!! Clear?
But what the code you've written is ?!!!! :(

tabstop
09-03-2009, 05:20 PM
Thanks,
I have to use a program to do that!!! What is "ifstat" ?!
Why not ask man?

Thanks,
I mean that I have to write a software and I need to get nic traffic!!! Clear?

No. Do you need to actually talk to the nic yourself, or are you just interested in using the network? (Maybe I'm just out of the loop, but I don't associate "traffic" with "writing a driver to talk to a piece of hardware".)

hosseinyounesi
09-03-2009, 05:23 PM
I need the send/receive of each interfaces :cool:

Kennedy
09-03-2009, 08:28 PM
Your English is not that good, or you just don't know how to express yourself. The bottom line is it is NOT clear what you are asking for.

If you need to get all network packets, you don't have to write software to do that. It is available in the Linux kernel. You'll have to configure network packet filter (iptables) and write rules that log all network traffic on each network interface.

If you are attempting to tell us that you have some project for school, then at least let us know what your requirements are. Just saying "I need send/receive of each interfaces" is NOT enough information. I can send and receive from each interface with hundreds of tools, Firefox to name one.

What are your requirements and what is your goal? Though English may not be your native language, you could always give us a 1000 word dissertation on the subject (a picture is worth a thousand words).

hosseinyounesi
09-04-2009, 09:01 AM
Thanks, But I think that you don't understand my question! I said that I've used "GetIfTable" to collect information in windows. I introduced ifstat, ...
By the way, Excuse me if I didn't ask my question clearly :(
This is not homework :) I want to use it for my software! I want to collect the send/receive of my COMPUTER (all interfaces) such as what we can see by right clicking on the connection icon in the taskbar of Windows XP ;) I could do this by "GetIfTable" in windows. My question is that how can I do this in Linux? CLEAR? (Tell me If any of sentences is not right)

Thanks again

MK27
09-04-2009, 09:05 AM
So what's wrong with ifconfig, which was suggested in post #2?



eth0 Link encap:Ethernet HWaddr 00:E0:4D:89:B5:73
inet addr:192.168.1.2 Bcast:192.168.1.255 Mask:255.255.255.0
UP BROADCAST RUNNING MULTICAST MTU:1500 Metric:1
RX packets:5792 errors:0 dropped:0 overruns:0 frame:0
TX packets:6309 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:1000
RX bytes:4451227 (4.2 MiB) TX bytes:1435602 (1.3 MiB)
Interrupt:23 Base address:0x8000

lo Link encap:Local Loopback
inet addr:127.0.0.1 Mask:255.0.0.0
UP LOOPBACK RUNNING MTU:16436 Metric:1
RX packets:354 errors:0 dropped:0 overruns:0 frame:0
TX packets:354 errors:0 dropped:0 overruns:0 carrier:0
collisions:0 txqueuelen:0
RX bytes:180029 (175.8 KiB) TX bytes:180029 (175.8 KiB)


I believe RX is short for "received" and TX is short for "transmitted".

hosseinyounesi
09-04-2009, 03:55 PM
yes, but isn't there any function or library that can be used in C or C++ ?!

MK27
09-04-2009, 04:04 PM
yes, but isn't there any function or library that can be used in C or C++ ?!

I think pcap() will provide you with that info too, but really I look at that and see that it will take about 10 lines of code to parse, so why bother using a library?

There are probably a cazillion little GUI apps around for this stuff, eg, it is one thing that the incredibly awesome gkrellm covers, if you learn to use one of those new "search engines" everyone talks about, such as "google.com" you might find something...

tabstop
09-04-2009, 04:06 PM
So I went here (http://linux.die.net), clicked on section 3 of the manual which is where the library functions are, then scrolled down to I and looked for things that started with if. Some of them look like what you want.

MK27
09-04-2009, 04:10 PM
So I went here (http://linux.die.net), clicked on section 3 of the manual which is where the library functions are, then scrolled down to I and looked for things that started with if. Some of them look like what you want.

Yes, if you are using a web browser "ctrl-f" will help. Research is just like coding, the more you do it, the easier it gets.

hosseinyounesi
09-05-2009, 02:42 PM
I know what is "google" !!!!!! I hope that you are joking :) I just thought that maybe someone has did this before :(
I will report my attempt here about libpcap and ifstat or ...

Thanks again

hosseinyounesi
09-05-2009, 07:48 PM
Hi everyone, At last I found it :cool: "/proc/net/dev" is what I need. This file consists of some counters for each interface, each one counts the number of packets (and bytes). ifconfig uses this file too, but after parsing it.The parser can be found here:

The Linux /proc Filesystem as a Programmers' Tool (http://www.linuxjournal.com/article/8381)
Also There are some software that do the network traffic monitoring (for JUST the purpose I have) such as ifstat and bwm-ng.

The other tool that can be used is, sysctl. It can be used on every Free-BSD based systems.