0
votes

I'm trying to compile some example C code with GCC/MinGW on Windows 7. The example code includes some local header files which ultimately include stdio.h, and I get this error when I try to compile:

c:\mingw\include\stdio.h:345:12: error: expected '=', ',', ';', 'asm' or '__attribute__' before '__mingw__snprintf'
extern int __mingw_stdio_redirect__(snprintf)(char*, size_t, const char*, ...);

This is a weird one to me. How could there possibly be errors in stdio.h?

1
There could be something in a file included before "stdio.h" that confuses the compiler. Do you still get the error if you try to compile just one file that includes "stdio.h" first? - Tim Randall
Please post the contents of the header file pcap.h Please do NOT post links to code, rather copy/paste the code into your question - user3629249
there are only two valid signatures for main() they are: int main( void ) and int main( int argc, char *argv[] ) - user3629249
Please post a minimal reproducible example so we can reproduce the problem and help you debug it - user3629249
@user3629249: the file pcap.h (and, for that matter, the sample code) are part of the winpcap code bundle, not the work of OP. So your comment about main prototypes is not as well-directed as it could be. - rici

1 Answers

0
votes

regarding:

if (i == 0)
{
    printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
    return 0;
}  
pcap_freealldevs(alldevs);

since the variable i is initialized to 0 and never modified, this if() statement will always be true. One result is the call to: pcap_freealldev() will never be called.

the scope of variables should be limited as much as reasonable.

Code should never depend on the OS to clean up after itself. suggest

#include <stdio.h>
#include <stdlib.h>
#include "pcap.h"

int main( void )
{
    pcap_if_t *alldevs = NULL;
    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( pcap_if_t *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 ( ! alldevs )
    {
        printf("\nNo interfaces found! Make sure WinPcap is installed.\n");
    }

    /* We don't need any more the device list. Free it */
    pcap_freealldevs(alldevs);
}