Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 620771
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T18:48:01+00:00 2026-05-13T18:48:01+00:00

I’m experimenting with WinPcap 4.1.1 libraries for Windows, but I can’t manage to compile

  • 0

I’m experimenting with WinPcap 4.1.1 libraries for Windows, but I can’t manage to compile even example source provided with the library.

I’m getting these errors:

‘PCAP_OPENFLAG_PROMISCUOUS’ undeclared (first use in this function)
‘PCAP_SRC_IF_STRING’ undeclared (first use in this function)

And bunch of warnings:

implicit declaration of function ‘localtime_s’
implicit declaration of function ‘pcap_findalldevs_ex’
implicit declaration of function ‘pcap_open’
implicit declaration of function ‘scanf_s’

I Googled up a bit and found that I should add a line #define HAVE_REMOTE (I have no clue what does it do) but it leads in much more errors like this:

undefined reference to ‘pcap_open’
undefined reference to ‘pcap_findalldevs_ex’
undefined reference to ‘localtime_s’

The "pcap.h" seems to be included properly (eclipse does not report any including errors).
I have copied the *.lib files into MinGW/lib direcotry and set this path in the Path and Symbols->Library Paths (eclipse project properties)

I have no idea what to try next. Any ideas are welcome.
Thanks in advance

Here’s the code:

#include "pcap.h"

/* prototype of the packet handler */
void packet_handler(u_char *param, const struct pcap_pkthdr *header,
const u_char *pkt_data);

int main()
{
pcap_if_t *alldevs;
pcap_if_t *d;
int inum;
int i=0;
pcap_t *adhandle;
char errbuf[PCAP_ERRBUF_SIZE];

       /* Retrieve the device list on the local machine */
       if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL, &alldevs, errbuf) == -1)
       {
               fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
               exit(1);
       }

       /* Print the list */
       for(d=alldevs; d; 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 -1;
       }

       printf("Enter the interface number (1-%d):",i);
       scanf_s("%d", &inum);

       if(inum < 1 || inum > i)
       {
               printf("\nInterface number out of range.\n");
               /* Free the device list */
               pcap_freealldevs(alldevs);
               return -1;
       }

       /* Jump to the selected adapter */
       for(d=alldevs, i=0; i< inum-1 ;d=d->next, i++);

       /* Open the device */
       if ( (adhandle= pcap_open(d->name,                      // name of the device
                                                         65536,                        // portion of the packet to capture
                                                                                               // 65536 guarantees that the whole packet will be captured
on all the link layers
                                                         PCAP_OPENFLAG_PROMISCUOUS,    // promiscuous mode
                                                         1000,                         // read timeout
                                                         NULL,                         // authentication on the remote machine
                                                         errbuf                        // error buffer
                                                         ) ) == NULL)
       {
               fprintf(stderr,"\nUnable to open the adapter. %s is not supported by
WinPcap\n", d->name);
               /* Free the device list */
               pcap_freealldevs(alldevs);
               return -1;
       }

       printf("\nlistening on %s...\n", d->description);

       /* At this point, we don't need any more the device list. Free it */
       pcap_freealldevs(alldevs);

       /* start the capture */
       pcap_loop(adhandle, 0, packet_handler, NULL);

       return 0;
}


/* Callback function invoked by libpcap for every incoming packet */
void packet_handler(u_char *param, const struct pcap_pkthdr *header,
const u_char *pkt_data)
{
       struct tm ltime;
       char timestr[16];
       time_t local_tv_sec;

       /*
        * unused variables
        */
       (VOID)(param);
       (VOID)(pkt_data);

       /* convert the timestamp to readable format */
       local_tv_sec = header->ts.tv_sec;
       localtime_s(&ltime, &local_tv_sec);
       strftime( timestr, sizeof timestr, "%H:%M:%S", &ltime);

       printf("%s,%.6d len:%d\n", timestr, header->ts.tv_usec, header->len);

}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T18:48:02+00:00Added an answer on May 13, 2026 at 6:48 pm

    You can replace your localtime_s call with:

    localtime_r(&local_tv_sec, &ltime);
    

    (Note the swapped arguments.)

    Also, replace your scanf_s call with scanf.

    localtime_s() and scanf_s() are Microsoft-specific extensions, and are not available in MinGW.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a .ini file as follows: [playlist] numberofentries=2 File1=http://87.230.82.17:80 Title1=(#1 - 365/1400) Example
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
Seemingly simple, but I cannot find anything relevant on the web. What is the
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
Does anyone know how can I replace this 2 symbol below from the string

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.