2 * Copyright (c) 1993, 1994, 1995, 1996, 1997, 1998
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the Computer Systems
16 * Engineering Group at Lawrence Berkeley Laboratory.
17 * 4. Neither the name of the University nor of the Laboratory may be used
18 * to endorse or promote products derived from this software without
19 * specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <pcap-stdinc.h>
46 #ifdef HAVE_SYS_BITYPES_H
47 #include <sys/bitypes.h>
49 #include <sys/types.h>
55 #if !defined(_MSC_VER) && !defined(__BORLANDC__) && !defined(__MINGW32__)
61 #ifdef HAVE_OS_PROTO_H
73 #endif /* HAVE_DAG_API */
75 #ifdef HAVE_SEPTEL_API
76 #include "pcap-septel.h"
77 #endif /* HAVE_SEPTEL_API */
81 #endif /* HAVE_SNF_API */
85 #endif /* HAVE_TC_API */
87 #ifdef PCAP_SUPPORT_USB
88 #include "pcap-usb-linux.h"
91 #ifdef PCAP_SUPPORT_BT
92 #include "pcap-bt-linux.h"
95 #ifdef PCAP_SUPPORT_BT_MONITOR
96 #include "pcap-bt-monitor-linux.h"
99 #ifdef PCAP_SUPPORT_CAN
100 #include "pcap-can-linux.h"
103 #ifdef PCAP_SUPPORT_CANUSB
104 #include "pcap-canusb-linux.h"
107 #ifdef PCAP_SUPPORT_NETFILTER
108 #include "pcap-netfilter-linux.h"
111 #ifdef PCAP_SUPPORT_DBUS
112 #include "pcap-dbus.h"
116 pcap_not_initialized(pcap_t
*pcap
)
118 /* in case the caller doesn't check for PCAP_ERROR_NOT_ACTIVATED */
119 (void)pcap_snprintf(pcap
->errbuf
, sizeof(pcap
->errbuf
),
120 "This handle hasn't been activated yet");
121 /* this means 'not initialized' */
122 return (PCAP_ERROR_NOT_ACTIVATED
);
127 pcap_not_initialized_ptr(pcap_t
*pcap
)
129 (void)pcap_snprintf(pcap
->errbuf
, sizeof(pcap
->errbuf
),
130 "This handle hasn't been activated yet");
135 pcap_getevent_not_initialized(pcap_t
*pcap
)
137 (void)pcap_snprintf(pcap
->errbuf
, sizeof(pcap
->errbuf
),
138 "This handle hasn't been activated yet");
139 return (INVALID_HANDLE_VALUE
);
143 pcap_sendqueue_transmit_not_initialized(pcap_t
*pcap
, pcap_send_queue
* queue
, int sync
)
145 (void)pcap_snprintf(pcap
->errbuf
, sizeof(pcap
->errbuf
),
146 "This handle hasn't been activated yet");
150 static PAirpcapHandle
151 pcap_get_airpcap_handle_not_initialized(pcap_t
*pcap
)
153 (void)pcap_snprintf(pcap
->errbuf
, sizeof(pcap
->errbuf
),
154 "This handle hasn't been activated yet");
160 * Returns 1 if rfmon mode can be set on the pcap_t, 0 if it can't,
161 * a PCAP_ERROR value on an error.
164 pcap_can_set_rfmon(pcap_t
*p
)
166 return (p
->can_set_rfmon_op(p
));
170 * For systems where rfmon mode is never supported.
173 pcap_cant_set_rfmon(pcap_t
*p _U_
)
179 * Sets *tstamp_typesp to point to an array 1 or more supported time stamp
180 * types; the return value is the number of supported time stamp types.
181 * The list should be freed by a call to pcap_free_tstamp_types() when
182 * you're done with it.
184 * A return value of 0 means "you don't get a choice of time stamp type",
185 * in which case *tstamp_typesp is set to null.
187 * PCAP_ERROR is returned on error.
190 pcap_list_tstamp_types(pcap_t
*p
, int **tstamp_typesp
)
192 if (p
->tstamp_type_count
== 0) {
194 * We don't support multiple time stamp types.
196 *tstamp_typesp
= NULL
;
198 *tstamp_typesp
= (int*)calloc(sizeof(**tstamp_typesp
),
199 p
->tstamp_type_count
);
200 if (*tstamp_typesp
== NULL
) {
201 (void)pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
202 "malloc: %s", pcap_strerror(errno
));
205 (void)memcpy(*tstamp_typesp
, p
->tstamp_type_list
,
206 sizeof(**tstamp_typesp
) * p
->tstamp_type_count
);
208 return (p
->tstamp_type_count
);
212 * In Windows, you might have a library built with one version of the
213 * C runtime library and an application built with another version of
214 * the C runtime library, which means that the library might use one
215 * version of malloc() and free() and the application might use another
216 * version of malloc() and free(). If so, that means something
217 * allocated by the library cannot be freed by the application, so we
218 * need to have a pcap_free_tstamp_types() routine to free up the list
219 * allocated by pcap_list_tstamp_types(), even though it's just a wrapper
223 pcap_free_tstamp_types(int *tstamp_type_list
)
225 free(tstamp_type_list
);
229 * Default one-shot callback; overridden for capture types where the
230 * packet data cannot be guaranteed to be available after the callback
231 * returns, so that a copy must be made.
234 pcap_oneshot(u_char
*user
, const struct pcap_pkthdr
*h
, const u_char
*pkt
)
236 struct oneshot_userdata
*sp
= (struct oneshot_userdata
*)user
;
243 pcap_next(pcap_t
*p
, struct pcap_pkthdr
*h
)
245 struct oneshot_userdata s
;
251 if (pcap_dispatch(p
, 1, p
->oneshot_callback
, (u_char
*)&s
) <= 0)
257 pcap_next_ex(pcap_t
*p
, struct pcap_pkthdr
**pkt_header
,
258 const u_char
**pkt_data
)
260 struct oneshot_userdata s
;
262 s
.hdr
= &p
->pcap_header
;
266 /* Saves a pointer to the packet headers */
267 *pkt_header
= &p
->pcap_header
;
269 if (p
->rfile
!= NULL
) {
272 /* We are on an offline capture */
273 status
= pcap_offline_read(p
, 1, p
->oneshot_callback
,
277 * Return codes for pcap_offline_read() are:
281 * The first one ('0') conflicts with the return code of
282 * 0 from pcap_read() meaning "no packets arrived before
283 * the timeout expired", so we map it to -2 so you can
284 * distinguish between an EOF from a savefile and a
285 * "no packets arrived before the timeout expired, try
286 * again" from a live capture.
295 * Return codes for pcap_read() are:
298 * - -2: loop was broken out of with pcap_breakloop()
300 * The first one ('0') conflicts with the return code of 0 from
301 * pcap_offline_read() meaning "end of file".
303 return (p
->read_op(p
, 1, p
->oneshot_callback
, (u_char
*)&s
));
306 #if defined(DAG_ONLY)
308 pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
310 return (dag_findalldevs(alldevsp
, errbuf
));
314 pcap_create(const char *source
, char *errbuf
)
317 return (dag_create(source
, errbuf
, &is_ours
));
319 #elif defined(SEPTEL_ONLY)
321 pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
323 return (septel_findalldevs(alldevsp
, errbuf
));
327 pcap_create(const char *source
, char *errbuf
)
330 return (septel_create(source
, errbuf
, &is_ours
));
332 #elif defined(SNF_ONLY)
334 pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
336 return (snf_findalldevs(alldevsp
, errbuf
));
340 pcap_create(const char *source
, char *errbuf
)
343 return (snf_create(source
, errbuf
, &is_ours
));
345 #else /* regular pcap */
346 struct capture_source_type
{
347 int (*findalldevs_op
)(pcap_if_t
**, char *);
348 pcap_t
*(*create_op
)(const char *, char *, int *);
349 } capture_source_types
[] = {
351 { dag_findalldevs
, dag_create
},
353 #ifdef HAVE_SEPTEL_API
354 { septel_findalldevs
, septel_create
},
357 { snf_findalldevs
, snf_create
},
360 { TcFindAllDevs
, TcCreate
},
362 #ifdef PCAP_SUPPORT_BT
363 { bt_findalldevs
, bt_create
},
365 #ifdef PCAP_SUPPORT_BT_MONITOR
366 { bt_monitor_findalldevs
, bt_monitor_create
},
368 #if PCAP_SUPPORT_CANUSB
369 { canusb_findalldevs
, canusb_create
},
371 #ifdef PCAP_SUPPORT_CAN
372 { can_findalldevs
, can_create
},
374 #ifdef PCAP_SUPPORT_USB
375 { usb_findalldevs
, usb_create
},
377 #ifdef PCAP_SUPPORT_NETFILTER
378 { netfilter_findalldevs
, netfilter_create
},
380 #ifdef PCAP_SUPPORT_DBUS
381 { dbus_findalldevs
, dbus_create
},
387 * Get a list of all capture sources that are up and that we can open.
388 * Returns -1 on error, 0 otherwise.
389 * The list, as returned through "alldevsp", may be null if no interfaces
390 * were up and could be opened.
393 pcap_findalldevs(pcap_if_t
**alldevsp
, char *errbuf
)
398 * Get the list of regular interfaces first.
400 if (pcap_findalldevs_interfaces(alldevsp
, errbuf
) == -1)
401 return (-1); /* failure */
404 * Add any interfaces that need a platform-specific mechanism
407 if (pcap_platform_finddevs(alldevsp
, errbuf
) == -1) {
409 * We had an error; free the list we've been
412 if (*alldevsp
!= NULL
) {
413 pcap_freealldevs(*alldevsp
);
420 * Ask each of the non-local-network-interface capture
421 * source types what interfaces they have.
423 for (i
= 0; capture_source_types
[i
].findalldevs_op
!= NULL
; i
++) {
424 if (capture_source_types
[i
].findalldevs_op(alldevsp
, errbuf
) == -1) {
426 * We had an error; free the list we've been
429 if (*alldevsp
!= NULL
) {
430 pcap_freealldevs(*alldevsp
);
441 pcap_create(const char *source
, char *errbuf
)
448 * A null source name is equivalent to the "any" device -
449 * which might not be supported on this platform, but
450 * this means that you'll get a "not supported" error
451 * rather than, say, a crash when we try to dereference
458 * Try each of the non-local-network-interface capture
459 * source types until we find one that works for this
460 * device or run out of types.
462 for (i
= 0; capture_source_types
[i
].create_op
!= NULL
; i
++) {
464 p
= capture_source_types
[i
].create_op(source
, errbuf
, &is_theirs
);
467 * The device name refers to a device of the
468 * type in question; either it succeeded,
469 * in which case p refers to a pcap_t to
470 * later activate for the device, or it
471 * failed, in which case p is null and we
472 * should return that to report the failure
480 * OK, try it as a regular network interface.
482 return (pcap_create_interface(source
, errbuf
));
487 initialize_ops(pcap_t
*p
)
490 * Set operation pointers for operations that only work on
491 * an activated pcap_t to point to a routine that returns
492 * a "this isn't activated" error.
494 p
->read_op
= (read_op_t
)pcap_not_initialized
;
495 p
->inject_op
= (inject_op_t
)pcap_not_initialized
;
496 p
->setfilter_op
= (setfilter_op_t
)pcap_not_initialized
;
497 p
->setdirection_op
= (setdirection_op_t
)pcap_not_initialized
;
498 p
->set_datalink_op
= (set_datalink_op_t
)pcap_not_initialized
;
499 p
->getnonblock_op
= (getnonblock_op_t
)pcap_not_initialized
;
500 p
->setnonblock_op
= (setnonblock_op_t
)pcap_not_initialized
;
501 p
->stats_op
= (stats_op_t
)pcap_not_initialized
;
503 p
->stats_ex_op
= (stats_ex_op_t
)pcap_not_initialized_ptr
;
504 p
->setbuff_op
= (setbuff_op_t
)pcap_not_initialized
;
505 p
->setmode_op
= (setmode_op_t
)pcap_not_initialized
;
506 p
->setmintocopy_op
= (setmintocopy_op_t
)pcap_not_initialized
;
507 p
->getevent_op
= pcap_getevent_not_initialized
;
508 p
->oid_get_request_op
= (oid_get_request_op_t
)pcap_not_initialized
;
509 p
->oid_set_request_op
= (oid_set_request_op_t
)pcap_not_initialized
;
510 p
->sendqueue_transmit_op
= pcap_sendqueue_transmit_not_initialized
;
511 p
->setuserbuffer_op
= (setuserbuffer_op_t
)pcap_not_initialized
;
512 p
->live_dump_op
= (live_dump_op_t
)pcap_not_initialized
;
513 p
->live_dump_ended_op
= (live_dump_ended_op_t
)pcap_not_initialized
;
514 p
->get_airpcap_handle_op
= pcap_get_airpcap_handle_not_initialized
;
518 * Default cleanup operation - implementations can override
519 * this, but should call pcap_cleanup_live_common() after
520 * doing their own additional cleanup.
522 p
->cleanup_op
= pcap_cleanup_live_common
;
525 * In most cases, the standard one-shot callback can
526 * be used for pcap_next()/pcap_next_ex().
528 p
->oneshot_callback
= pcap_oneshot
;
532 pcap_alloc_pcap_t(char *ebuf
, size_t size
)
538 * Allocate a chunk of memory big enough for a pcap_t
539 * plus a structure following it of size "size". The
540 * structure following it is a private data structure
541 * for the routines that handle this pcap_t.
543 chunk
= malloc(sizeof (pcap_t
) + size
);
545 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "malloc: %s",
546 pcap_strerror(errno
));
549 memset(chunk
, 0, sizeof (pcap_t
) + size
);
552 * Get a pointer to the pcap_t at the beginning.
557 p
->fd
= -1; /* not opened yet */
558 p
->selectable_fd
= -1;
562 /* No private data was requested. */
566 * Set the pointer to the private data; that's the structure
567 * of size "size" following the pcap_t.
569 p
->priv
= (void *)(chunk
+ sizeof (pcap_t
));
576 pcap_create_common(const char *source
, char *ebuf
, size_t size
)
580 p
= pcap_alloc_pcap_t(ebuf
, size
);
584 p
->opt
.source
= strdup(source
);
585 if (p
->opt
.source
== NULL
) {
586 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "malloc: %s",
587 pcap_strerror(errno
));
593 * Default to "can't set rfmon mode"; if it's supported by
594 * a platform, the create routine that called us can set
595 * the op to its routine to check whether a particular
596 * device supports it.
598 p
->can_set_rfmon_op
= pcap_cant_set_rfmon
;
602 /* put in some defaults*/
603 pcap_set_snaplen(p
, MAXIMUM_SNAPLEN
); /* max packet size */
604 p
->opt
.timeout
= 0; /* no timeout specified */
605 p
->opt
.buffer_size
= 0; /* use the platform's default */
608 p
->opt
.immediate
= 0;
609 p
->opt
.tstamp_type
= -1; /* default to not setting time stamp type */
610 p
->opt
.tstamp_precision
= PCAP_TSTAMP_PRECISION_MICRO
;
613 * Start out with no BPF code generation flags set.
615 p
->bpf_codegen_flags
= 0;
621 pcap_check_activated(pcap_t
*p
)
624 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "can't perform "
625 " operation on activated capture");
632 pcap_set_snaplen(pcap_t
*p
, int snaplen
)
634 if (pcap_check_activated(p
))
635 return (PCAP_ERROR_ACTIVATED
);
636 p
->snapshot
= snaplen
;
641 pcap_set_promisc(pcap_t
*p
, int promisc
)
643 if (pcap_check_activated(p
))
644 return (PCAP_ERROR_ACTIVATED
);
645 p
->opt
.promisc
= promisc
;
650 pcap_set_rfmon(pcap_t
*p
, int rfmon
)
652 if (pcap_check_activated(p
))
653 return (PCAP_ERROR_ACTIVATED
);
654 p
->opt
.rfmon
= rfmon
;
659 pcap_set_timeout(pcap_t
*p
, int timeout_ms
)
661 if (pcap_check_activated(p
))
662 return (PCAP_ERROR_ACTIVATED
);
663 p
->opt
.timeout
= timeout_ms
;
668 pcap_set_tstamp_type(pcap_t
*p
, int tstamp_type
)
672 if (pcap_check_activated(p
))
673 return (PCAP_ERROR_ACTIVATED
);
676 * If p->tstamp_type_count is 0, we only support PCAP_TSTAMP_HOST;
677 * the default time stamp type is PCAP_TSTAMP_HOST.
679 if (p
->tstamp_type_count
== 0) {
680 if (tstamp_type
== PCAP_TSTAMP_HOST
) {
681 p
->opt
.tstamp_type
= tstamp_type
;
686 * Check whether we claim to support this type of time stamp.
688 for (i
= 0; i
< p
->tstamp_type_count
; i
++) {
689 if (p
->tstamp_type_list
[i
] == tstamp_type
) {
693 p
->opt
.tstamp_type
= tstamp_type
;
700 * We don't support this type of time stamp.
702 return (PCAP_WARNING_TSTAMP_TYPE_NOTSUP
);
706 pcap_set_immediate_mode(pcap_t
*p
, int immediate
)
708 if (pcap_check_activated(p
))
709 return (PCAP_ERROR_ACTIVATED
);
710 p
->opt
.immediate
= immediate
;
715 pcap_set_buffer_size(pcap_t
*p
, int buffer_size
)
717 if (pcap_check_activated(p
))
718 return (PCAP_ERROR_ACTIVATED
);
719 p
->opt
.buffer_size
= buffer_size
;
724 pcap_set_tstamp_precision(pcap_t
*p
, int tstamp_precision
)
728 if (pcap_check_activated(p
))
729 return (PCAP_ERROR_ACTIVATED
);
732 * If p->tstamp_precision_count is 0, we only support setting
733 * the time stamp precision to microsecond precision; every
734 * pcap module *MUST* support microsecond precision, even if
735 * it does so by converting the native precision to
738 if (p
->tstamp_precision_count
== 0) {
739 if (tstamp_precision
== PCAP_TSTAMP_PRECISION_MICRO
) {
740 p
->opt
.tstamp_precision
= tstamp_precision
;
745 * Check whether we claim to support this precision of
748 for (i
= 0; i
< p
->tstamp_precision_count
; i
++) {
749 if (p
->tstamp_precision_list
[i
] == tstamp_precision
) {
753 p
->opt
.tstamp_precision
= tstamp_precision
;
760 * We don't support this time stamp precision.
762 return (PCAP_ERROR_TSTAMP_PRECISION_NOTSUP
);
766 pcap_get_tstamp_precision(pcap_t
*p
)
768 return (p
->opt
.tstamp_precision
);
772 pcap_activate(pcap_t
*p
)
777 * Catch attempts to re-activate an already-activated
778 * pcap_t; this should, for example, catch code that
779 * calls pcap_open_live() followed by pcap_activate(),
780 * as some code that showed up in a Stack Exchange
783 if (pcap_check_activated(p
))
784 return (PCAP_ERROR_ACTIVATED
);
785 status
= p
->activate_op(p
);
789 if (p
->errbuf
[0] == '\0') {
791 * No error message supplied by the activate routine;
792 * for the benefit of programs that don't specially
793 * handle errors other than PCAP_ERROR, return the
794 * error message corresponding to the status.
796 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "%s",
797 pcap_statustostr(status
));
801 * Undo any operation pointer setting, etc. done by
802 * the activate operation.
810 pcap_open_live(const char *source
, int snaplen
, int promisc
, int to_ms
, char *errbuf
)
815 p
= pcap_create(source
, errbuf
);
818 status
= pcap_set_snaplen(p
, snaplen
);
821 status
= pcap_set_promisc(p
, promisc
);
824 status
= pcap_set_timeout(p
, to_ms
);
828 * Mark this as opened with pcap_open_live(), so that, for
829 * example, we show the full list of DLT_ values, rather
830 * than just the ones that are compatible with capturing
831 * when not in monitor mode. That allows existing applications
832 * to work the way they used to work, but allows new applications
833 * that know about the new open API to, for example, find out the
834 * DLT_ values that they can select without changing whether
835 * the adapter is in monitor mode or not.
838 status
= pcap_activate(p
);
843 if (status
== PCAP_ERROR
)
844 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "%s: %s", source
,
846 else if (status
== PCAP_ERROR_NO_SUCH_DEVICE
||
847 status
== PCAP_ERROR_PERM_DENIED
||
848 status
== PCAP_ERROR_PROMISC_PERM_DENIED
)
849 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "%s: %s (%s)", source
,
850 pcap_statustostr(status
), p
->errbuf
);
852 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "%s: %s", source
,
853 pcap_statustostr(status
));
859 pcap_open_offline_common(char *ebuf
, size_t size
)
863 p
= pcap_alloc_pcap_t(ebuf
, size
);
867 p
->opt
.tstamp_precision
= PCAP_TSTAMP_PRECISION_MICRO
;
868 p
->opt
.source
= strdup("(savefile)");
869 if (p
->opt
.source
== NULL
) {
870 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "malloc: %s",
871 pcap_strerror(errno
));
880 pcap_dispatch(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
882 return (p
->read_op(p
, cnt
, callback
, user
));
886 pcap_loop(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
891 if (p
->rfile
!= NULL
) {
893 * 0 means EOF, so don't loop if we get 0.
895 n
= pcap_offline_read(p
, cnt
, callback
, user
);
898 * XXX keep reading until we get something
899 * (or an error occurs)
902 n
= p
->read_op(p
, cnt
, callback
, user
);
907 if (!PACKET_COUNT_IS_UNLIMITED(cnt
)) {
916 * Force the loop in "pcap_read()" or "pcap_read_offline()" to terminate.
919 pcap_breakloop(pcap_t
*p
)
925 pcap_datalink(pcap_t
*p
)
928 return (PCAP_ERROR_NOT_ACTIVATED
);
929 return (p
->linktype
);
933 pcap_datalink_ext(pcap_t
*p
)
936 return (PCAP_ERROR_NOT_ACTIVATED
);
937 return (p
->linktype_ext
);
941 pcap_list_datalinks(pcap_t
*p
, int **dlt_buffer
)
944 return (PCAP_ERROR_NOT_ACTIVATED
);
945 if (p
->dlt_count
== 0) {
947 * We couldn't fetch the list of DLTs, which means
948 * this platform doesn't support changing the
949 * DLT for an interface. Return a list of DLTs
950 * containing only the DLT this device supports.
952 *dlt_buffer
= (int*)malloc(sizeof(**dlt_buffer
));
953 if (*dlt_buffer
== NULL
) {
954 (void)pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
955 "malloc: %s", pcap_strerror(errno
));
958 **dlt_buffer
= p
->linktype
;
961 *dlt_buffer
= (int*)calloc(sizeof(**dlt_buffer
), p
->dlt_count
);
962 if (*dlt_buffer
== NULL
) {
963 (void)pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
964 "malloc: %s", pcap_strerror(errno
));
967 (void)memcpy(*dlt_buffer
, p
->dlt_list
,
968 sizeof(**dlt_buffer
) * p
->dlt_count
);
969 return (p
->dlt_count
);
974 * In Windows, you might have a library built with one version of the
975 * C runtime library and an application built with another version of
976 * the C runtime library, which means that the library might use one
977 * version of malloc() and free() and the application might use another
978 * version of malloc() and free(). If so, that means something
979 * allocated by the library cannot be freed by the application, so we
980 * need to have a pcap_free_datalinks() routine to free up the list
981 * allocated by pcap_list_datalinks(), even though it's just a wrapper
985 pcap_free_datalinks(int *dlt_list
)
991 pcap_set_datalink(pcap_t
*p
, int dlt
)
994 const char *dlt_name
;
996 if (p
->dlt_count
== 0 || p
->set_datalink_op
== NULL
) {
998 * We couldn't fetch the list of DLTs, or we don't
999 * have a "set datalink" operation, which means
1000 * this platform doesn't support changing the
1001 * DLT for an interface. Check whether the new
1002 * DLT is the one this interface supports.
1004 if (p
->linktype
!= dlt
)
1008 * It is, so there's nothing we need to do here.
1012 for (i
= 0; i
< p
->dlt_count
; i
++)
1013 if (p
->dlt_list
[i
] == dlt
)
1015 if (i
>= p
->dlt_count
)
1017 if (p
->dlt_count
== 2 && p
->dlt_list
[0] == DLT_EN10MB
&&
1018 dlt
== DLT_DOCSIS
) {
1020 * This is presumably an Ethernet device, as the first
1021 * link-layer type it offers is DLT_EN10MB, and the only
1022 * other type it offers is DLT_DOCSIS. That means that
1023 * we can't tell the driver to supply DOCSIS link-layer
1024 * headers - we're just pretending that's what we're
1025 * getting, as, presumably, we're capturing on a dedicated
1026 * link to a Cisco Cable Modem Termination System, and
1027 * it's putting raw DOCSIS frames on the wire inside low-level
1033 if (p
->set_datalink_op(p
, dlt
) == -1)
1039 dlt_name
= pcap_datalink_val_to_name(dlt
);
1040 if (dlt_name
!= NULL
) {
1041 (void) pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
1042 "%s is not one of the DLTs supported by this device",
1045 (void) pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
1046 "DLT %d is not one of the DLTs supported by this device",
1053 * This array is designed for mapping upper and lower case letter
1054 * together for a case independent comparison. The mappings are
1055 * based upon ascii character sequences.
1057 static const u_char charmap
[] = {
1058 (u_char
)'\000', (u_char
)'\001', (u_char
)'\002', (u_char
)'\003',
1059 (u_char
)'\004', (u_char
)'\005', (u_char
)'\006', (u_char
)'\007',
1060 (u_char
)'\010', (u_char
)'\011', (u_char
)'\012', (u_char
)'\013',
1061 (u_char
)'\014', (u_char
)'\015', (u_char
)'\016', (u_char
)'\017',
1062 (u_char
)'\020', (u_char
)'\021', (u_char
)'\022', (u_char
)'\023',
1063 (u_char
)'\024', (u_char
)'\025', (u_char
)'\026', (u_char
)'\027',
1064 (u_char
)'\030', (u_char
)'\031', (u_char
)'\032', (u_char
)'\033',
1065 (u_char
)'\034', (u_char
)'\035', (u_char
)'\036', (u_char
)'\037',
1066 (u_char
)'\040', (u_char
)'\041', (u_char
)'\042', (u_char
)'\043',
1067 (u_char
)'\044', (u_char
)'\045', (u_char
)'\046', (u_char
)'\047',
1068 (u_char
)'\050', (u_char
)'\051', (u_char
)'\052', (u_char
)'\053',
1069 (u_char
)'\054', (u_char
)'\055', (u_char
)'\056', (u_char
)'\057',
1070 (u_char
)'\060', (u_char
)'\061', (u_char
)'\062', (u_char
)'\063',
1071 (u_char
)'\064', (u_char
)'\065', (u_char
)'\066', (u_char
)'\067',
1072 (u_char
)'\070', (u_char
)'\071', (u_char
)'\072', (u_char
)'\073',
1073 (u_char
)'\074', (u_char
)'\075', (u_char
)'\076', (u_char
)'\077',
1074 (u_char
)'\100', (u_char
)'\141', (u_char
)'\142', (u_char
)'\143',
1075 (u_char
)'\144', (u_char
)'\145', (u_char
)'\146', (u_char
)'\147',
1076 (u_char
)'\150', (u_char
)'\151', (u_char
)'\152', (u_char
)'\153',
1077 (u_char
)'\154', (u_char
)'\155', (u_char
)'\156', (u_char
)'\157',
1078 (u_char
)'\160', (u_char
)'\161', (u_char
)'\162', (u_char
)'\163',
1079 (u_char
)'\164', (u_char
)'\165', (u_char
)'\166', (u_char
)'\167',
1080 (u_char
)'\170', (u_char
)'\171', (u_char
)'\172', (u_char
)'\133',
1081 (u_char
)'\134', (u_char
)'\135', (u_char
)'\136', (u_char
)'\137',
1082 (u_char
)'\140', (u_char
)'\141', (u_char
)'\142', (u_char
)'\143',
1083 (u_char
)'\144', (u_char
)'\145', (u_char
)'\146', (u_char
)'\147',
1084 (u_char
)'\150', (u_char
)'\151', (u_char
)'\152', (u_char
)'\153',
1085 (u_char
)'\154', (u_char
)'\155', (u_char
)'\156', (u_char
)'\157',
1086 (u_char
)'\160', (u_char
)'\161', (u_char
)'\162', (u_char
)'\163',
1087 (u_char
)'\164', (u_char
)'\165', (u_char
)'\166', (u_char
)'\167',
1088 (u_char
)'\170', (u_char
)'\171', (u_char
)'\172', (u_char
)'\173',
1089 (u_char
)'\174', (u_char
)'\175', (u_char
)'\176', (u_char
)'\177',
1090 (u_char
)'\200', (u_char
)'\201', (u_char
)'\202', (u_char
)'\203',
1091 (u_char
)'\204', (u_char
)'\205', (u_char
)'\206', (u_char
)'\207',
1092 (u_char
)'\210', (u_char
)'\211', (u_char
)'\212', (u_char
)'\213',
1093 (u_char
)'\214', (u_char
)'\215', (u_char
)'\216', (u_char
)'\217',
1094 (u_char
)'\220', (u_char
)'\221', (u_char
)'\222', (u_char
)'\223',
1095 (u_char
)'\224', (u_char
)'\225', (u_char
)'\226', (u_char
)'\227',
1096 (u_char
)'\230', (u_char
)'\231', (u_char
)'\232', (u_char
)'\233',
1097 (u_char
)'\234', (u_char
)'\235', (u_char
)'\236', (u_char
)'\237',
1098 (u_char
)'\240', (u_char
)'\241', (u_char
)'\242', (u_char
)'\243',
1099 (u_char
)'\244', (u_char
)'\245', (u_char
)'\246', (u_char
)'\247',
1100 (u_char
)'\250', (u_char
)'\251', (u_char
)'\252', (u_char
)'\253',
1101 (u_char
)'\254', (u_char
)'\255', (u_char
)'\256', (u_char
)'\257',
1102 (u_char
)'\260', (u_char
)'\261', (u_char
)'\262', (u_char
)'\263',
1103 (u_char
)'\264', (u_char
)'\265', (u_char
)'\266', (u_char
)'\267',
1104 (u_char
)'\270', (u_char
)'\271', (u_char
)'\272', (u_char
)'\273',
1105 (u_char
)'\274', (u_char
)'\275', (u_char
)'\276', (u_char
)'\277',
1106 (u_char
)'\300', (u_char
)'\341', (u_char
)'\342', (u_char
)'\343',
1107 (u_char
)'\344', (u_char
)'\345', (u_char
)'\346', (u_char
)'\347',
1108 (u_char
)'\350', (u_char
)'\351', (u_char
)'\352', (u_char
)'\353',
1109 (u_char
)'\354', (u_char
)'\355', (u_char
)'\356', (u_char
)'\357',
1110 (u_char
)'\360', (u_char
)'\361', (u_char
)'\362', (u_char
)'\363',
1111 (u_char
)'\364', (u_char
)'\365', (u_char
)'\366', (u_char
)'\367',
1112 (u_char
)'\370', (u_char
)'\371', (u_char
)'\372', (u_char
)'\333',
1113 (u_char
)'\334', (u_char
)'\335', (u_char
)'\336', (u_char
)'\337',
1114 (u_char
)'\340', (u_char
)'\341', (u_char
)'\342', (u_char
)'\343',
1115 (u_char
)'\344', (u_char
)'\345', (u_char
)'\346', (u_char
)'\347',
1116 (u_char
)'\350', (u_char
)'\351', (u_char
)'\352', (u_char
)'\353',
1117 (u_char
)'\354', (u_char
)'\355', (u_char
)'\356', (u_char
)'\357',
1118 (u_char
)'\360', (u_char
)'\361', (u_char
)'\362', (u_char
)'\363',
1119 (u_char
)'\364', (u_char
)'\365', (u_char
)'\366', (u_char
)'\367',
1120 (u_char
)'\370', (u_char
)'\371', (u_char
)'\372', (u_char
)'\373',
1121 (u_char
)'\374', (u_char
)'\375', (u_char
)'\376', (u_char
)'\377',
1125 pcap_strcasecmp(const char *s1
, const char *s2
)
1127 register const u_char
*cm
= charmap
,
1128 *us1
= (const u_char
*)s1
,
1129 *us2
= (const u_char
*)s2
;
1131 while (cm
[*us1
] == cm
[*us2
++])
1134 return (cm
[*us1
] - cm
[*--us2
]);
1139 const char *description
;
1143 #define DLT_CHOICE(code, description) { #code, description, code }
1144 #define DLT_CHOICE_SENTINEL { NULL, NULL, 0 }
1146 static struct dlt_choice dlt_choices
[] = {
1147 DLT_CHOICE(DLT_NULL
, "BSD loopback"),
1148 DLT_CHOICE(DLT_EN10MB
, "Ethernet"),
1149 DLT_CHOICE(DLT_IEEE802
, "Token ring"),
1150 DLT_CHOICE(DLT_ARCNET
, "BSD ARCNET"),
1151 DLT_CHOICE(DLT_SLIP
, "SLIP"),
1152 DLT_CHOICE(DLT_PPP
, "PPP"),
1153 DLT_CHOICE(DLT_FDDI
, "FDDI"),
1154 DLT_CHOICE(DLT_ATM_RFC1483
, "RFC 1483 LLC-encapsulated ATM"),
1155 DLT_CHOICE(DLT_RAW
, "Raw IP"),
1156 DLT_CHOICE(DLT_SLIP_BSDOS
, "BSD/OS SLIP"),
1157 DLT_CHOICE(DLT_PPP_BSDOS
, "BSD/OS PPP"),
1158 DLT_CHOICE(DLT_ATM_CLIP
, "Linux Classical IP-over-ATM"),
1159 DLT_CHOICE(DLT_PPP_SERIAL
, "PPP over serial"),
1160 DLT_CHOICE(DLT_PPP_ETHER
, "PPPoE"),
1161 DLT_CHOICE(DLT_SYMANTEC_FIREWALL
, "Symantec Firewall"),
1162 DLT_CHOICE(DLT_C_HDLC
, "Cisco HDLC"),
1163 DLT_CHOICE(DLT_IEEE802_11
, "802.11"),
1164 DLT_CHOICE(DLT_FRELAY
, "Frame Relay"),
1165 DLT_CHOICE(DLT_LOOP
, "OpenBSD loopback"),
1166 DLT_CHOICE(DLT_ENC
, "OpenBSD encapsulated IP"),
1167 DLT_CHOICE(DLT_LINUX_SLL
, "Linux cooked"),
1168 DLT_CHOICE(DLT_LTALK
, "Localtalk"),
1169 DLT_CHOICE(DLT_PFLOG
, "OpenBSD pflog file"),
1170 DLT_CHOICE(DLT_PFSYNC
, "Packet filter state syncing"),
1171 DLT_CHOICE(DLT_PRISM_HEADER
, "802.11 plus Prism header"),
1172 DLT_CHOICE(DLT_IP_OVER_FC
, "RFC 2625 IP-over-Fibre Channel"),
1173 DLT_CHOICE(DLT_SUNATM
, "Sun raw ATM"),
1174 DLT_CHOICE(DLT_IEEE802_11_RADIO
, "802.11 plus radiotap header"),
1175 DLT_CHOICE(DLT_ARCNET_LINUX
, "Linux ARCNET"),
1176 DLT_CHOICE(DLT_JUNIPER_MLPPP
, "Juniper Multi-Link PPP"),
1177 DLT_CHOICE(DLT_JUNIPER_MLFR
, "Juniper Multi-Link Frame Relay"),
1178 DLT_CHOICE(DLT_JUNIPER_ES
, "Juniper Encryption Services PIC"),
1179 DLT_CHOICE(DLT_JUNIPER_GGSN
, "Juniper GGSN PIC"),
1180 DLT_CHOICE(DLT_JUNIPER_MFR
, "Juniper FRF.16 Frame Relay"),
1181 DLT_CHOICE(DLT_JUNIPER_ATM2
, "Juniper ATM2 PIC"),
1182 DLT_CHOICE(DLT_JUNIPER_SERVICES
, "Juniper Advanced Services PIC"),
1183 DLT_CHOICE(DLT_JUNIPER_ATM1
, "Juniper ATM1 PIC"),
1184 DLT_CHOICE(DLT_APPLE_IP_OVER_IEEE1394
, "Apple IP-over-IEEE 1394"),
1185 DLT_CHOICE(DLT_MTP2_WITH_PHDR
, "SS7 MTP2 with Pseudo-header"),
1186 DLT_CHOICE(DLT_MTP2
, "SS7 MTP2"),
1187 DLT_CHOICE(DLT_MTP3
, "SS7 MTP3"),
1188 DLT_CHOICE(DLT_SCCP
, "SS7 SCCP"),
1189 DLT_CHOICE(DLT_DOCSIS
, "DOCSIS"),
1190 DLT_CHOICE(DLT_LINUX_IRDA
, "Linux IrDA"),
1191 DLT_CHOICE(DLT_IEEE802_11_RADIO_AVS
, "802.11 plus AVS radio information header"),
1192 DLT_CHOICE(DLT_JUNIPER_MONITOR
, "Juniper Passive Monitor PIC"),
1193 DLT_CHOICE(DLT_BACNET_MS_TP
, "BACnet MS/TP"),
1194 DLT_CHOICE(DLT_PPP_PPPD
, "PPP for pppd, with direction flag"),
1195 DLT_CHOICE(DLT_JUNIPER_PPPOE
, "Juniper PPPoE"),
1196 DLT_CHOICE(DLT_JUNIPER_PPPOE_ATM
, "Juniper PPPoE/ATM"),
1197 DLT_CHOICE(DLT_GPRS_LLC
, "GPRS LLC"),
1198 DLT_CHOICE(DLT_GPF_T
, "GPF-T"),
1199 DLT_CHOICE(DLT_GPF_F
, "GPF-F"),
1200 DLT_CHOICE(DLT_JUNIPER_PIC_PEER
, "Juniper PIC Peer"),
1201 DLT_CHOICE(DLT_ERF_ETH
, "Ethernet with Endace ERF header"),
1202 DLT_CHOICE(DLT_ERF_POS
, "Packet-over-SONET with Endace ERF header"),
1203 DLT_CHOICE(DLT_LINUX_LAPD
, "Linux vISDN LAPD"),
1204 DLT_CHOICE(DLT_JUNIPER_ETHER
, "Juniper Ethernet"),
1205 DLT_CHOICE(DLT_JUNIPER_PPP
, "Juniper PPP"),
1206 DLT_CHOICE(DLT_JUNIPER_FRELAY
, "Juniper Frame Relay"),
1207 DLT_CHOICE(DLT_JUNIPER_CHDLC
, "Juniper C-HDLC"),
1208 DLT_CHOICE(DLT_MFR
, "FRF.16 Frame Relay"),
1209 DLT_CHOICE(DLT_JUNIPER_VP
, "Juniper Voice PIC"),
1210 DLT_CHOICE(DLT_A429
, "Arinc 429"),
1211 DLT_CHOICE(DLT_A653_ICM
, "Arinc 653 Interpartition Communication"),
1212 DLT_CHOICE(DLT_USB
, "USB"),
1213 DLT_CHOICE(DLT_BLUETOOTH_HCI_H4
, "Bluetooth HCI UART transport layer"),
1214 DLT_CHOICE(DLT_IEEE802_16_MAC_CPS
, "IEEE 802.16 MAC Common Part Sublayer"),
1215 DLT_CHOICE(DLT_USB_LINUX
, "USB with Linux header"),
1216 DLT_CHOICE(DLT_CAN20B
, "Controller Area Network (CAN) v. 2.0B"),
1217 DLT_CHOICE(DLT_IEEE802_15_4_LINUX
, "IEEE 802.15.4 with Linux padding"),
1218 DLT_CHOICE(DLT_PPI
, "Per-Packet Information"),
1219 DLT_CHOICE(DLT_IEEE802_16_MAC_CPS_RADIO
, "IEEE 802.16 MAC Common Part Sublayer plus radiotap header"),
1220 DLT_CHOICE(DLT_JUNIPER_ISM
, "Juniper Integrated Service Module"),
1221 DLT_CHOICE(DLT_IEEE802_15_4
, "IEEE 802.15.4 with FCS"),
1222 DLT_CHOICE(DLT_SITA
, "SITA pseudo-header"),
1223 DLT_CHOICE(DLT_ERF
, "Endace ERF header"),
1224 DLT_CHOICE(DLT_RAIF1
, "Ethernet with u10 Networks pseudo-header"),
1225 DLT_CHOICE(DLT_IPMB
, "IPMB"),
1226 DLT_CHOICE(DLT_JUNIPER_ST
, "Juniper Secure Tunnel"),
1227 DLT_CHOICE(DLT_BLUETOOTH_HCI_H4_WITH_PHDR
, "Bluetooth HCI UART transport layer plus pseudo-header"),
1228 DLT_CHOICE(DLT_AX25_KISS
, "AX.25 with KISS header"),
1229 DLT_CHOICE(DLT_IEEE802_15_4_NONASK_PHY
, "IEEE 802.15.4 with non-ASK PHY data"),
1230 DLT_CHOICE(DLT_MPLS
, "MPLS with label as link-layer header"),
1231 DLT_CHOICE(DLT_LINUX_EVDEV
, "Linux evdev events"),
1232 DLT_CHOICE(DLT_USB_LINUX_MMAPPED
, "USB with padded Linux header"),
1233 DLT_CHOICE(DLT_DECT
, "DECT"),
1234 DLT_CHOICE(DLT_AOS
, "AOS Space Data Link protocol"),
1235 DLT_CHOICE(DLT_WIHART
, "Wireless HART"),
1236 DLT_CHOICE(DLT_FC_2
, "Fibre Channel FC-2"),
1237 DLT_CHOICE(DLT_FC_2_WITH_FRAME_DELIMS
, "Fibre Channel FC-2 with frame delimiters"),
1238 DLT_CHOICE(DLT_IPNET
, "Solaris ipnet"),
1239 DLT_CHOICE(DLT_CAN_SOCKETCAN
, "CAN-bus with SocketCAN headers"),
1240 DLT_CHOICE(DLT_IPV4
, "Raw IPv4"),
1241 DLT_CHOICE(DLT_IPV6
, "Raw IPv6"),
1242 DLT_CHOICE(DLT_IEEE802_15_4_NOFCS
, "IEEE 802.15.4 without FCS"),
1243 DLT_CHOICE(DLT_DBUS
, "D-Bus"),
1244 DLT_CHOICE(DLT_JUNIPER_VS
, "Juniper Virtual Server"),
1245 DLT_CHOICE(DLT_JUNIPER_SRX_E2E
, "Juniper SRX E2E"),
1246 DLT_CHOICE(DLT_JUNIPER_FIBRECHANNEL
, "Juniper Fibre Channel"),
1247 DLT_CHOICE(DLT_DVB_CI
, "DVB-CI"),
1248 DLT_CHOICE(DLT_MUX27010
, "MUX27010"),
1249 DLT_CHOICE(DLT_STANAG_5066_D_PDU
, "STANAG 5066 D_PDUs"),
1250 DLT_CHOICE(DLT_JUNIPER_ATM_CEMIC
, "Juniper ATM CEMIC"),
1251 DLT_CHOICE(DLT_NFLOG
, "Linux netfilter log messages"),
1252 DLT_CHOICE(DLT_NETANALYZER
, "Ethernet with Hilscher netANALYZER pseudo-header"),
1253 DLT_CHOICE(DLT_NETANALYZER_TRANSPARENT
, "Ethernet with Hilscher netANALYZER pseudo-header and with preamble and SFD"),
1254 DLT_CHOICE(DLT_IPOIB
, "RFC 4391 IP-over-Infiniband"),
1255 DLT_CHOICE(DLT_MPEG_2_TS
, "MPEG-2 transport stream"),
1256 DLT_CHOICE(DLT_NG40
, "ng40 protocol tester Iub/Iur"),
1257 DLT_CHOICE(DLT_NFC_LLCP
, "NFC LLCP PDUs with pseudo-header"),
1258 DLT_CHOICE(DLT_INFINIBAND
, "InfiniBand"),
1259 DLT_CHOICE(DLT_SCTP
, "SCTP"),
1260 DLT_CHOICE(DLT_USBPCAP
, "USB with USBPcap header"),
1261 DLT_CHOICE(DLT_RTAC_SERIAL
, "Schweitzer Engineering Laboratories RTAC packets"),
1262 DLT_CHOICE(DLT_BLUETOOTH_LE_LL
, "Bluetooth Low Energy air interface"),
1263 DLT_CHOICE(DLT_NETLINK
, "Linux netlink"),
1264 DLT_CHOICE(DLT_BLUETOOTH_LINUX_MONITOR
, "Bluetooth Linux Monitor"),
1265 DLT_CHOICE(DLT_BLUETOOTH_BREDR_BB
, "Bluetooth Basic Rate/Enhanced Data Rate baseband packets"),
1266 DLT_CHOICE(DLT_BLUETOOTH_LE_LL_WITH_PHDR
, "Bluetooth Low Energy air interface with pseudo-header"),
1267 DLT_CHOICE(DLT_PROFIBUS_DL
, "PROFIBUS data link layer"),
1268 DLT_CHOICE(DLT_PKTAP
, "Apple DLT_PKTAP"),
1269 DLT_CHOICE(DLT_EPON
, "Ethernet with 802.3 Clause 65 EPON preamble"),
1274 pcap_datalink_name_to_val(const char *name
)
1278 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
1279 if (pcap_strcasecmp(dlt_choices
[i
].name
+ sizeof("DLT_") - 1,
1281 return (dlt_choices
[i
].dlt
);
1287 pcap_datalink_val_to_name(int dlt
)
1291 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
1292 if (dlt_choices
[i
].dlt
== dlt
)
1293 return (dlt_choices
[i
].name
+ sizeof("DLT_") - 1);
1299 pcap_datalink_val_to_description(int dlt
)
1303 for (i
= 0; dlt_choices
[i
].name
!= NULL
; i
++) {
1304 if (dlt_choices
[i
].dlt
== dlt
)
1305 return (dlt_choices
[i
].description
);
1310 struct tstamp_type_choice
{
1312 const char *description
;
1316 static struct tstamp_type_choice tstamp_type_choices
[] = {
1317 { "host", "Host", PCAP_TSTAMP_HOST
},
1318 { "host_lowprec", "Host, low precision", PCAP_TSTAMP_HOST_LOWPREC
},
1319 { "host_hiprec", "Host, high precision", PCAP_TSTAMP_HOST_HIPREC
},
1320 { "adapter", "Adapter", PCAP_TSTAMP_ADAPTER
},
1321 { "adapter_unsynced", "Adapter, not synced with system time", PCAP_TSTAMP_ADAPTER_UNSYNCED
},
1326 pcap_tstamp_type_name_to_val(const char *name
)
1330 for (i
= 0; tstamp_type_choices
[i
].name
!= NULL
; i
++) {
1331 if (pcap_strcasecmp(tstamp_type_choices
[i
].name
, name
) == 0)
1332 return (tstamp_type_choices
[i
].type
);
1334 return (PCAP_ERROR
);
1338 pcap_tstamp_type_val_to_name(int tstamp_type
)
1342 for (i
= 0; tstamp_type_choices
[i
].name
!= NULL
; i
++) {
1343 if (tstamp_type_choices
[i
].type
== tstamp_type
)
1344 return (tstamp_type_choices
[i
].name
);
1350 pcap_tstamp_type_val_to_description(int tstamp_type
)
1354 for (i
= 0; tstamp_type_choices
[i
].name
!= NULL
; i
++) {
1355 if (tstamp_type_choices
[i
].type
== tstamp_type
)
1356 return (tstamp_type_choices
[i
].description
);
1362 pcap_snapshot(pcap_t
*p
)
1365 return (PCAP_ERROR_NOT_ACTIVATED
);
1366 return (p
->snapshot
);
1370 pcap_is_swapped(pcap_t
*p
)
1373 return (PCAP_ERROR_NOT_ACTIVATED
);
1374 return (p
->swapped
);
1378 pcap_major_version(pcap_t
*p
)
1381 return (PCAP_ERROR_NOT_ACTIVATED
);
1382 return (p
->version_major
);
1386 pcap_minor_version(pcap_t
*p
)
1389 return (PCAP_ERROR_NOT_ACTIVATED
);
1390 return (p
->version_minor
);
1394 pcap_file(pcap_t
*p
)
1400 pcap_fileno(pcap_t
*p
)
1405 if (p
->adapter
!= NULL
)
1406 return ((int)(DWORD
)p
->adapter
->hFile
);
1408 return (PCAP_ERROR
);
1412 #if !defined(_WIN32) && !defined(MSDOS)
1414 pcap_get_selectable_fd(pcap_t
*p
)
1416 return (p
->selectable_fd
);
1421 pcap_perror(pcap_t
*p
, char *prefix
)
1423 fprintf(stderr
, "%s: %s\n", prefix
, p
->errbuf
);
1427 pcap_geterr(pcap_t
*p
)
1433 pcap_getnonblock(pcap_t
*p
, char *errbuf
)
1437 ret
= p
->getnonblock_op(p
, errbuf
);
1440 * In case somebody depended on the bug wherein
1441 * the error message was put into p->errbuf
1442 * by pcap_getnonblock_fd().
1444 strlcpy(p
->errbuf
, errbuf
, PCAP_ERRBUF_SIZE
);
1450 * Get the current non-blocking mode setting, under the assumption that
1451 * it's just the standard POSIX non-blocking flag.
1453 #if !defined(_WIN32) && !defined(MSDOS)
1455 pcap_getnonblock_fd(pcap_t
*p
, char *errbuf
)
1459 fdflags
= fcntl(p
->fd
, F_GETFL
, 0);
1460 if (fdflags
== -1) {
1461 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "F_GETFL: %s",
1462 pcap_strerror(errno
));
1465 if (fdflags
& O_NONBLOCK
)
1473 pcap_setnonblock(pcap_t
*p
, int nonblock
, char *errbuf
)
1477 ret
= p
->setnonblock_op(p
, nonblock
, errbuf
);
1480 * In case somebody depended on the bug wherein
1481 * the error message was put into p->errbuf
1482 * by pcap_setnonblock_fd().
1484 strlcpy(p
->errbuf
, errbuf
, PCAP_ERRBUF_SIZE
);
1489 #if !defined(_WIN32) && !defined(MSDOS)
1491 * Set non-blocking mode, under the assumption that it's just the
1492 * standard POSIX non-blocking flag. (This can be called by the
1493 * per-platform non-blocking-mode routine if that routine also
1494 * needs to do some additional work.)
1497 pcap_setnonblock_fd(pcap_t
*p
, int nonblock
, char *errbuf
)
1501 fdflags
= fcntl(p
->fd
, F_GETFL
, 0);
1502 if (fdflags
== -1) {
1503 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "F_GETFL: %s",
1504 pcap_strerror(errno
));
1508 fdflags
|= O_NONBLOCK
;
1510 fdflags
&= ~O_NONBLOCK
;
1511 if (fcntl(p
->fd
, F_SETFL
, fdflags
) == -1) {
1512 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "F_SETFL: %s",
1513 pcap_strerror(errno
));
1522 * Generate a string for a Win32-specific error (i.e. an error generated when
1523 * calling a Win32 API).
1524 * For errors occurred during standard C calls, we still use pcap_strerror()
1527 pcap_win32_err_to_str(DWORD error
, char *errbuf
)
1532 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM
, NULL
, error
, 0, errbuf
,
1533 PCAP_ERRBUF_SIZE
, NULL
);
1536 * "FormatMessage()" "helpfully" sticks CR/LF at the end of the
1537 * message. Get rid of it.
1539 errlen
= strlen(errbuf
);
1541 errbuf
[errlen
- 1] = '\0';
1542 errbuf
[errlen
- 2] = '\0';
1544 p
= strchr(errbuf
, '\0');
1545 pcap_snprintf (p
, PCAP_ERRBUF_SIZE
+1-(p
-errbuf
), " (%lu)", error
);
1550 * Generate error strings for PCAP_ERROR_ and PCAP_WARNING_ values.
1553 pcap_statustostr(int errnum
)
1555 static char ebuf
[15+10+1];
1560 return("Generic warning");
1562 case PCAP_WARNING_TSTAMP_TYPE_NOTSUP
:
1563 return ("That type of time stamp is not supported by that device");
1565 case PCAP_WARNING_PROMISC_NOTSUP
:
1566 return ("That device doesn't support promiscuous mode");
1569 return("Generic error");
1571 case PCAP_ERROR_BREAK
:
1572 return("Loop terminated by pcap_breakloop");
1574 case PCAP_ERROR_NOT_ACTIVATED
:
1575 return("The pcap_t has not been activated");
1577 case PCAP_ERROR_ACTIVATED
:
1578 return ("The setting can't be changed after the pcap_t is activated");
1580 case PCAP_ERROR_NO_SUCH_DEVICE
:
1581 return ("No such device exists");
1583 case PCAP_ERROR_RFMON_NOTSUP
:
1584 return ("That device doesn't support monitor mode");
1586 case PCAP_ERROR_NOT_RFMON
:
1587 return ("That operation is supported only in monitor mode");
1589 case PCAP_ERROR_PERM_DENIED
:
1590 return ("You don't have permission to capture on that device");
1592 case PCAP_ERROR_IFACE_NOT_UP
:
1593 return ("That device is not up");
1595 case PCAP_ERROR_CANTSET_TSTAMP_TYPE
:
1596 return ("That device doesn't support setting the time stamp type");
1598 case PCAP_ERROR_PROMISC_PERM_DENIED
:
1599 return ("You don't have permission to capture in promiscuous mode on that device");
1601 case PCAP_ERROR_TSTAMP_PRECISION_NOTSUP
:
1602 return ("That device doesn't support that time stamp precision");
1604 (void)pcap_snprintf(ebuf
, sizeof ebuf
, "Unknown error: %d", errnum
);
1609 * Not all systems have strerror().
1612 pcap_strerror(int errnum
)
1614 #ifdef HAVE_STRERROR
1615 return (strerror(errnum
));
1617 extern int sys_nerr
;
1618 extern const char *const sys_errlist
[];
1619 static char ebuf
[15+10+1];
1621 if ((unsigned int)errnum
< sys_nerr
)
1622 return ((char *)sys_errlist
[errnum
]);
1623 (void)pcap_snprintf(ebuf
, sizeof ebuf
, "Unknown error: %d", errnum
);
1629 pcap_setfilter(pcap_t
*p
, struct bpf_program
*fp
)
1631 return (p
->setfilter_op(p
, fp
));
1635 * Set direction flag, which controls whether we accept only incoming
1636 * packets, only outgoing packets, or both.
1637 * Note that, depending on the platform, some or all direction arguments
1638 * might not be supported.
1641 pcap_setdirection(pcap_t
*p
, pcap_direction_t d
)
1643 if (p
->setdirection_op
== NULL
) {
1644 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1645 "Setting direction is not implemented on this platform");
1648 return (p
->setdirection_op(p
, d
));
1652 pcap_stats(pcap_t
*p
, struct pcap_stat
*ps
)
1654 return (p
->stats_op(p
, ps
));
1658 pcap_stats_dead(pcap_t
*p
, struct pcap_stat
*ps _U_
)
1660 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1661 "Statistics aren't available from a pcap_open_dead pcap_t");
1667 pcap_stats_ex(pcap_t
*p
, int *pcap_stat_size
)
1669 return (p
->stats_ex_op(p
, pcap_stat_size
));
1673 pcap_setbuff(pcap_t
*p
, int dim
)
1675 return (p
->setbuff_op(p
, dim
));
1679 pcap_setbuff_dead(pcap_t
*p
, int dim
)
1681 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1682 "The kernel buffer size cannot be set on a pcap_open_dead pcap_t");
1687 pcap_setmode(pcap_t
*p
, int mode
)
1689 return (p
->setmode_op(p
, mode
));
1693 pcap_setmode_dead(pcap_t
*p
, int mode
)
1695 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1696 "impossible to set mode on a pcap_open_dead pcap_t");
1701 pcap_setmintocopy(pcap_t
*p
, int size
)
1703 return (p
->setmintocopy_op(p
, size
));
1707 pcap_setmintocopy_dead(pcap_t
*p
, int size
)
1709 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1710 "The mintocopy parameter cannot be set on a pcap_open_dead pcap_t");
1715 pcap_getevent(pcap_t
*p
)
1717 return (p
->getevent_op(p
));
1721 pcap_getevent_dead(pcap_t
*p
)
1723 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1724 "A pcap_open_dead pcap_t has no event handle");
1725 return (INVALID_HANDLE_VALUE
);
1729 pcap_oid_get_request(pcap_t
*p
, bpf_u_int32 oid
, void *data
, size_t len
)
1731 return (p
->oid_get_request_op(p
, oid
, data
, len
));
1735 pcap_oid_get_request_dead(pcap_t
*p
, bpf_u_int32 oid _U_
, void *data _U_
,
1738 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1739 "An OID get request cannot be performed on a pcap_open_dead pcap_t");
1740 return (PCAP_ERROR
);
1744 pcap_oid_set_request(pcap_t
*p
, bpf_u_int32 oid
, const void *data
, size_t len
)
1746 return (p
->oid_set_request_op(p
, oid
, data
, len
));
1750 pcap_oid_set_request_dead(pcap_t
*p
, bpf_u_int32 oid _U_
, const void *data _U_
,
1753 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1754 "An OID set request cannot be performed on a pcap_open_dead pcap_t");
1755 return (PCAP_ERROR
);
1759 pcap_sendqueue_alloc(u_int memsize
)
1761 pcap_send_queue
*tqueue
;
1763 /* Allocate the queue */
1764 tqueue
= (pcap_send_queue
*)malloc(sizeof(pcap_send_queue
));
1765 if (tqueue
== NULL
){
1769 /* Allocate the buffer */
1770 tqueue
->buffer
= (char *)malloc(memsize
);
1771 if (tqueue
->buffer
== NULL
) {
1776 tqueue
->maxlen
= memsize
;
1783 pcap_sendqueue_destroy(pcap_send_queue
*queue
)
1785 free(queue
->buffer
);
1790 pcap_sendqueue_queue(pcap_send_queue
*queue
, const struct pcap_pkthdr
*pkt_header
, const u_char
*pkt_data
)
1792 if (queue
->len
+ sizeof(struct pcap_pkthdr
) + pkt_header
->caplen
> queue
->maxlen
){
1796 /* Copy the pcap_pkthdr header*/
1797 memcpy(queue
->buffer
+ queue
->len
, pkt_header
, sizeof(struct pcap_pkthdr
));
1798 queue
->len
+= sizeof(struct pcap_pkthdr
);
1800 /* copy the packet */
1801 memcpy(queue
->buffer
+ queue
->len
, pkt_data
, pkt_header
->caplen
);
1802 queue
->len
+= pkt_header
->caplen
;
1808 pcap_sendqueue_transmit(pcap_t
*p
, pcap_send_queue
*queue
, int sync
)
1810 return (p
->sendqueue_transmit_op(p
, queue
, sync
));
1814 pcap_sendqueue_transmit_dead(pcap_t
*p
, pcap_send_queue
*queue
, int sync
)
1816 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1817 "Packets cannot be transmitted on a pcap_open_dead pcap_t");
1822 pcap_setuserbuffer(pcap_t
*p
, int size
)
1824 return (p
->setuserbuffer_op(p
, size
));
1828 pcap_setuserbuffer_dead(pcap_t
*p
, int size
)
1830 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1831 "The user buffer cannot be set on a pcap_open_dead pcap_t");
1836 pcap_live_dump(pcap_t
*p
, char *filename
, int maxsize
, int maxpacks
)
1838 return (p
->live_dump_op(p
, filename
, maxsize
, maxpacks
));
1842 pcap_live_dump_dead(pcap_t
*p
, char *filename
, int maxsize
, int maxpacks
)
1844 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1845 "Live packet dumping cannot be performed on a pcap_open_dead pcap_t");
1850 pcap_live_dump_ended(pcap_t
*p
, int sync
)
1852 return (p
->live_dump_ended_op(p
, sync
));
1856 pcap_live_dump_ended_dead(pcap_t
*p
, int sync
)
1858 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
1859 "Live packet dumping cannot be performed on a pcap_open_dead pcap_t");
1864 pcap_get_airpcap_handle(pcap_t
*p
)
1866 PAirpcapHandle handle
;
1868 handle
= p
->get_airpcap_handle_op(p
);
1869 if (handle
== NULL
) {
1870 (void)pcap_snprintf(p
->errbuf
, sizeof(p
->errbuf
),
1871 "This isn't an AirPcap device");
1876 static PAirpcapHandle
1877 pcap_get_airpcap_handle_dead(pcap_t
*p
)
1884 * On some platforms, we need to clean up promiscuous or monitor mode
1885 * when we close a device - and we want that to happen even if the
1886 * application just exits without explicitl closing devices.
1887 * On those platforms, we need to register a "close all the pcaps"
1888 * routine to be called when we exit, and need to maintain a list of
1889 * pcaps that need to be closed to clean up modes.
1891 * XXX - not thread-safe.
1895 * List of pcaps on which we've done something that needs to be
1897 * If there are any such pcaps, we arrange to call "pcap_close_all()"
1898 * when we exit, and have it close all of them.
1900 static struct pcap
*pcaps_to_close
;
1903 * TRUE if we've already called "atexit()" to cause "pcap_close_all()" to
1904 * be called on exit.
1906 static int did_atexit
;
1909 pcap_close_all(void)
1911 struct pcap
*handle
;
1913 while ((handle
= pcaps_to_close
) != NULL
)
1918 pcap_do_addexit(pcap_t
*p
)
1921 * If we haven't already done so, arrange to have
1922 * "pcap_close_all()" called when we exit.
1925 if (atexit(pcap_close_all
) == -1) {
1927 * "atexit()" failed; let our caller know.
1929 strncpy(p
->errbuf
, "atexit failed",
1939 pcap_add_to_pcaps_to_close(pcap_t
*p
)
1941 p
->next
= pcaps_to_close
;
1946 pcap_remove_from_pcaps_to_close(pcap_t
*p
)
1948 pcap_t
*pc
, *prevpc
;
1950 for (pc
= pcaps_to_close
, prevpc
= NULL
; pc
!= NULL
;
1951 prevpc
= pc
, pc
= pc
->next
) {
1954 * Found it. Remove it from the list.
1956 if (prevpc
== NULL
) {
1958 * It was at the head of the list.
1960 pcaps_to_close
= pc
->next
;
1963 * It was in the middle of the list.
1965 prevpc
->next
= pc
->next
;
1973 pcap_cleanup_live_common(pcap_t
*p
)
1975 if (p
->buffer
!= NULL
) {
1979 if (p
->dlt_list
!= NULL
) {
1984 if (p
->tstamp_type_list
!= NULL
) {
1985 free(p
->tstamp_type_list
);
1986 p
->tstamp_type_list
= NULL
;
1987 p
->tstamp_type_count
= 0;
1989 if (p
->tstamp_precision_list
!= NULL
) {
1990 free(p
->tstamp_precision_list
);
1991 p
->tstamp_precision_list
= NULL
;
1992 p
->tstamp_precision_count
= 0;
1994 pcap_freecode(&p
->fcode
);
1995 #if !defined(_WIN32) && !defined(MSDOS)
2000 p
->selectable_fd
= -1;
2005 pcap_cleanup_dead(pcap_t
*p _U_
)
2007 /* Nothing to do. */
2011 pcap_open_dead_with_tstamp_precision(int linktype
, int snaplen
, u_int precision
)
2015 switch (precision
) {
2017 case PCAP_TSTAMP_PRECISION_MICRO
:
2018 case PCAP_TSTAMP_PRECISION_NANO
:
2024 p
= malloc(sizeof(*p
));
2027 memset (p
, 0, sizeof(*p
));
2028 p
->snapshot
= snaplen
;
2029 p
->linktype
= linktype
;
2030 p
->opt
.tstamp_precision
= precision
;
2031 p
->stats_op
= pcap_stats_dead
;
2033 p
->stats_ex_op
= (stats_ex_op_t
)pcap_not_initialized_ptr
;
2034 p
->setbuff_op
= pcap_setbuff_dead
;
2035 p
->setmode_op
= pcap_setmode_dead
;
2036 p
->setmintocopy_op
= pcap_setmintocopy_dead
;
2037 p
->getevent_op
= pcap_getevent_dead
;
2038 p
->oid_get_request_op
= pcap_oid_get_request_dead
;
2039 p
->oid_set_request_op
= pcap_oid_set_request_dead
;
2040 p
->sendqueue_transmit_op
= pcap_sendqueue_transmit_dead
;
2041 p
->setuserbuffer_op
= pcap_setuserbuffer_dead
;
2042 p
->live_dump_op
= pcap_live_dump_dead
;
2043 p
->live_dump_ended_op
= pcap_live_dump_ended_dead
;
2044 p
->get_airpcap_handle_op
= pcap_get_airpcap_handle_dead
;
2046 p
->cleanup_op
= pcap_cleanup_dead
;
2049 * A "dead" pcap_t never requires special BPF code generation.
2051 p
->bpf_codegen_flags
= 0;
2058 pcap_open_dead(int linktype
, int snaplen
)
2060 return (pcap_open_dead_with_tstamp_precision(linktype
, snaplen
,
2061 PCAP_TSTAMP_PRECISION_MICRO
));
2065 * API compatible with WinPcap's "send a packet" routine - returns -1
2066 * on error, 0 otherwise.
2068 * XXX - what if we get a short write?
2071 pcap_sendpacket(pcap_t
*p
, const u_char
*buf
, int size
)
2073 if (p
->inject_op(p
, buf
, size
) == -1)
2079 * API compatible with OpenBSD's "send a packet" routine - returns -1 on
2080 * error, number of bytes written otherwise.
2083 pcap_inject(pcap_t
*p
, const void *buf
, size_t size
)
2085 return (p
->inject_op(p
, buf
, size
));
2089 pcap_close(pcap_t
*p
)
2091 if (p
->opt
.source
!= NULL
)
2092 free(p
->opt
.source
);
2098 * Given a BPF program, a pcap_pkthdr structure for a packet, and the raw
2099 * data for the packet, check whether the packet passes the filter.
2100 * Returns the return value of the filter program, which will be zero if
2101 * the packet doesn't pass and non-zero if the packet does pass.
2104 pcap_offline_filter(const struct bpf_program
*fp
, const struct pcap_pkthdr
*h
,
2107 const struct bpf_insn
*fcode
= fp
->bf_insns
;
2110 return (bpf_filter(fcode
, pkt
, h
->len
, h
->caplen
));
2116 * We make the version string static, and return a pointer to it, rather
2117 * than exporting the version string directly. On at least some UNIXes,
2118 * if you import data from a shared library into an program, the data is
2119 * bound into the program binary, so if the string in the version of the
2120 * library with which the program was linked isn't the same as the
2121 * string in the version of the library with which the program is being
2122 * run, various undesirable things may happen (warnings, the string
2123 * being the one from the version of the library with which the program
2124 * was linked, or even weirder things, such as the string being the one
2125 * from the library but being truncated).
2127 #ifdef HAVE_VERSION_H
2128 #include "version.h"
2130 static const char pcap_version_string
[] = "libpcap version 1.x.y";
2135 * XXX - it'd be nice if we could somehow generate the WinPcap and libpcap
2136 * version numbers when building WinPcap. (It'd be nice to do so for
2137 * the packet.dll version number as well.)
2139 static const char wpcap_version_string
[] = "4.0";
2140 static const char pcap_version_string_fmt
[] =
2141 "WinPcap version %s, based on %s";
2142 static const char pcap_version_string_packet_dll_fmt
[] =
2143 "WinPcap version %s (packet.dll version %s), based on %s";
2144 static char *full_pcap_version_string
;
2147 pcap_lib_version(void)
2149 char *packet_version_string
;
2150 size_t full_pcap_version_string_len
;
2152 if (full_pcap_version_string
== NULL
) {
2154 * Generate the version string.
2156 packet_version_string
= PacketGetVersion();
2157 if (strcmp(wpcap_version_string
, packet_version_string
) == 0) {
2159 * WinPcap version string and packet.dll version
2160 * string are the same; just report the WinPcap
2163 full_pcap_version_string_len
=
2164 (sizeof pcap_version_string_fmt
- 4) +
2165 strlen(wpcap_version_string
) +
2166 strlen(pcap_version_string
);
2167 full_pcap_version_string
=
2168 malloc(full_pcap_version_string_len
);
2169 if (full_pcap_version_string
== NULL
)
2171 sprintf(full_pcap_version_string
,
2172 pcap_version_string_fmt
, wpcap_version_string
,
2173 pcap_version_string
);
2176 * WinPcap version string and packet.dll version
2177 * string are different; that shouldn't be the
2178 * case (the two libraries should come from the
2179 * same version of WinPcap), so we report both
2182 full_pcap_version_string_len
=
2183 (sizeof pcap_version_string_packet_dll_fmt
- 6) +
2184 strlen(wpcap_version_string
) +
2185 strlen(packet_version_string
) +
2186 strlen(pcap_version_string
);
2187 full_pcap_version_string
= malloc(full_pcap_version_string_len
);
2188 if (full_pcap_version_string
== NULL
)
2190 sprintf(full_pcap_version_string
,
2191 pcap_version_string_packet_dll_fmt
,
2192 wpcap_version_string
, packet_version_string
,
2193 pcap_version_string
);
2196 return (full_pcap_version_string
);
2199 #elif defined(MSDOS)
2201 static char *full_pcap_version_string
;
2204 pcap_lib_version (void)
2206 char *packet_version_string
;
2207 size_t full_pcap_version_string_len
;
2208 static char dospfx
[] = "DOS-";
2210 if (full_pcap_version_string
== NULL
) {
2212 * Generate the version string.
2214 full_pcap_version_string_len
=
2215 sizeof dospfx
+ strlen(pcap_version_string
);
2216 full_pcap_version_string
=
2217 malloc(full_pcap_version_string_len
);
2218 if (full_pcap_version_string
== NULL
)
2220 strcpy(full_pcap_version_string
, dospfx
);
2221 strcat(full_pcap_version_string
, pcap_version_string
);
2223 return (full_pcap_version_string
);
2229 pcap_lib_version(void)
2231 return (pcap_version_string
);