[Winpcap-users] Compilation Error - Send queues

Gianluca Varenni gianluca.varenni at cacetech.com
Tue May 2 16:45:38 GMT 2006


After I sent the mail, another possible issue came to my mind.

You should *not* include "win32-extensions.h" and "remote-ext.h" directly. Those are private include files. You should just include pcap.h, and add the preprocessor definitions WPCAP and HAVE_REMOTE to automatically include the remote extensions and the win32 winpcap specific extensions.

If you don't define those preprocessor definitions and include those header files directly, you'll end up having linking issues because of some function name decoration issues between C and C++ (long story...)

Have a nice day
GV

  ----- Original Message ----- 
  From: Marta Perez 
  To: winpcap-users at winpcap.org 
  Sent: Tuesday, May 02, 2006 9:19 AM
  Subject: Re: [Winpcap-users] Compilation Error - Send queues


  Thanks Gianluca,
    This morning I made the change you suggested, but then I got all the following errors (and assumed this wasn't right):

  SendQWin32 error LNK2019: unresolved external symbol "int __cdecl pcap_sendqueue_queue(struct pcap_send_queue *,struct pcap_pkthdr const *,unsigned char const *)" (?pcap_sendqueue_queue@@YAHPAUpcap_send_queue@@PBUpcap_pkthdr@@PBE at Z) referenced in function _main
  SendQWin32 error LNK2019: unresolved external symbol "struct pcap_send_queue * __cdecl pcap_sendqueue_alloc(unsigned int)" (?pcap_sendqueue_alloc@@YAPAUpcap_send_queue@@I at Z) referenced in function _main
  SendQWin32 error LNK2019: unresolved external symbol "unsigned int __cdecl pcap_sendqueue_transmit(struct pcap *,struct pcap_send_queue *,int)" (?pcap_sendqueue_transmit@@YAIPAUpcap@@PAUpcap_send_queue@@H at Z) referenced in function _main
  SendQWin32 error LNK2019: unresolved external symbol "void __cdecl pcap_sendqueue_destroy(struct pcap_send_queue *)" (?pcap_sendqueue_destroy@@YAXPAUpcap_send_queue@@@Z) referenced in function _main

  I might be totally wrong, but it sounds like I am missing out some #include directives...

  Thanks in advance,
  Marta

  Gianluca Varenni <gianluca.varenni at cacetech.com> wrote:
    Marta,

    it's a known bug in the documentation (due to a "const" qualifier that was added to the prototype of pcap_next_ex(), without reflecting the change to the samples).

    Here is the patch to solve your problem (marked with <------)

    int caplen,
    sync;
    u_int res;
    pcap_send_queue *squeue;
    struct pcap_pkthdr *pktheader;
    const u_char *pktdata;      <------
    /* Check the validity of the command line */
    if (argc <= 2 || argc >= 5)
    {
    usage();
    return 0;
    }

    Have a nice day
    GV




      ----- Original Message ----- 
      From: Marta Perez 
      To: winpcap-users at winpcap.org 
      Sent: Monday, May 01, 2006 7:03 AM
      Subject: [Winpcap-users] Compilation Error - Send queues


      Hello everybody,
         I am having problems with the compilation of the example code found in:
      http://www.winpcap.org/docs/man/html/group__wpcap__tut8.html
      Precisely, the first example  (sendpacket()) is fine; the problem is with send queues' code example. I tried both VS 6.0 and .NET2003. These are the errors I am getting:

      VS6.0:
      error C2664: 'pcap_next_ex' : cannot convert parameter 3 from 'unsigned char ** ' to 'const unsigned char ** '
              Conversion loses qualifiers

      .NET2003:
      error C2664: 'pcap_next_ex' : cannot convert parameter 3 from 'u_char **__w64  ' to 'const u_char ** '

      The code is exactly the one in the tutorial because I usually start by getting the example code to work and then modify what needs to be modified.

      I am really working in .NET2003, but I also tried VS6.0 just to make sure it was not a small mistake I might have overlooked. Any help with be greatly appreciated,
      Marta

      P.S: Just in case, here it is my code

      #include "stdafx.h"
      #include <stdlib.h>
      #include <stdio.h>
      #include <pcap.h>
      #include <Win32-Extensions.h>
      #include <remote-ext.h>
      void usage();
      int _tmain(int argc, _TCHAR* argv[])
      {
      pcap_t *indesc,*outdesc;
      char error[PCAP_ERRBUF_SIZE];
      FILE *capfile;
      int caplen,
      sync;
      u_int res;
      pcap_send_queue *squeue;
      struct pcap_pkthdr *pktheader;
      u_char *pktdata;
      /* Check the validity of the command line */
      if (argc <= 2 || argc >= 5)
      {
      usage();
      return 0;
      }
      /* Retrieve the length of the capture file */
      capfile=fopen(argv[1],"rb");
      if(!capfile){
      printf("Capture file not found!\n");
      return 0;
      }
      fseek(capfile , 0, SEEK_END);
      caplen= ftell(capfile)- sizeof(struct pcap_file_header);
      fclose(capfile);
      /* Chek if the timestamps must be respected */
      if(argc == 4 && argv[3][0] == 's')
      sync = TRUE;
      else
      sync = FALSE;
      /* Open the capture */
      if((indesc = pcap_open_offline(argv[1], error)) == NULL){
      fprintf(stderr,"\nError opening the input file: %s\n", error);
      return 0; 
      }
      /* Open the output adapter */
      if((outdesc = pcap_open_live(argv[2], 100, 1, 1000, error) ) == NULL)
      {
      fprintf(stderr,"\nError opening adapter: %s\n", error);
      return 0;
      }
      /* Check the MAC type */
      if(pcap_datalink(indesc) != pcap_datalink(outdesc)){
      printf("Warning: the datalink of the capture differs from the one of the selected interface.\n");
      printf("Press a key to continue, or CTRL+C to stop.\n");
      getchar();
      }
      /* Allocate a send queue */
      squeue = pcap_sendqueue_alloc(caplen);
      /* Fill the queue with the packets from the file */
      while((res = pcap_next_ex( indesc, &pktheader, &pktdata)) == 1){
      if(pcap_sendqueue_queue(squeue, pktheader, pktdata) == -1){
      printf("Warning: packet buffer too small, not all the packets will be sent.\n");
      break;
      }
      }
      if(res == -1){
      printf("Corrupted input file.\n");
      pcap_sendqueue_destroy(squeue);
      return 0;
      }
      /* Transmit the queue */
      if((res = pcap_sendqueue_transmit(outdesc, squeue, sync)) < squeue->len)
      {
      printf("An error occurred sending the packets: %s. Only %d bytes were sent\n", error, res);
      }
      /* free the send queue */
      pcap_sendqueue_destroy(squeue);
      return 0;
      }
      void usage()
      {
      printf("\nSendcap, sends a libpcap/tcpdump capture file to the net. Copyright (C) 2002 Loris Degioanni.\n");
      printf("\nUsage:\n");
      printf("\t sendcap file_name adapter [s]\n");
      printf("\nParameters:\n");
      printf("\nfile_name: the name of the dump file that will be sent to the network\n");
      printf("\nadapter: the device to use. Use \"WinDump -D\" for a list of valid devices\n");
      printf("\ns: if present, forces the packets to be sent synchronously, i.e. respecting the timestamps in the dump file. This option will work only under Windows NTx.\n\n");
      exit(0);
      }

      __________________________________________________
      Do You Yahoo!?
      Tired of spam? Yahoo! Mail has the best spam protection around 
      http://mail.yahoo.com 

--------------------------------------------------------------------------

      _______________________________________________
      Winpcap-users mailing list
      Winpcap-users at winpcap.org
      https://www.winpcap.org/mailman/listinfo/winpcap-users

    _______________________________________________
    Winpcap-users mailing list
    Winpcap-users at winpcap.org
    https://www.winpcap.org/mailman/listinfo/winpcap-users





------------------------------------------------------------------------------
  Share your photos with the people who matter at Yahoo! Canada Photos


------------------------------------------------------------------------------


  _______________________________________________
  Winpcap-users mailing list
  Winpcap-users at winpcap.org
  https://www.winpcap.org/mailman/listinfo/winpcap-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20060502/4f369410/attachment.htm


More information about the Winpcap-users mailing list