popen()

This is a discussion on popen() within the Windows Programming forums, part of the Platform Specific Boards category; I'm trying to do some parsing on netstat's output, but this is proving rather difficult...: So far, popen() has me ...

  1. #1
    int x = *((int *) NULL); Cactus_Hugger's Avatar
    Join Date
    Jul 2003
    Location
    Banks of the River Styx
    Posts
    902

    popen()

    I'm trying to do some parsing on netstat's output, but this is proving rather difficult...:

    So far, popen() has me baffled. As far as I can tell from the snippit below, popen is returning NULL, and errno is set to zero. (Which makes no sense.) What is going on here?

    Code:
    	ph = popen("netstat -e", "r");
    	if(!ph)
    	{
    		sprintf(err, "Error is %d. ph = %d\n", errno, ph);
    		MessageBox(HWND_DESKTOP, "popen failed.", "popen", MB_OK);
    		MessageBox(HWND_DESKTOP, err, err, MB_OK);
    		return;
    	}
    (function continues..., or would, if popen() would succeed...)
    Since all I really care about is the bytes sent & recv'd... is there an easier way to get those numbers? Some API call I know nothing about?
    long time; /* know C? */
    Unprecedented performance: Nothing ever ran this slow before.
    Any sufficiently advanced bug is indistinguishable from a feature.
    Real Programmers confuse Halloween and Christmas, because dec 25 == oct 31.
    The best way to accelerate an IBM is at 9.8 m/s/s.
    recursion (re - cur' - zhun) n. 1. (see recursion)

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    Perhaps the health warning here explains.
    Note The _popen function returns an invalid file handle, if used in a Windows program, that will cause the program to hang indefinitely. _popen works properly in a Console application. To create a Win
    > Some API call I know nothing about?
    Almost certainly, probably the ones netstat uses itself.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Yes, my avatar is stolen anonytmouse's Avatar
    Join Date
    Dec 2002
    Posts
    2,544
    You could use GetIfTable, which will give you the number of bytes sent and received for each interface. Netstat appears to use GetIpStatsFromStackEx, which is undocumented.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. popen and fgets, underflow!
    By henrikstolpe in forum Linux Programming
    Replies: 0
    Last Post: 02-06-2009, 03:39 AM
  2. popen takes too long?
    By Largo in forum C Programming
    Replies: 2
    Last Post: 11-20-2006, 06:46 AM
  3. popen and fseek
    By mach5 in forum C Programming
    Replies: 4
    Last Post: 11-29-2003, 02:03 AM
  4. popen vs fopen
    By esme in forum Linux Programming
    Replies: 1
    Last Post: 11-25-2002, 10:37 AM

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