]> The Tcpdump Group git mirrors - libpcap/blob - pcap-win32.c
From Patrick Marie <[email protected]>: add support for port ranges
[libpcap] / pcap-win32.c
1 /*
2 * Copyright (c) 1999 - 2003
3 * NetGroup, Politecnico di Torino (Italy)
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 *
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. Neither the name of the Politecnico di Torino nor the names of its
16 * contributors may be used to endorse or promote products derived from
17 * this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 */
32
33 #ifndef lint
34 static const char rcsid[] _U_ =
35 "@(#) $Header: /tcpdump/master/libpcap/pcap-win32.c,v 1.25 2005-02-26 21:58:06 guy Exp $ (LBL)";
36 #endif
37
38 #include <pcap-int.h>
39 #include <packet32.h>
40 #include <Ntddndis.h>
41 #ifdef HAVE_DAG_API
42 #include <dagnew.h>
43 #include <dagapi.h>
44 #endif /* HAVE_DAG_API */
45 #ifdef __MINGW32__
46 int* _errno();
47 #define errno (*_errno())
48 #endif /* __MINGW32__ */
49
50 static int pcap_setfilter_win32_npf(pcap_t *, struct bpf_program *);
51 static int pcap_setfilter_win32_dag(pcap_t *, struct bpf_program *);
52 static int pcap_getnonblock_win32(pcap_t *, char *);
53 static int pcap_setnonblock_win32(pcap_t *, int, char *);
54
55 #define PcapBufSize 256000 /*dimension of the buffer in the pcap_t structure*/
56 #define SIZE_BUF 1000000
57
58 /* Equivalent to ntohs(), but a lot faster under Windows */
59 #define SWAPS(_X) ((_X & 0xff) << 8) | (_X >> 8)
60
61 /*
62 * Header that the WinPcap driver associates to the packets.
63 * Once was in bpf.h
64 */
65 struct bpf_hdr {
66 struct timeval bh_tstamp; /* time stamp */
67 bpf_u_int32 bh_caplen; /* length of captured portion */
68 bpf_u_int32 bh_datalen; /* original length of packet */
69 u_short bh_hdrlen; /* length of bpf header (this struct
70 plus alignment padding) */
71 };
72
73 /* Start winsock */
74 int
75 wsockinit()
76 {
77 WORD wVersionRequested;
78 WSADATA wsaData;
79 int err;
80 wVersionRequested = MAKEWORD( 1, 1);
81 err = WSAStartup( wVersionRequested, &wsaData );
82 if ( err != 0 )
83 {
84 return -1;
85 }
86 return 0;
87 }
88
89
90 static int
91 pcap_stats_win32(pcap_t *p, struct pcap_stat *ps)
92 {
93
94 if(PacketGetStats(p->adapter, (struct bpf_stat*)ps) != TRUE){
95 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "PacketGetStats error: %s", pcap_win32strerror());
96 return -1;
97 }
98
99 return 0;
100 }
101
102 static int
103 pcap_read_win32_npf(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
104 {
105 int cc;
106 int n = 0;
107 register u_char *bp, *ep;
108
109 cc = p->cc;
110 if (p->cc == 0) {
111 /*
112 * Has "pcap_breakloop()" been called?
113 */
114 if (p->break_loop) {
115 /*
116 * Yes - clear the flag that indicates that it
117 * has, and return -2 to indicate that we were
118 * told to break out of the loop.
119 */
120 p->break_loop = 0;
121 return (-2);
122 }
123
124 /* capture the packets */
125 if(PacketReceivePacket(p->adapter,p->Packet,TRUE)==FALSE){
126 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
127 return (-1);
128 }
129
130 cc = p->Packet->ulBytesReceived;
131
132 bp = p->Packet->Buffer;
133 }
134 else
135 bp = p->bp;
136
137 /*
138 * Loop through each packet.
139 */
140 #define bhp ((struct bpf_hdr *)bp)
141 ep = bp + cc;
142 while (1) {
143 register int caplen, hdrlen;
144
145 /*
146 * Has "pcap_breakloop()" been called?
147 * If so, return immediately - if we haven't read any
148 * packets, clear the flag and return -2 to indicate
149 * that we were told to break out of the loop, otherwise
150 * leave the flag set, so that the *next* call will break
151 * out of the loop without having read any packets, and
152 * return the number of packets we've processed so far.
153 */
154 if (p->break_loop) {
155 if (n == 0) {
156 p->break_loop = 0;
157 return (-2);
158 } else {
159 p->bp = bp;
160 p->cc = ep - bp;
161 return (n);
162 }
163 }
164 if (bp >= ep)
165 break;
166
167 caplen = bhp->bh_caplen;
168 hdrlen = bhp->bh_hdrlen;
169
170 /*
171 * XXX A bpf_hdr matches a pcap_pkthdr.
172 */
173 (*callback)(user, (struct pcap_pkthdr*)bp, bp + hdrlen);
174 bp += BPF_WORDALIGN(caplen + hdrlen);
175 if (++n >= cnt && cnt > 0) {
176 p->bp = bp;
177 p->cc = ep - bp;
178 return (n);
179 }
180 }
181 #undef bhp
182 p->cc = 0;
183 return (n);
184 }
185
186 #ifdef HAVE_DAG_API
187 static int
188 pcap_read_win32_dag(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
189 {
190 u_char *dp = NULL;
191 int packet_len = 0, caplen = 0;
192 struct pcap_pkthdr pcap_header;
193 u_char *endofbuf;
194 int n = 0;
195 dag_record_t *header;
196 unsigned erf_record_len;
197 ULONGLONG ts;
198 int cc;
199 unsigned swt;
200 unsigned dfp = p->adapter->DagFastProcess;
201
202 cc = p->cc;
203 if (cc == 0) /* Get new packets only if we have processed all the ones of the previous read */
204 {
205 /* Get new packets from the network */
206 if(PacketReceivePacket(p->adapter, p->Packet, TRUE)==FALSE){
207 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "read error: PacketReceivePacket failed");
208 return (-1);
209 }
210
211 cc = p->Packet->ulBytesReceived;
212 if(cc == 0)
213 /* The timeout has expired but we no packets arrived */
214 return 0;
215 header = (dag_record_t*)p->adapter->DagBuffer;
216 }
217 else
218 header = (dag_record_t*)p->bp;
219
220 endofbuf = (char*)header + cc;
221
222 /*
223 * Cycle through the packets
224 */
225 do
226 {
227 erf_record_len = SWAPS(header->rlen);
228 if((char*)header + erf_record_len > endofbuf)
229 break;
230
231 /* Increase the number of captured packets */
232 p->md.stat.ps_recv++;
233
234 /* Find the beginning of the packet */
235 dp = ((u_char *)header) + dag_record_size;
236
237 /* Determine actual packet len */
238 switch(header->type)
239 {
240 case TYPE_ATM:
241 packet_len = ATM_SNAPLEN;
242 caplen = ATM_SNAPLEN;
243 dp += 4;
244
245 break;
246
247 case TYPE_ETH:
248 swt = SWAPS(header->wlen);
249 packet_len = swt - (p->md.dag_fcs_bits);
250 caplen = erf_record_len - dag_record_size - 2;
251 if (caplen > packet_len)
252 {
253 caplen = packet_len;
254 }
255 dp += 2;
256
257 break;
258
259 case TYPE_HDLC_POS:
260 swt = SWAPS(header->wlen);
261 packet_len = swt - (p->md.dag_fcs_bits);
262 caplen = erf_record_len - dag_record_size;
263 if (caplen > packet_len)
264 {
265 caplen = packet_len;
266 }
267
268 break;
269 }
270
271 if(caplen > p->snapshot)
272 caplen = p->snapshot;
273
274 /*
275 * Has "pcap_breakloop()" been called?
276 * If so, return immediately - if we haven't read any
277 * packets, clear the flag and return -2 to indicate
278 * that we were told to break out of the loop, otherwise
279 * leave the flag set, so that the *next* call will break
280 * out of the loop without having read any packets, and
281 * return the number of packets we've processed so far.
282 */
283 if (p->break_loop)
284 {
285 if (n == 0)
286 {
287 p->break_loop = 0;
288 return (-2);
289 }
290 else
291 {
292 p->bp = (char*)header;
293 p->cc = endofbuf - (char*)header;
294 return (n);
295 }
296 }
297
298 if(!dfp)
299 {
300 /* convert between timestamp formats */
301 ts = header->ts;
302 pcap_header.ts.tv_sec = (int)(ts >> 32);
303 ts = (ts & 0xffffffffi64) * 1000000;
304 ts += 0x80000000; /* rounding */
305 pcap_header.ts.tv_usec = (int)(ts >> 32);
306 if (pcap_header.ts.tv_usec >= 1000000) {
307 pcap_header.ts.tv_usec -= 1000000;
308 pcap_header.ts.tv_sec++;
309 }
310 }
311
312 /* No underlaying filtering system. We need to filter on our own */
313 if (p->fcode.bf_insns)
314 {
315 if (bpf_filter(p->fcode.bf_insns, dp, packet_len, caplen) == 0)
316 {
317 /* Move to next packet */
318 header = (dag_record_t*)((char*)header + erf_record_len);
319 continue;
320 }
321 }
322
323 /* Fill the header for the user suppplied callback function */
324 pcap_header.caplen = caplen;
325 pcap_header.len = packet_len;
326
327 /* Call the callback function */
328 (*callback)(user, &pcap_header, dp);
329
330 /* Move to next packet */
331 header = (dag_record_t*)((char*)header + erf_record_len);
332
333 /* Stop if the number of packets requested by user has been reached*/
334 if (++n >= cnt && cnt > 0)
335 {
336 p->bp = (char*)header;
337 p->cc = endofbuf - (char*)header;
338 return (n);
339 }
340 }
341 while((u_char*)header < endofbuf);
342
343 return 1;
344 }
345 #endif /* HAVE_DAG_API */
346
347 /* Send a packet to the network */
348 static int
349 pcap_inject_win32(pcap_t *p, const void *buf, size_t size){
350 LPPACKET PacketToSend;
351
352 PacketToSend=PacketAllocatePacket();
353
354 if (PacketToSend == NULL)
355 {
356 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketAllocatePacket failed");
357 return -1;
358 }
359
360 PacketInitPacket(PacketToSend,(PVOID)buf,size);
361 if(PacketSendPacket(p->adapter,PacketToSend,TRUE) == FALSE){
362 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "send error: PacketSendPacket failed");
363 PacketFreePacket(PacketToSend);
364 return -1;
365 }
366
367 PacketFreePacket(PacketToSend);
368
369 /*
370 * We assume it all got sent if "PacketSendPacket()" succeeded.
371 * "pcap_inject()" is expected to return the number of bytes
372 * sent.
373 */
374 return size;
375 }
376
377 static void
378 pcap_close_win32(pcap_t *p)
379 {
380 pcap_close_common(p);
381 if (p->adapter != NULL) {
382 PacketCloseAdapter(p->adapter);
383 p->adapter = NULL;
384 }
385 if (p->Packet) {
386 PacketFreePacket(p->Packet);
387 p->Packet = NULL;
388 }
389 }
390
391 pcap_t *
392 pcap_open_live(const char *device, int snaplen, int promisc, int to_ms,
393 char *ebuf)
394 {
395 register pcap_t *p;
396 NetType type;
397
398 /* Init WinSock */
399 wsockinit();
400
401 p = (pcap_t *)malloc(sizeof(*p));
402 if (p == NULL)
403 {
404 snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
405 return (NULL);
406 }
407 memset(p, 0, sizeof(*p));
408 p->adapter=NULL;
409
410 p->adapter = PacketOpenAdapter((char*)device);
411
412 if (p->adapter == NULL)
413 {
414 /* Adapter detected but we are not able to open it. Return failure. */
415 snprintf(ebuf, PCAP_ERRBUF_SIZE, "Error opening adapter: %s", pcap_win32strerror());
416 return NULL;
417 }
418
419 /*get network type*/
420 if(PacketGetNetType (p->adapter,&type) == FALSE)
421 {
422 snprintf(ebuf, PCAP_ERRBUF_SIZE, "Cannot determine the network type: %s", pcap_win32strerror());
423 goto bad;
424 }
425
426 /*Set the linktype*/
427 switch (type.LinkType)
428 {
429 case NdisMediumWan:
430 p->linktype = DLT_EN10MB;
431 break;
432
433 case NdisMedium802_3:
434 p->linktype = DLT_EN10MB;
435 /*
436 * This is (presumably) a real Ethernet capture; give it a
437 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
438 * that an application can let you choose it, in case you're
439 * capturing DOCSIS traffic that a Cisco Cable Modem
440 * Termination System is putting out onto an Ethernet (it
441 * doesn't put an Ethernet header onto the wire, it puts raw
442 * DOCSIS frames out on the wire inside the low-level
443 * Ethernet framing).
444 */
445 p->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
446 /*
447 * If that fails, just leave the list empty.
448 */
449 if (p->dlt_list != NULL) {
450 p->dlt_list[0] = DLT_EN10MB;
451 p->dlt_list[1] = DLT_DOCSIS;
452 p->dlt_count = 2;
453 }
454 break;
455
456 case NdisMediumFddi:
457 p->linktype = DLT_FDDI;
458 break;
459
460 case NdisMedium802_5:
461 p->linktype = DLT_IEEE802;
462 break;
463
464 case NdisMediumArcnetRaw:
465 p->linktype = DLT_ARCNET;
466 break;
467
468 case NdisMediumArcnet878_2:
469 p->linktype = DLT_ARCNET;
470 break;
471
472 case NdisMediumAtm:
473 p->linktype = DLT_ATM_RFC1483;
474 break;
475
476 case NdisMediumCHDLC:
477 p->linktype = DLT_CHDLC;
478 break;
479
480 case NdisMediumPPPSerial:
481 p->linktype = DLT_PPP_SERIAL;
482 break;
483
484 case NdisMediumNull:
485 p->linktype = DLT_NULL;
486 break;
487
488 default:
489 p->linktype = DLT_EN10MB; /*an unknown adapter is assumed to be ethernet*/
490 break;
491 }
492
493 /* Set promisquous mode */
494 if (promisc) PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_PROMISCUOUS);
495 else PacketSetHwFilter(p->adapter,NDIS_PACKET_TYPE_ALL_LOCAL);
496
497 /* Set the buffer size */
498 p->bufsize = PcapBufSize;
499
500 /* allocate Packet structure used during the capture */
501 if((p->Packet = PacketAllocatePacket())==NULL)
502 {
503 snprintf(ebuf, PCAP_ERRBUF_SIZE, "failed to allocate the PACKET structure");
504 goto bad;
505 }
506
507 if(!(p->adapter->Flags & INFO_FLAG_DAG_CARD))
508 {
509 /*
510 * Traditional Adapter
511 */
512
513 p->buffer = (u_char *)malloc(PcapBufSize);
514 if (p->buffer == NULL)
515 {
516 snprintf(ebuf, PCAP_ERRBUF_SIZE, "malloc: %s", pcap_strerror(errno));
517 goto bad;
518 }
519
520 PacketInitPacket(p->Packet,(BYTE*)p->buffer,p->bufsize);
521
522 p->snapshot = snaplen;
523
524 /* allocate the standard buffer in the driver */
525 if(PacketSetBuff( p->adapter, SIZE_BUF)==FALSE)
526 {
527 snprintf(ebuf, PCAP_ERRBUF_SIZE,"driver error: not enough memory to allocate the kernel buffer\n");
528 goto bad;
529 }
530
531 /* tell the driver to copy the buffer only if it contains at least 16K */
532 if(PacketSetMinToCopy(p->adapter,16000)==FALSE)
533 {
534 snprintf(ebuf, PCAP_ERRBUF_SIZE,"Error calling PacketSetMinToCopy: %s\n", pcap_win32strerror());
535 goto bad;
536 }
537 }
538 else
539 #ifdef HAVE_DAG_API
540 {
541 /*
542 * Dag Card
543 */
544 LONG status;
545 HKEY dagkey;
546 DWORD lptype;
547 DWORD lpcbdata;
548 int postype = 0;
549 char keyname[512];
550
551 snprintf(keyname, sizeof(keyname), "%s\\CardParams\\%s",
552 "SYSTEM\\CurrentControlSet\\Services\\DAG",
553 strstr(_strlwr((char*)device), "dag"));
554 do
555 {
556 status = RegOpenKeyEx(HKEY_LOCAL_MACHINE, keyname, 0, KEY_READ, &dagkey);
557 if(status != ERROR_SUCCESS)
558 break;
559
560 status = RegQueryValueEx(dagkey,
561 "PosType",
562 NULL,
563 &lptype,
564 (char*)&postype,
565 &lpcbdata);
566
567 if(status != ERROR_SUCCESS)
568 {
569 postype = 0;
570 }
571
572 RegCloseKey(dagkey);
573 }
574 while(FALSE);
575
576
577 p->snapshot = PacketSetSnapLen(p->adapter, snaplen);
578
579 /* Set the length of the FCS associated to any packet. This value
580 * will be subtracted to the packet length */
581 p->md.dag_fcs_bits = p->adapter->DagFcsLen;
582 }
583 #else
584 goto bad;
585 #endif /* HAVE_DAG_API */
586
587 PacketSetReadTimeout(p->adapter, to_ms);
588
589 #ifdef HAVE_DAG_API
590 if(p->adapter->Flags & INFO_FLAG_DAG_CARD)
591 {
592 /* install dag specific handlers for read and setfilter */
593 p->read_op = pcap_read_win32_dag;
594 p->setfilter_op = pcap_setfilter_win32_dag;
595 }
596 else
597 {
598 #endif /* HAVE_DAG_API */
599 /* install traditional npf handlers for read and setfilter */
600 p->read_op = pcap_read_win32_npf;
601 p->setfilter_op = pcap_setfilter_win32_npf;
602 #ifdef HAVE_DAG_API
603 }
604 #endif /* HAVE_DAG_API */
605 p->inject_op = pcap_inject_win32;
606 p->set_datalink_op = NULL; /* can't change data link type */
607 p->getnonblock_op = pcap_getnonblock_win32;
608 p->setnonblock_op = pcap_setnonblock_win32;
609 p->stats_op = pcap_stats_win32;
610 p->close_op = pcap_close_win32;
611
612 return (p);
613 bad:
614 if (p->adapter)
615 PacketCloseAdapter(p->adapter);
616 if (p->buffer != NULL)
617 free(p->buffer);
618 if(p->Packet)
619 PacketFreePacket(p->Packet);
620 /*
621 * Get rid of any link-layer type list we allocated.
622 */
623 if (p->dlt_list != NULL)
624 free(p->dlt_list);
625 free(p);
626 return (NULL);
627 }
628
629
630 static int
631 pcap_setfilter_win32_npf(pcap_t *p, struct bpf_program *fp)
632 {
633 if(PacketSetBpf(p->adapter,fp)==FALSE){
634 /*
635 * Kernel filter not installed.
636 * XXX - fall back on userland filtering, as is done
637 * on other platforms?
638 */
639 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Driver error: cannot set bpf filter: %s", pcap_win32strerror());
640 return (-1);
641 }
642
643 /*
644 * Discard any previously-received packets, as they might have
645 * passed whatever filter was formerly in effect, but might
646 * not pass this filter (BIOCSETF discards packets buffered
647 * in the kernel, so you can lose packets in any case).
648 */
649 p->cc = 0;
650 return (0);
651 }
652
653 /*
654 * We filter at user level, since the kernel driver does't process the packets
655 */
656 static int
657 pcap_setfilter_win32_dag(pcap_t *p, struct bpf_program *fp) {
658
659 if(!fp)
660 {
661 strncpy(p->errbuf, "setfilter: No filter specified", sizeof(p->errbuf));
662 return -1;
663 }
664
665 /* Install a user level filter */
666 if (install_bpf_program(p, fp) < 0)
667 {
668 snprintf(p->errbuf, sizeof(p->errbuf),
669 "setfilter, unable to install the filter: %s", pcap_strerror(errno));
670 return -1;
671 }
672
673 p->md.use_bpf = 0;
674
675 return (0);
676 }
677
678 static int
679 pcap_getnonblock_win32(pcap_t *p, char *errbuf)
680 {
681 /*
682 * XXX - if there were a PacketGetReadTimeout() call, we
683 * would use it, and return 1 if the timeout is -1
684 * and 0 otherwise.
685 */
686 return (p->nonblock);
687 }
688
689 static int
690 pcap_setnonblock_win32(pcap_t *p, int nonblock, char *errbuf)
691 {
692 int newtimeout;
693
694 if (nonblock) {
695 /*
696 * Set the read timeout to -1 for non-blocking mode.
697 */
698 newtimeout = -1;
699 } else {
700 /*
701 * Restore the timeout set when the device was opened.
702 * (Note that this may be -1, in which case we're not
703 * really leaving non-blocking mode.)
704 */
705 newtimeout = p->timeout;
706 }
707 if (!PacketSetReadTimeout(p->adapter, newtimeout)) {
708 snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
709 "PacketSetReadTimeout: %s", pcap_win32strerror());
710 return (-1);
711 }
712 p->nonblock = (newtimeout == -1);
713 return (0);
714 }
715
716 /* Set the driver working mode */
717 int
718 pcap_setmode(pcap_t *p, int mode){
719
720 if (p->adapter==NULL)
721 {
722 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "impossible to set mode while reading from a file");
723 return -1;
724 }
725
726 if(PacketSetMode(p->adapter,mode)==FALSE)
727 {
728 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: working mode not recognized");
729 return -1;
730 }
731
732 return 0;
733 }
734
735 /* Set the dimension of the kernel-level capture buffer */
736 int
737 pcap_setbuff(pcap_t *p, int dim)
738 {
739 if (p->adapter==NULL)
740 {
741 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "The kernel buffer size cannot be set while reading from a file");
742 return -1;
743 }
744
745 if(PacketSetBuff(p->adapter,dim)==FALSE)
746 {
747 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: not enough memory to allocate the kernel buffer");
748 return -1;
749 }
750 return 0;
751 }
752
753 /*set the minimum amount of data that will release a read call*/
754 int
755 pcap_setmintocopy(pcap_t *p, int size)
756 {
757 if (p->adapter==NULL)
758 {
759 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "Impossible to set the mintocopy parameter on an offline capture");
760 return -1;
761 }
762
763 if(PacketSetMinToCopy(p->adapter, size)==FALSE)
764 {
765 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, "driver error: unable to set the requested mintocopy size");
766 return -1;
767 }
768 return 0;
769 }