2 * Copyright (c) 1993, 1994, 1995, 1996, 1997
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: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
21 * This code contributed by Atanu Ghosh (atanu@cs.ucl.ac.uk),
22 * University College London, and subsequently modified by
23 * Guy Harris (guy@alum.mit.edu), Mark Pizzolato
24 * <List-tcpdump-workers@subscriptions.pizzolato.net>,
25 * Mark C. Brown (mbrown@hp.com), and Sagun Shakya <Sagun.Shakya@Sun.COM>.
29 * Packet capture routine for DLPI under SunOS 5, HP-UX 9/10/11, and AIX.
33 * - The DLIOCRAW ioctl() is specific to SunOS.
35 * - There is a bug in bufmod(7) such that setting the snapshot
36 * length results in data being left of the front of the packet.
38 * - It might be desirable to use pfmod(7) to filter packets in the
39 * kernel when possible.
41 * - An older version of the HP-UX DLPI Programmer's Guide, which
42 * I think was advertised as the 10.20 version, used to be available
45 * http://docs.hp.com/hpux/onlinedocs/B2355-90093/B2355-90093.html
47 * but is no longer available; it can still be found at
49 * http://h21007.www2.hp.com/dspp/files/unprotected/Drivers/Docs/Refs/B2355-90093.pdf
53 * - The HP-UX 10.x, 11.0, and 11i v1.6 version of the HP-UX DLPI
54 * Programmer's Guide, which I think was once advertised as the
55 * 11.00 version is available at
57 * http://docs.hp.com/en/B2355-90139/index.html
59 * - The HP-UX 11i v2 version of the HP-UX DLPI Programmer's Guide
62 * http://docs.hp.com/en/B2355-90871/index.html
64 * - All of the HP documents describe raw-mode services, which are
65 * what we use if DL_HP_RAWDLS is defined. XXX - we use __hpux
66 * in some places to test for HP-UX, but use DL_HP_RAWDLS in
67 * other places; do we support any versions of HP-UX without
75 #include <sys/types.h>
77 #ifdef HAVE_SYS_BUFMOD_H
78 #include <sys/bufmod.h>
81 #ifdef HAVE_SYS_DLPI_EXT_H
82 #include <sys/dlpi_ext.h>
85 #include <sys/socket.h>
90 #include <sys/stream.h>
91 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
92 #include <sys/systeminfo.h>
115 #define INT_MAX 2147483647
118 #include "pcap-int.h"
119 #include "dlpisubs.h"
121 #ifdef HAVE_OS_PROTO_H
122 #include "os-proto.h"
127 * HP-UX has a /dev/dlpi device; you open it and set the PPA of the actual
128 * network device you want.
130 #define HAVE_DEV_DLPI
133 * AIX has a /dev/dlpi directory, with devices named after the interfaces
136 #define PCAP_DEV_PREFIX "/dev/dlpi"
137 #elif defined(HAVE_SOLARIS)
139 * Solaris has devices named after the interfaces underneath /dev.
141 #define PCAP_DEV_PREFIX "/dev"
144 #define MAXDLBUF 8192
147 static char *split_dname(char *, u_int *, char *);
148 static int dl_doattach(int, int, char *);
150 static int dl_dohpuxbind(int, char *);
152 static int dlpromiscon(pcap_t *, bpf_u_int32);
153 static int dlbindreq(int, bpf_u_int32, char *);
154 static int dlbindack(int, char *, char *, int *);
155 static int dlokack(int, const char *, char *, char *);
156 static int dlinforeq(int, char *);
157 static int dlinfoack(int, char *, char *);
159 #ifdef HAVE_DL_PASSIVE_REQ_T
160 static void dlpassive(int, char *);
164 static int dlrawdatareq(int, const u_char *, int);
166 static int recv_ack(int, int, const char *, char *, char *, int *);
167 static char *dlstrerror(char *, size_t, bpf_u_int32);
168 static char *dlprim(char *, size_t, bpf_u_int32);
169 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
170 #define GET_RELEASE_BUFSIZE 32
171 static void get_release(char *, size_t, bpf_u_int32 *, bpf_u_int32 *,
174 static int send_request(int, char *, int, char *, char *);
176 static int dlpi_kread(int, off_t, void *, u_int, char *);
179 static int get_dlpi_ppa(int, const char *, u_int, u_int *, char *);
183 * Cast a buffer to "union DL_primitives" without provoking warnings
186 #define MAKE_DL_PRIMITIVES(ptr) ((union DL_primitives *)(void *)(ptr))
189 pcap_read_dlpi(pcap_t *p, int cnt, pcap_handler callback, u_char *user)
194 bpf_u_int32 ctlbuf[MAXDLBUF];
195 struct strbuf ctl = {
205 data.buf = (char *)p->buffer + p->offset;
206 data.maxlen = p->bufsize;
210 * Has "pcap_breakloop()" been called?
214 * Yes - clear the flag that indicates
215 * that it has, and return -2 to
216 * indicate that we were told to
217 * break out of the loop.
223 * XXX - check for the DLPI primitive, which
224 * would be DL_HP_RAWDATA_IND on HP-UX
225 * if we're in raw mode?
227 ctl.buf = (char *)ctlbuf;
228 ctl.maxlen = MAXDLBUF;
230 if (getmsg(p->fd, &ctl, &data, &flags) < 0) {
231 /* Don't choke when we get ptraced */
241 pcap_fmt_errmsg_for_errno(p->errbuf,
242 sizeof(p->errbuf), errno, "getmsg");
247 bp = (u_char *)p->buffer + p->offset;
251 return (pcap_process_pkts(p, callback, user, cnt, bp, cc));
255 pcap_inject_dlpi(pcap_t *p, const void *buf, size_t size)
258 struct pcap_dlpi *pd = p->priv;
262 #if defined(DLIOCRAW)
263 ret = write(p->fd, buf, size);
265 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
269 #elif defined(DL_HP_RAWDLS)
270 if (pd->send_fd < 0) {
271 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
272 "send: Output FD couldn't be opened");
275 ret = dlrawdatareq(pd->send_fd, buf, size);
277 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
282 * putmsg() returns either 0 or -1; it doesn't indicate how
283 * many bytes were written (presumably they were all written
284 * or none of them were written). OpenBSD's pcap_inject()
285 * returns the number of bytes written, so, for API compatibility,
286 * we return the number of bytes we were told to write.
289 #else /* no raw mode */
291 * XXX - this is a pain, because you might have to extract
292 * the address from the packet and use it in a DL_UNITDATA_REQ
293 * request. That would be dependent on the link-layer type.
295 * I also don't know what SAP you'd have to bind the descriptor
296 * to, or whether you'd need separate "receive" and "send" FDs,
297 * nor do I know whether you'd need different bindings for
298 * D/I/X Ethernet and 802.3, or for {FDDI,Token Ring} plus
299 * 802.2 and {FDDI,Token Ring} plus 802.2 plus SNAP.
301 * So, for now, we just return a "you can't send" indication,
302 * and leave it up to somebody with a DLPI-based system lacking
303 * both DLIOCRAW and DL_HP_RAWDLS to supply code to implement
304 * packet transmission on that system. If they do, they should
305 * send it to us - but should not send us code that assumes
306 * Ethernet; if the code doesn't work on non-Ethernet interfaces,
307 * it should check "p->linktype" and reject the send request if
308 * it's anything other than DLT_EN10MB.
310 pcap_strlcpy(p->errbuf, "send: Not supported on this version of this OS",
313 #endif /* raw mode */
318 #define DL_IPATM 0x12 /* ATM Classical IP interface */
326 #define A_GET_UNITS (('A'<<8)|118)
327 #endif /* A_GET_UNITS */
328 #ifndef A_PROMISCON_REQ
329 #define A_PROMISCON_REQ (('A'<<8)|121)
330 #endif /* A_PROMISCON_REQ */
331 #endif /* HAVE_SOLARIS */
334 pcap_cleanup_dlpi(pcap_t *p)
337 struct pcap_dlpi *pd = p->priv;
339 if (pd->send_fd >= 0) {
344 pcap_cleanup_live_common(p);
348 open_dlpi_device(const char *name, u_int *ppa, char *errbuf)
362 ** Remove any "/dev/" on the front of the device.
364 cp = strrchr(name, '/');
366 pcap_strlcpy(dname, name, sizeof(dname));
368 pcap_strlcpy(dname, cp + 1, sizeof(dname));
371 * Split the device name into a device type name and a unit number;
372 * chop off the unit number, so "dname" is just a device type name.
374 cp = split_dname(dname, &unit, errbuf);
376 return (PCAP_ERROR_NO_SUCH_DEVICE);
380 * Use "/dev/dlpi" as the device.
382 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
383 * the "dl_mjr_num" field is for the "major number of interface
384 * driver"; that's the major of "/dev/dlpi" on the system on
385 * which I tried this, but there may be DLPI devices that
386 * use a different driver, in which case we may need to
387 * search "/dev" for the appropriate device with that major
388 * device number, rather than hardwiring "/dev/dlpi".
391 if ((fd = open(cp, O_RDWR)) < 0) {
392 if (errno == EPERM || errno == EACCES)
393 status = PCAP_ERROR_PERM_DENIED;
396 pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
402 * Get a table of all PPAs for that device, and search that
403 * table for the specified device type name and unit number.
405 status = get_dlpi_ppa(fd, dname, unit, ppa, errbuf);
412 * If the device name begins with "/", assume it begins with
413 * the pathname of the directory containing the device to open;
414 * otherwise, concatenate the device directory name and the
418 pcap_strlcpy(dname, name, sizeof(dname));
420 pcap_snprintf(dname, sizeof(dname), "%s/%s", PCAP_DEV_PREFIX,
424 * Get the unit number, and a pointer to the end of the device
427 cp = split_dname(dname, ppa, errbuf);
429 return (PCAP_ERROR_NO_SUCH_DEVICE);
432 * Make a copy of the device pathname, and then remove the unit
433 * number from the device pathname.
435 pcap_strlcpy(dname2, dname, sizeof(dname));
438 /* Try device without unit number */
439 if ((fd = open(dname, O_RDWR)) < 0) {
440 if (errno != ENOENT) {
441 if (errno == EPERM || errno == EACCES)
442 status = PCAP_ERROR_PERM_DENIED;
445 pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
450 /* Try again with unit number */
451 if ((fd = open(dname2, O_RDWR)) < 0) {
452 if (errno == ENOENT) {
453 status = PCAP_ERROR_NO_SUCH_DEVICE;
456 * We provide an error message even
457 * for this error, for diagnostic
458 * purposes (so that, for example,
459 * the app can show the message if the
462 * In it, we just report "No DLPI device
463 * found" with the device name, so people
464 * don't get confused and think, for example,
465 * that if they can't capture on "lo0"
466 * on Solaris prior to Solaris 11 the fix
467 * is to change libpcap (or the application
468 * that uses it) to look for something other
469 * than "/dev/lo0", as the fix is to use
470 * Solaris 11 or some operating system
471 * other than Solaris - you just *can't*
472 * capture on a loopback interface
473 * on Solaris prior to Solaris 11, the lack
474 * of a DLPI device for the loopback
475 * interface is just a symptom of that
478 pcap_snprintf(errbuf, PCAP_ERRBUF_SIZE,
479 "%s: No DLPI device found", name);
481 if (errno == EPERM || errno == EACCES)
482 status = PCAP_ERROR_PERM_DENIED;
485 pcap_fmt_errmsg_for_errno(errbuf,
486 PCAP_ERRBUF_SIZE, errno, "%s", dname2);
490 /* XXX Assume unit zero */
498 pcap_activate_dlpi(pcap_t *p)
501 struct pcap_dlpi *pd = p->priv;
509 register dl_info_ack_t *infop;
510 #ifdef HAVE_SYS_BUFMOD_H
513 char release[GET_RELEASE_BUFSIZE];
514 bpf_u_int32 osmajor, osminor, osmicro;
517 bpf_u_int32 buf[MAXDLBUF];
519 p->fd = open_dlpi_device(p->opt.device, &ppa, p->errbuf);
527 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
528 * receiving packets on the same descriptor - you need separate
529 * descriptors for sending and receiving, bound to different SAPs.
531 * If the open fails, we just leave -1 in "pd->send_fd" and reject
532 * attempts to send packets, just as if, in pcap-bpf.c, we fail
533 * to open the BPF device for reading and writing, we just try
534 * to open it for reading only and, if that succeeds, just let
535 * the send attempts fail.
537 pd->send_fd = open("/dev/dlpi", O_RDWR);
541 ** Attach if "style 2" provider
543 if (dlinforeq(p->fd, p->errbuf) < 0 ||
544 dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
548 infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
550 if (infop->dl_mac_type == DL_IPATM)
553 if (infop->dl_provider_style == DL_STYLE2) {
554 retv = dl_doattach(p->fd, ppa, p->errbuf);
560 if (pd->send_fd >= 0) {
561 retv = dl_doattach(pd->send_fd, ppa, p->errbuf);
572 * This device exists, but we don't support monitor mode
573 * any platforms that support DLPI.
575 status = PCAP_ERROR_RFMON_NOTSUP;
579 #ifdef HAVE_DL_PASSIVE_REQ_T
581 * Enable Passive mode to be able to capture on aggregated link.
582 * Not supported in all Solaris versions.
584 dlpassive(p->fd, p->errbuf);
587 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
588 ** skip if using SINIX)
590 #if !defined(HAVE_HPUX9) && !defined(HAVE_HPUX10_20_OR_LATER) && !defined(sinix)
594 ** According to IBM's AIX Support Line, the dl_sap value
595 ** should not be less than 0x600 (1536) for standard Ethernet.
596 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
597 ** format or invalid" - errors if we use 1537 on the "tr0"
598 ** device, which, given that its name starts with "tr" and that
599 ** it's IBM, probably means a Token Ring device. (Perhaps we
600 ** need to use 1537 on "/dev/dlpi/en" because that device is for
601 ** D/I/X Ethernet, the "SAP" is actually an Ethernet type, and
602 ** it rejects invalid Ethernet types.)
604 ** So if 1537 fails, we try 2, as Hyung Sik Yoon of IBM Korea
605 ** says that works on Token Ring (he says that 0 does *not*
606 ** work; perhaps that's considered an invalid LLC SAP value - I
607 ** assume the SAP value in a DLPI bind is an LLC SAP for network
608 ** types that use 802.2 LLC).
610 if ((dlbindreq(p->fd, 1537, p->errbuf) < 0 &&
611 dlbindreq(p->fd, 2, p->errbuf) < 0) ||
612 dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
616 #elif defined(DL_HP_RAWDLS)
618 ** HP-UX 10.0x and 10.1x.
620 if (dl_dohpuxbind(p->fd, p->errbuf) < 0) {
624 if (pd->send_fd >= 0) {
626 ** XXX - if this fails, just close send_fd and
627 ** set it to -1, so that you can't send but can
630 if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) {
635 #else /* neither AIX nor HP-UX */
637 ** Not Sinix, and neither AIX nor HP-UX - Solaris, and any other
640 if (dlbindreq(p->fd, 0, p->errbuf) < 0 ||
641 dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
645 #endif /* AIX vs. HP-UX vs. other */
646 #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
649 * Turn a negative snapshot value (invalid), a snapshot value of
650 * 0 (unspecified), or a value bigger than the normal maximum
651 * value, into the maximum allowed value.
653 * If some application really *needs* a bigger snapshot
654 * length, we should just increase MAXIMUM_SNAPLEN.
656 if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
657 p->snapshot = MAXIMUM_SNAPLEN;
662 ** Have to turn on some special ATM promiscuous mode
664 ** Do *NOT* turn regular promiscuous mode on; it doesn't
665 ** help, and may break things.
667 if (strioctl(p->fd, A_PROMISCON_REQ, 0, NULL) < 0) {
669 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
670 errno, "A_PROMISCON_REQ");
675 if (p->opt.promisc) {
677 ** Enable promiscuous (not necessary on send FD)
679 retv = dlpromiscon(p, DL_PROMISC_PHYS);
681 if (retv == PCAP_ERROR_PERM_DENIED)
682 status = PCAP_ERROR_PROMISC_PERM_DENIED;
689 ** Try to enable multicast (you would have thought
690 ** promiscuous would be sufficient). (Skip if using
691 ** HP-UX or SINIX) (Not necessary on send FD)
693 #if !defined(__hpux) && !defined(sinix)
694 retv = dlpromiscon(p, DL_PROMISC_MULTI);
696 status = PCAP_WARNING;
700 ** Try to enable SAP promiscuity (when not in promiscuous mode
701 ** when using HP-UX, when not doing SunATM on Solaris, and never
702 ** under SINIX) (Not necessary on send FD)
706 /* HP-UX - only do this when not in promiscuous mode */
707 if (!p->opt.promisc) {
708 #elif defined(HAVE_SOLARIS)
709 /* Solaris - don't do this on SunATM devices */
712 /* Everything else (except for SINIX) - always do this */
715 retv = dlpromiscon(p, DL_PROMISC_SAP);
717 if (p->opt.promisc) {
719 * Not fatal, since the DL_PROMISC_PHYS mode
722 * Report it as a warning, however.
724 status = PCAP_WARNING;
737 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
738 ** promiscuous options.
740 #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
741 if (dl_dohpuxbind(p->fd, p->errbuf) < 0) {
746 ** We don't set promiscuous mode on the send FD, but we'll defer
747 ** binding it anyway, just to keep the HP-UX 9/10.20 or later
750 if (pd->send_fd >= 0) {
752 ** XXX - if this fails, just close send_fd and
753 ** set it to -1, so that you can't send but can
756 if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) {
764 ** Determine link type
765 ** XXX - get SAP length and address length as well, for use
766 ** when sending packets.
768 if (dlinforeq(p->fd, p->errbuf) < 0 ||
769 dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
774 infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
775 if (pcap_process_mactype(p, infop->dl_mac_type) != 0) {
782 ** This is a non standard SunOS hack to get the full raw link-layer
785 if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) {
787 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
793 #ifdef HAVE_SYS_BUFMOD_H
797 ** There is a bug in bufmod(7). When dealing with messages of
798 ** less than snaplen size it strips data from the beginning not
801 ** This bug is fixed in 5.3.2. Also, there is a patch available.
802 ** Ask for bugid 1149065.
805 get_release(release, sizeof (release), &osmajor, &osminor, &osmicro);
806 if (osmajor == 5 && (osminor <= 2 || (osminor == 3 && osmicro < 2)) &&
807 getenv("BUFMOD_FIXED") == NULL) {
808 pcap_snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
809 "WARNING: bufmod is broken in SunOS %s; ignoring snaplen.",
812 status = PCAP_WARNING;
816 /* Push and configure bufmod. */
817 if (pcap_conf_bufmod(p, ss) != 0) {
824 ** As the last operation flush the read side.
826 if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
828 pcap_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
833 /* Allocate data buffer. */
834 if (pcap_alloc_databuf(p) != 0) {
842 * "p->fd" is an FD for a STREAMS device, so "select()" and
843 * "poll()" should work on it.
845 p->selectable_fd = p->fd;
847 p->read_op = pcap_read_dlpi;
848 p->inject_op = pcap_inject_dlpi;
849 p->setfilter_op = install_bpf_program; /* no kernel filtering */
850 p->setdirection_op = NULL; /* Not implemented.*/
851 p->set_datalink_op = NULL; /* can't change data link type */
852 p->getnonblock_op = pcap_getnonblock_fd;
853 p->setnonblock_op = pcap_setnonblock_fd;
854 p->stats_op = pcap_stats_dlpi;
855 p->cleanup_op = pcap_cleanup_dlpi;
859 pcap_cleanup_dlpi(p);
864 * Split a device name into a device type name and a unit number;
865 * return the a pointer to the beginning of the unit number, which
866 * is the end of the device type name, and set "*unitp" to the unit
869 * Returns NULL on error, and fills "ebuf" with an error message.
872 split_dname(char *device, u_int *unitp, char *ebuf)
879 * Look for a number at the end of the device name string.
881 cp = device + strlen(device) - 1;
882 if (*cp < '0' || *cp > '9') {
883 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s missing unit number",
888 /* Digits at end of string are unit number */
889 while (cp-1 >= device && *(cp-1) >= '0' && *(cp-1) <= '9')
893 unit = strtol(cp, &eos, 10);
895 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s bad unit number", device);
898 if (errno == ERANGE || unit > INT_MAX) {
899 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s unit number too large",
904 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "%s unit number is negative",
908 *unitp = (u_int)unit;
913 dl_doattach(int fd, int ppa, char *ebuf)
916 bpf_u_int32 buf[MAXDLBUF];
919 req.dl_primitive = DL_ATTACH_REQ;
921 if (send_request(fd, (char *)&req, sizeof(req), "attach", ebuf) < 0)
924 err = dlokack(fd, "attach", (char *)buf, ebuf);
932 dl_dohpuxbind(int fd, char *ebuf)
936 bpf_u_int32 buf[MAXDLBUF];
939 * XXX - we start at 22 because we used to use only 22, but
940 * that was just because that was the value used in some
941 * sample code from HP. With what value *should* we start?
942 * Does it matter, given that we're enabling SAP promiscuity
947 if (dlbindreq(fd, hpsap, ebuf) < 0)
949 if (dlbindack(fd, (char *)buf, ebuf, &uerror) >= 0)
952 * For any error other than a UNIX EBUSY, give up.
954 if (uerror != EBUSY) {
956 * dlbindack() has already filled in ebuf for
963 * For EBUSY, try the next SAP value; that means that
964 * somebody else is using that SAP. Clear ebuf so
965 * that application doesn't report the "Device busy"
966 * error as a warning.
972 "All SAPs from 22 through 100 are in use",
981 #define STRINGIFY(n) #n
984 dlpromiscon(pcap_t *p, bpf_u_int32 level)
986 dl_promiscon_req_t req;
987 bpf_u_int32 buf[MAXDLBUF];
990 req.dl_primitive = DL_PROMISCON_REQ;
991 req.dl_level = level;
992 if (send_request(p->fd, (char *)&req, sizeof(req), "promiscon",
995 err = dlokack(p->fd, "promiscon" STRINGIFY(level), (char *)buf,
1003 * Not all interfaces are DLPI interfaces, and thus not all interfaces
1004 * can be opened with DLPI (for example, the loopback interface is not
1005 * a DLPI interface on Solaris prior to Solaris 11), so try to open
1006 * the specified interface; return 0 if we fail with PCAP_ERROR_NO_SUCH_DEVICE
1010 is_dlpi_interface(const char *name)
1014 char errbuf[PCAP_ERRBUF_SIZE];
1016 fd = open_dlpi_device(name, &ppa, errbuf);
1019 * Error - was it PCAP_ERROR_NO_SUCH_DEVICE?
1021 if (fd == PCAP_ERROR_NO_SUCH_DEVICE) {
1023 * Yes, so we can't open this because it's
1024 * not a DLPI interface.
1029 * No, so, in the case where there's a single DLPI
1030 * device for all interfaces of this type ("style
1031 * 2" providers?), we don't know whether it's a DLPI
1032 * interface or not, as we didn't try an attach.
1033 * Say it is a DLPI device, so that the user can at
1034 * least try to open it and report the error (which
1035 * is probably "you don't have permission to open that
1036 * DLPI device"; reporting those interfaces means
1037 * users will ask "why am I getting a permissions error
1038 * when I try to capture" rather than "why am I not
1039 * seeing any interfaces", making the underlying problem
1053 get_if_flags(const char *name _U_, bpf_u_int32 *flags _U_, char *errbuf _U_)
1056 * Nothing we can do other than mark loopback devices as "the
1057 * connected/disconnected status doesn't apply".
1059 * XXX - on Solaris, can we do what the dladm command does,
1060 * i.e. get a connected/disconnected indication from a kstat?
1061 * (Note that you can also get the link speed, and possibly
1062 * other information, from a kstat as well.)
1064 if (*flags & PCAP_IF_LOOPBACK) {
1066 * Loopback devices aren't wireless, and "connected"/
1067 * "disconnected" doesn't apply to them.
1069 *flags |= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE;
1076 pcap_platform_finddevs(pcap_if_list_t *devlistp, char *errbuf)
1082 char pad[516]; /* XXX - must be at least 513; is 516
1090 * Get the list of regular interfaces first.
1092 if (pcap_findalldevs_interfaces(devlistp, errbuf, is_dlpi_interface,
1093 get_if_flags) == -1)
1094 return (-1); /* failure */
1098 * We may have to do special magic to get ATM devices.
1100 if ((fd = open("/dev/ba", O_RDWR)) < 0) {
1102 * We couldn't open the "ba" device.
1103 * For now, just give up; perhaps we should
1104 * return an error if the problem is neither
1105 * a "that device doesn't exist" error (ENOENT,
1106 * ENXIO, etc.) or a "you're not allowed to do
1107 * that" error (EPERM, EACCES).
1112 if (strioctl(fd, A_GET_UNITS, sizeof(buf), (char *)&buf) < 0) {
1113 pcap_fmt_errmsg_for_errno(errbuf, PCAP_ERRBUF_SIZE,
1114 errno, "A_GET_UNITS");
1117 for (i = 0; i < buf.nunits; i++) {
1118 pcap_snprintf(baname, sizeof baname, "ba%u", i);
1120 * XXX - is there a notion of "up" and "running"?
1121 * And is there a way to determine whether the
1122 * interface is plugged into a network?
1124 if (add_dev(devlistp, baname, 0, NULL, errbuf) == NULL)
1133 send_request(int fd, char *ptr, int len, char *what, char *ebuf)
1143 if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0) {
1144 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1145 errno, "send_request: putmsg \"%s\"", what);
1152 recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf, int *uerror)
1154 union DL_primitives *dlp;
1157 char errmsgbuf[PCAP_ERRBUF_SIZE];
1161 * Clear out "*uerror", so it's only set for DL_ERROR_ACK/DL_SYSERR,
1162 * making that the only place where EBUSY is treated specially.
1167 ctl.maxlen = MAXDLBUF;
1172 if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0) {
1173 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1174 errno, "recv_ack: %s getmsg", what);
1175 return (PCAP_ERROR);
1178 dlp = MAKE_DL_PRIMITIVES(ctl.buf);
1179 switch (dlp->dl_primitive) {
1184 #ifdef DL_HP_PPA_ACK
1191 switch (dlp->error_ack.dl_errno) {
1195 *uerror = dlp->error_ack.dl_unix_errno;
1196 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1197 dlp->error_ack.dl_unix_errno,
1198 "recv_ack: %s: UNIX error", what);
1199 if (dlp->error_ack.dl_unix_errno == EPERM ||
1200 dlp->error_ack.dl_unix_errno == EACCES)
1201 return (PCAP_ERROR_PERM_DENIED);
1205 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1206 "recv_ack: %s: %s", what,
1207 dlstrerror(errmsgbuf, sizeof (errmsgbuf), dlp->error_ack.dl_errno));
1208 if (dlp->error_ack.dl_errno == DL_BADPPA)
1209 return (PCAP_ERROR_NO_SUCH_DEVICE);
1210 else if (dlp->error_ack.dl_errno == DL_ACCESS)
1211 return (PCAP_ERROR_PERM_DENIED);
1214 return (PCAP_ERROR);
1217 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1218 "recv_ack: %s: Unexpected primitive ack %s",
1219 what, dlprim(dlprimbuf, sizeof (dlprimbuf), dlp->dl_primitive));
1220 return (PCAP_ERROR);
1223 if (ctl.len < size) {
1224 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1225 "recv_ack: %s: Ack too small (%d < %d)",
1226 what, ctl.len, size);
1227 return (PCAP_ERROR);
1233 dlstrerror(char *errbuf, size_t errbufsize, bpf_u_int32 dl_errno)
1238 return ("Improper permissions for request");
1241 return ("DLSAP addr in improper format or invalid");
1244 return ("Seq number not from outstand DL_CONN_IND");
1247 return ("User data exceeded provider limit");
1250 #ifdef HAVE_DEV_DLPI
1252 * With a single "/dev/dlpi" device used for all
1253 * DLPI providers, PPAs have nothing to do with
1256 return ("Specified PPA was invalid");
1259 * We have separate devices for separate devices;
1260 * the PPA is just the unit number.
1262 return ("Specified PPA (device unit) was invalid");
1266 return ("Primitive received not known by provider");
1268 case DL_BADQOSPARAM:
1269 return ("QOS parameters contained invalid values");
1272 return ("QOS structure type is unknown/unsupported");
1275 return ("Bad LSAP selector");
1278 return ("Token used not an active stream");
1281 return ("Attempted second bind with dl_max_conind");
1284 return ("Physical link initialization failed");
1287 return ("Provider couldn't allocate alternate address");
1290 return ("Physical link not initialized");
1293 return ("Primitive issued in improper state");
1296 return ("UNIX system error occurred");
1298 case DL_UNSUPPORTED:
1299 return ("Requested service not supplied by provider");
1301 case DL_UNDELIVERABLE:
1302 return ("Previous data unit could not be delivered");
1304 case DL_NOTSUPPORTED:
1305 return ("Primitive is known but not supported");
1308 return ("Limit exceeded");
1311 return ("Promiscuous mode not enabled");
1314 return ("Other streams for PPA in post-attached");
1317 return ("Automatic handling XID&TEST not supported");
1320 return ("Automatic handling of XID not supported");
1323 return ("Automatic handling of TEST not supported");
1326 return ("Automatic handling of XID response");
1329 return ("Automatic handling of TEST response");
1332 return ("Pending outstanding connect indications");
1335 pcap_snprintf(errbuf, errbufsize, "Error %02x", dl_errno);
1341 dlprim(char *primbuf, size_t primbufsize, bpf_u_int32 prim)
1346 return ("DL_INFO_REQ");
1349 return ("DL_INFO_ACK");
1352 return ("DL_ATTACH_REQ");
1355 return ("DL_DETACH_REQ");
1358 return ("DL_BIND_REQ");
1361 return ("DL_BIND_ACK");
1364 return ("DL_UNBIND_REQ");
1367 return ("DL_OK_ACK");
1370 return ("DL_ERROR_ACK");
1372 case DL_SUBS_BIND_REQ:
1373 return ("DL_SUBS_BIND_REQ");
1375 case DL_SUBS_BIND_ACK:
1376 return ("DL_SUBS_BIND_ACK");
1378 case DL_UNITDATA_REQ:
1379 return ("DL_UNITDATA_REQ");
1381 case DL_UNITDATA_IND:
1382 return ("DL_UNITDATA_IND");
1384 case DL_UDERROR_IND:
1385 return ("DL_UDERROR_IND");
1388 return ("DL_UDQOS_REQ");
1390 case DL_CONNECT_REQ:
1391 return ("DL_CONNECT_REQ");
1393 case DL_CONNECT_IND:
1394 return ("DL_CONNECT_IND");
1396 case DL_CONNECT_RES:
1397 return ("DL_CONNECT_RES");
1399 case DL_CONNECT_CON:
1400 return ("DL_CONNECT_CON");
1403 return ("DL_TOKEN_REQ");
1406 return ("DL_TOKEN_ACK");
1408 case DL_DISCONNECT_REQ:
1409 return ("DL_DISCONNECT_REQ");
1411 case DL_DISCONNECT_IND:
1412 return ("DL_DISCONNECT_IND");
1415 return ("DL_RESET_REQ");
1418 return ("DL_RESET_IND");
1421 return ("DL_RESET_RES");
1424 return ("DL_RESET_CON");
1427 pcap_snprintf(primbuf, primbufsize, "unknown primitive 0x%x",
1434 dlbindreq(int fd, bpf_u_int32 sap, char *ebuf)
1439 memset((char *)&req, 0, sizeof(req));
1440 req.dl_primitive = DL_BIND_REQ;
1441 /* XXX - what if neither of these are defined? */
1442 #if defined(DL_HP_RAWDLS)
1443 req.dl_max_conind = 1; /* XXX magic number */
1444 req.dl_service_mode = DL_HP_RAWDLS;
1445 #elif defined(DL_CLDLS)
1446 req.dl_service_mode = DL_CLDLS;
1450 return (send_request(fd, (char *)&req, sizeof(req), "bind", ebuf));
1454 dlbindack(int fd, char *bufp, char *ebuf, int *uerror)
1457 return (recv_ack(fd, DL_BIND_ACK_SIZE, "bind", bufp, ebuf, uerror));
1461 dlokack(int fd, const char *what, char *bufp, char *ebuf)
1464 return (recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf, NULL));
1469 dlinforeq(int fd, char *ebuf)
1473 req.dl_primitive = DL_INFO_REQ;
1475 return (send_request(fd, (char *)&req, sizeof(req), "info", ebuf));
1479 dlinfoack(int fd, char *bufp, char *ebuf)
1482 return (recv_ack(fd, DL_INFO_ACK_SIZE, "info", bufp, ebuf, NULL));
1485 #ifdef HAVE_DL_PASSIVE_REQ_T
1487 * Enable DLPI passive mode. We do not care if this request fails, as this
1488 * indicates the underlying DLPI device does not support link aggregation.
1491 dlpassive(int fd, char *ebuf)
1493 dl_passive_req_t req;
1494 bpf_u_int32 buf[MAXDLBUF];
1496 req.dl_primitive = DL_PASSIVE_REQ;
1498 if (send_request(fd, (char *)&req, sizeof(req), "dlpassive", ebuf) == 0)
1499 (void) dlokack(fd, "dlpassive", (char *)buf, ebuf);
1505 * There's an ack *if* there's an error.
1508 dlrawdatareq(int fd, const u_char *datap, int datalen)
1510 struct strbuf ctl, data;
1511 long buf[MAXDLBUF]; /* XXX - char? */
1512 union DL_primitives *dlp;
1515 dlp = MAKE_DL_PRIMITIVES(buf);
1517 dlp->dl_primitive = DL_HP_RAWDATA_REQ;
1518 dlen = DL_HP_RAWDATA_REQ_SIZE;
1521 * HP's documentation doesn't appear to show us supplying any
1522 * address pointed to by the control part of the message.
1523 * I think that's what raw mode means - you just send the raw
1524 * packet, you don't specify where to send it to, as that's
1525 * implied by the destination address.
1529 ctl.buf = (void *)buf;
1533 data.buf = (void *)datap;
1535 return (putmsg(fd, &ctl, &data, 0));
1537 #endif /* DL_HP_RAWDLS */
1539 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
1541 get_release(char *buf, size_t bufsize, bpf_u_int32 *majorp,
1542 bpf_u_int32 *minorp, bpf_u_int32 *microp)
1549 if (sysinfo(SI_RELEASE, buf, bufsize) < 0) {
1550 pcap_strlcpy(buf, "?", bufsize);
1554 if (!isdigit((unsigned char)*cp))
1556 *majorp = strtol(cp, &cp, 10);
1559 *minorp = strtol(cp, &cp, 10);
1562 *microp = strtol(cp, &cp, 10);
1566 #ifdef DL_HP_PPA_REQ
1568 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1573 * Determine ppa number that specifies ifname.
1575 * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
1576 * the code that's used here is the old code for HP-UX 10.x.
1578 * However, HP-UX 10.20, at least, appears to have such a member
1579 * in its "dl_hp_ppa_info_t" structure, so the new code is used.
1580 * The new code didn't work on an old 10.20 system on which Rick
1581 * Jones of HP tried it, but with later patches installed, it
1582 * worked - it appears that the older system had those members but
1583 * didn't put anything in them, so, if the search by name fails, we
1584 * do the old search.
1586 * Rick suggests that making sure your system is "up on the latest
1587 * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
1588 * that problem, as well as allowing libpcap to see packets sent
1589 * from the system on which the libpcap application is being run.
1590 * (On 10.20, in addition to getting the latest patches, you need
1591 * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
1592 * a posting to "comp.sys.hp.hpux" at
1594 * http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
1596 * says that, to see the machine's outgoing traffic, you'd need to
1597 * apply the right patches to your system, and also set that variable
1600 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1602 * which could be put in, for example, "/sbin/init.d/lan".
1604 * Setting the variable is not necessary on HP-UX 11.x.
1607 get_dlpi_ppa(register int fd, register const char *device, register u_int unit,
1608 u_int *ppa, register char *ebuf)
1610 register dl_hp_ppa_ack_t *ap;
1611 register dl_hp_ppa_info_t *ipstart, *ip;
1614 register u_long majdev;
1615 struct stat statbuf;
1616 dl_hp_ppa_req_t req;
1619 dl_hp_ppa_ack_t *dlp;
1623 memset((char *)&req, 0, sizeof(req));
1624 req.dl_primitive = DL_HP_PPA_REQ;
1626 memset((char *)buf, 0, sizeof(buf));
1627 if (send_request(fd, (char *)&req, sizeof(req), "hpppa", ebuf) < 0)
1628 return (PCAP_ERROR);
1630 ctl.maxlen = DL_HP_PPA_ACK_SIZE;
1632 ctl.buf = (char *)buf;
1636 * DLPI may return a big chunk of data for a DL_HP_PPA_REQ. The normal
1637 * recv_ack will fail because it set the maxlen to MAXDLBUF (8192)
1638 * which is NOT big enough for a DL_HP_PPA_REQ.
1640 * This causes libpcap applications to fail on a system with HP-APA
1643 * To figure out how big the returned data is, we first call getmsg
1644 * to get the small head and peek at the head to get the actual data
1645 * length, and then issue another getmsg to get the actual PPA data.
1647 /* get the head first */
1648 if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
1649 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1650 errno, "get_dlpi_ppa: hpppa getmsg");
1651 return (PCAP_ERROR);
1653 if (ctl.len == -1) {
1654 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1655 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1656 return (PCAP_ERROR);
1659 dlp = (dl_hp_ppa_ack_t *)ctl.buf;
1660 if (dlp->dl_primitive != DL_HP_PPA_ACK) {
1661 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1662 "get_dlpi_ppa: hpppa unexpected primitive ack 0x%x",
1663 (bpf_u_int32)dlp->dl_primitive);
1664 return (PCAP_ERROR);
1667 if ((size_t)ctl.len < DL_HP_PPA_ACK_SIZE) {
1668 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1669 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1670 ctl.len, (unsigned long)DL_HP_PPA_ACK_SIZE);
1671 return (PCAP_ERROR);
1674 /* allocate buffer */
1675 if ((ppa_data_buf = (char *)malloc(dlp->dl_length)) == NULL) {
1676 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1677 errno, "get_dlpi_ppa: hpppa malloc");
1678 return (PCAP_ERROR);
1680 ctl.maxlen = dlp->dl_length;
1682 ctl.buf = (char *)ppa_data_buf;
1684 if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
1685 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1686 errno, "get_dlpi_ppa: hpppa getmsg");
1688 return (PCAP_ERROR);
1690 if (ctl.len == -1) {
1691 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1692 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1693 return (PCAP_ERROR);
1695 if ((u_int)ctl.len < dlp->dl_length) {
1696 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1697 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1698 ctl.len, (unsigned long)dlp->dl_length);
1700 return (PCAP_ERROR);
1703 ap = (dl_hp_ppa_ack_t *)buf;
1704 ipstart = (dl_hp_ppa_info_t *)ppa_data_buf;
1707 #ifdef HAVE_DL_HP_PPA_INFO_T_DL_MODULE_ID_1
1709 * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
1710 * member that should, in theory, contain the part of the
1711 * name for the device that comes before the unit number,
1712 * and should also have a "dl_module_id_2" member that may
1713 * contain an alternate name (e.g., I think Ethernet devices
1714 * have both "lan", for "lanN", and "snap", for "snapN", with
1715 * the former being for Ethernet packets and the latter being
1716 * for 802.3/802.2 packets).
1718 * Search for the device that has the specified name and
1721 for (i = 0; i < ap->dl_count; i++) {
1722 if ((strcmp((const char *)ip->dl_module_id_1, device) == 0 ||
1723 strcmp((const char *)ip->dl_module_id_2, device) == 0) &&
1724 ip->dl_instance_num == unit)
1727 ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
1731 * We don't have that member, so the search is impossible; make it
1732 * look as if the search failed.
1737 if (i == ap->dl_count) {
1739 * Well, we didn't, or can't, find the device by name.
1741 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1742 * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
1743 * doesn't seem to fill them in unless the system is
1744 * at a reasonably up-to-date patch level.
1746 * Older HP-UX 10.x systems might not have those fields
1749 * Therefore, we'll search for the entry with the major
1750 * device number of a device with the name "/dev/<dev><unit>",
1751 * if such a device exists, as the old code did.
1753 pcap_snprintf(dname, sizeof(dname), "/dev/%s%u", device, unit);
1754 if (stat(dname, &statbuf) < 0) {
1755 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1756 errno, "stat: %s", dname);
1757 return (PCAP_ERROR);
1759 majdev = major(statbuf.st_rdev);
1763 for (i = 0; i < ap->dl_count; i++) {
1764 if (ip->dl_mjr_num == majdev &&
1765 ip->dl_instance_num == unit)
1768 ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
1771 if (i == ap->dl_count) {
1772 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1773 "can't find /dev/dlpi PPA for %s%u", device, unit);
1774 return (PCAP_ERROR_NO_SUCH_DEVICE);
1776 if (ip->dl_hdw_state == HDW_DEAD) {
1777 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1778 "%s%d: hardware state: DOWN\n", device, unit);
1780 return (PCAP_ERROR);
1790 * Under HP-UX 9, there is no good way to determine the ppa.
1791 * So punt and read it from /dev/kmem.
1793 static struct nlist nl[] = {
1799 static char path_vmunix[] = "/hp-ux";
1801 /* Determine ppa number that specifies ifname */
1803 get_dlpi_ppa(register int fd, register const char *ifname, register u_int unit,
1804 u_int *ppa, register char *ebuf)
1806 register const char *cp;
1810 char if_name[sizeof(ifnet.if_name) + 1];
1812 cp = strrchr(ifname, '/');
1815 if (nlist(path_vmunix, &nl) < 0) {
1816 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "nlist %s failed",
1818 return (PCAP_ERROR);
1820 if (nl[NL_IFNET].n_value == 0) {
1821 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE,
1822 "could't find %s kernel symbol",
1823 nl[NL_IFNET].n_name);
1824 return (PCAP_ERROR);
1826 kd = open("/dev/kmem", O_RDONLY);
1828 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1829 errno, "kmem open");
1830 return (PCAP_ERROR);
1832 if (dlpi_kread(kd, nl[NL_IFNET].n_value,
1833 &addr, sizeof(addr), ebuf) < 0) {
1835 return (PCAP_ERROR);
1837 for (; addr != NULL; addr = ifnet.if_next) {
1838 if (dlpi_kread(kd, (off_t)addr,
1839 &ifnet, sizeof(ifnet), ebuf) < 0 ||
1840 dlpi_kread(kd, (off_t)ifnet.if_name,
1841 if_name, sizeof(ifnet.if_name), ebuf) < 0) {
1843 return (PCAP_ERROR);
1845 if_name[sizeof(ifnet.if_name)] = '\0';
1846 if (strcmp(if_name, ifname) == 0 && ifnet.if_unit == unit) {
1847 *ppa = ifnet.if_index;
1852 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "Can't find %s", ifname);
1853 return (PCAP_ERROR_NO_SUCH_DEVICE);
1857 dlpi_kread(register int fd, register off_t addr,
1858 register void *buf, register u_int len, register char *ebuf)
1862 if (lseek(fd, addr, SEEK_SET) < 0) {
1863 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1867 cc = read(fd, buf, len);
1869 pcap_fmt_errmsg_for_errno(ebuf, PCAP_ERRBUF_SIZE,
1872 } else if (cc != len) {
1873 pcap_snprintf(ebuf, PCAP_ERRBUF_SIZE, "short read (%d != %d)", cc,
1882 pcap_create_interface(const char *device _U_, char *ebuf)
1886 struct pcap_dlpi *pd;
1889 p = pcap_create_common(ebuf, sizeof (struct pcap_dlpi));
1895 pd->send_fd = -1; /* it hasn't been opened yet */
1898 p->activate_op = pcap_activate_dlpi;
1903 * Libpcap version string.
1906 pcap_lib_version(void)
1908 return (PCAP_VERSION_STRING);