Thread: Simple winpcap shows "process returned 0 <0x0>"

  1. #1
    Registered User
    Join Date
    Feb 2016
    Posts
    37

    Simple winpcap shows "process returned 0 <0x0>"

    Code:
    #include "pcap.h"
    
    void main()
    {
        pcap_if_t *alldevs;
        pcap_if_t *d;
        int i=0;
        char errbuf[PCAP_ERRBUF_SIZE];
        /* Retrieve the device list from the local machine */
        if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
        {
            fprintf(stderr,"Error in pcap_findalldevs_ex: %s\n", errbuf);
            exit(1);
        }
        /* Print the list */
        for(d= alldevs; d != NULL; d= d->next)
        {
            printf("%d. %s", ++i, d->name);
            if (d->description)
                printf(" (%s)\n", d->description);
            else
                printf(" (No description available)\n");
        }
        
        if (i == 0)
        {
            printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
            return;
        }
    
        /* We don't need any more the device list. Free it */
        pcap_freealldevs(alldevs);
    }
    What it means? no devices? What error?
    How check alternatively as in linux - ifconfigure?
    But before -- I got error -that if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1) -- that some expression nessesary before ','??

  2. #2
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    Maybe I need to link something else in Winx Xp for Winpcap?

  3. #3
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    Maybe i do not everything correctly. What is the role of rpcapd? Despite after launching this server my app again returns 0. What is exact procedure to launch the wincap?

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    35,295
    > "process returned 0 <0x0>"
    This just means the process fell off the end of main, and the exit status was 0.

    Which is pure dumb luck on your part since you declared main as returning void rather than int.

    The rest doesn't make any sense either.

    > that if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1) -- that some expression nessesary before ','??
    This suggests a compilation failure.

    > What it means? no devices? What error?
    How about copy/pasting what you actually see on screen?

    > pcap_freealldevs(alldevs);
    This should be done before you bail out in case of no devices found.
    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.

  5. #5
    Registered User
    Join Date
    Feb 2016
    Posts
    37

    1

    Could you rewrite code to be correctly? It returns what I provided so in such case the compilation succeded. The issue of Colon was resolved. I also commented freealldevices but nothing changed. And I do not think that changing return type to int change something. Moreover this sample is from official samples of wincap libraries that also should be located on wincap official site.

  6. #6
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    35,295
    I don't have windows.
    I don't have pcap installed.

    It's up to you to write and debug code, and provide accurate information to the rest of us.

    For example, I've still no idea what you actually see on screen.
    At least nothing which accurately maps to the printf lines in your code.

    > I also commented freealldevices but nothing changed.
    Well internally, the library would have returned to a consistent state with no memory leaks.

    > And I do not think that changing return type to int change something.
    Well it makes the program startup correct, as opposed to merely "works for me".

    > Moreover this sample is from official samples of wincap libraries that also should be located on wincap official site.
    You have to realise there is a lot of crap code on the web, even from people who ought to know better.
    Publishing it doesn't make it right.
    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.

  7. #7
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    Black screen of console: Process returned 0 execution time: 0.563 s Press any key to continue -- it is when int main(). When void main() -- process returned 10692353 execution time: 0.125 s....// are there people that handled winpcap, and especially this simple first example?

  8. #8
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    As far as I see no printf is invoked. For example if i put if(i!=0) or as it is provided (i==0) the "no interface found" is neither displayed. So I do not understand what the code is going through the run-time? Do device list are filled, if so why there is no its description?

  9. #9
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    if(pcap_alldev)... if(!(pcap_alldev) all the same

  10. #10
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    35,295
    > Process returned 0 execution time: 0.563 s Press any key to continue -- it is when int main().
    > When void main() -- process returned 10692353 execution time: 0.125 s
    Well this at least seems to prove you're compiling the code each time.

    However, the lack of any other kind of printf output is disturbing.
    Given that it seems to be achieving a normal exit, there doesn't appear to be any route through the code which results in nothing being printed.

    By chance, have you edited your IDE configuration to save the output of the console to a text file instead of printing to stdout?
    Check your run settings.

    Or try to run the executable from a separate console window outside the IDE.
    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.

  11. #11
    Registered User
    Join Date
    Feb 2016
    Posts
    37

    2

    That is all output. So how to make output to text file? Despite I have doubts that something would change. And what run settings you mean? I should also note when I tried to compile and run the simplest app in qt on codeblocks i have some test output despite yet qt was not configured. So maybe there is some testing tool for validity of winpcap. And one more question. In linux we can check libpcap traffic by tcpdump so what to use in windows xp?

  12. #12
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    Why this code do not works:
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    //#include <libnet.h>
    int main()
    {
        unsigned char f[12] ="B25678C57F3E";
        //u_char* ff=(u_char*)malloc(17*sizeof(u_char));
        unsigned char ff[17];
        int k=sizeof(f)/sizeof(f[0]);
        int kk=0;
        int i=0;
        for (i=0; i<k;i++) {
        if ((i==2)||(i==4)||(i==6)||(i==8)||(i==10)) {ff[i+kk]=":";
        kk++; }
        else ff[i+kk]=f[i];
        }
        printf("%i\n",k);
        printf(f);
        printf("\n");
        printf(ff);
        return 0;
    }

  13. #13
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    35,295
    Presumably because you neither allocate space for a \0, store a \0 or using printf with a proper format string.
    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.

  14. #14
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    It should be some kind of problems in settings of CodeBlocks, as even simple code
    Code:
    #include <stdio.h>
    #include <string.h>
    #include <stdlib.h>
    int main()
    {
        int f=2;
        printf("%i\n",f);
        return 0;
    }
    returns not 2, but process returned 0 <0x0>. But it doesnt means that Winpcap is set correctly on my pc, as when I compile and run abovementioned Winpcap code in Qtcreator (after creating simple only C project), I got nothing as in Codeblocks, despite I linked winpcap Include and Lib folder to qt *.pro file.

  15. #15
    Registered User
    Join Date
    Feb 2016
    Posts
    37
    No clear, no rebuild in Codeblocks

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A "Simple" Array/String Problem. "Help" ASAP needed
    By AirulFmy in forum C Programming
    Replies: 10
    Last Post: 08-19-2015, 04:30 AM
  2. Replies: 2
    Last Post: 03-26-2015, 08:52 AM
  3. Replies: 3
    Last Post: 03-02-2013, 08:21 PM
  4. Replies: 2
    Last Post: 08-07-2012, 11:18 AM
  5. "itoa"-"_itoa" , "inp"-"_inp", Why some functions have "
    By L.O.K. in forum Windows Programming
    Replies: 5
    Last Post: 12-08-2002, 07:25 AM
Website Security Test