Network Interface Card Traffic

This is a discussion on Network Interface Card Traffic within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I want to get send/receive of my PC NICs in Linux?! For windows I can use "GetIfTable" and process ...

  1. #1
    Registered User
    Join Date
    Jul 2009
    Posts
    61

    Question Network Interface Card Traffic

    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

  2. #2
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    Translating. . .
    Quote Originally Posted by hosseinyounesi
    How do I get my IP addresses on all of my network cards in Linux?
    Easy, at the command prompt type:
    Code:
    ifconfig
    In windows you can do about the same thing from the cmd prompt (Start->run-> Then type cmd and click okay)
    Code:
    ipconfig /all
    If this ain't wha'jer lookin fer, I ain't got no clue.

  3. #3
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    Thanks,
    I have to use a program to do that!!! What is "ifstat" ?!

  4. #4
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    EDIT: What do you mean you have to use a program to do that???? ifconfig IS a program.


    Code:
            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.

  5. #5
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    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 ?!!!!

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Quote Originally Posted by hosseinyounesi View Post
    Thanks,
    I have to use a program to do that!!! What is "ifstat" ?!
    Why not ask man?
    Quote Originally Posted by hosseinyounesi View Post
    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".)

  7. #7
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    I need the send/receive of each interfaces

  8. #8
    {Jaxom,Imriel,Liam}'s Dad Kennedy's Avatar
    Join Date
    Aug 2006
    Location
    Alabama
    Posts
    1,065
    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).

  9. #9
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    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

  10. #10
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    So what's wrong with ifconfig, which was suggested in post #2?

    Code:
    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".
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  11. #11
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    yes, but isn't there any function or library that can be used in C or C++ ?!

  12. #12
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by hosseinyounesi View Post
    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...
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  13. #13
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    So I went here, 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.

  14. #14
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    Quote Originally Posted by tabstop View Post
    So I went here, 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.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  15. #15
    Registered User
    Join Date
    Jul 2009
    Posts
    61
    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

Page 1 of 2 12 LastLast
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Bitwise Unwanted Output
    By pobri19 in forum C++ Programming
    Replies: 4
    Last Post: 09-15-2008, 05:07 AM
  2. Vector out of range program crash.
    By Shamino in forum C++ Programming
    Replies: 11
    Last Post: 01-18-2008, 05:37 PM
  3. Segmentation Fault - aaaaaaaah!
    By yogibear in forum C Programming
    Replies: 6
    Last Post: 10-01-2007, 04:21 AM
  4. Blackjack
    By Tommo in forum C Programming
    Replies: 10
    Last Post: 06-20-2007, 09:07 PM
  5. How can I access a struct (from a header file)?
    By loxslay in forum C++ Programming
    Replies: 3
    Last Post: 10-07-2006, 02:25 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21