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"
125 #ifndef PCAP_DEV_PREFIX
127 #define PCAP_DEV_PREFIX "/dev/dlpi"
129 #define PCAP_DEV_PREFIX "/dev"
133 #define MAXDLBUF 8192
136 static char *split_dname(char *, int *, char *);
137 static int dl_doattach(int, int, char *);
139 static int dl_dohpuxbind(int, char *);
141 static int dlpromiscon(pcap_t
*, bpf_u_int32
);
142 static int dlbindreq(int, bpf_u_int32
, char *);
143 static int dlbindack(int, char *, char *, int *);
144 static int dlokack(int, const char *, char *, char *);
145 static int dlinforeq(int, char *);
146 static int dlinfoack(int, char *, char *);
148 #ifdef HAVE_DLPI_PASSIVE
149 static void dlpassive(int, char *);
153 static int dlrawdatareq(int, const u_char
*, int);
155 static int recv_ack(int, int, const char *, char *, char *, int *);
156 static char *dlstrerror(bpf_u_int32
);
157 static char *dlprim(bpf_u_int32
);
158 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
159 static char *get_release(bpf_u_int32
*, bpf_u_int32
*, bpf_u_int32
*);
161 static int send_request(int, char *, int, char *, char *);
163 static int dlpi_kread(int, off_t
, void *, u_int
, char *);
166 static int get_dlpi_ppa(int, const char *, int, char *);
169 /* XXX Needed by HP-UX (at least) */
170 static bpf_u_int32 ctlbuf
[MAXDLBUF
];
171 static struct strbuf ctl
= {
178 * Cast a buffer to "union DL_primitives" without provoking warnings
181 #define MAKE_DL_PRIMITIVES(ptr) ((union DL_primitives *)(void *)(ptr))
184 pcap_read_dlpi(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
194 data
.buf
= (char *)p
->buffer
+ p
->offset
;
195 data
.maxlen
= p
->bufsize
;
199 * Has "pcap_breakloop()" been called?
203 * Yes - clear the flag that indicates
204 * that it has, and return -2 to
205 * indicate that we were told to
206 * break out of the loop.
212 * XXX - check for the DLPI primitive, which
213 * would be DL_HP_RAWDATA_IND on HP-UX
214 * if we're in raw mode?
216 if (getmsg(p
->fd
, &ctl
, &data
, &flags
) < 0) {
217 /* Don't choke when we get ptraced */
227 strlcpy(p
->errbuf
, pcap_strerror(errno
),
233 bp
= (u_char
*)p
->buffer
+ p
->offset
;
237 return (pcap_process_pkts(p
, callback
, user
, cnt
, bp
, cc
));
241 pcap_inject_dlpi(pcap_t
*p
, const void *buf
, size_t size
)
244 struct pcap_dlpi
*pd
= p
->priv
;
248 #if defined(DLIOCRAW)
249 ret
= write(p
->fd
, buf
, size
);
251 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
252 pcap_strerror(errno
));
255 #elif defined(DL_HP_RAWDLS)
256 if (pd
->send_fd
< 0) {
257 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
258 "send: Output FD couldn't be opened");
261 ret
= dlrawdatareq(pd
->send_fd
, buf
, size
);
263 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
264 pcap_strerror(errno
));
268 * putmsg() returns either 0 or -1; it doesn't indicate how
269 * many bytes were written (presumably they were all written
270 * or none of them were written). OpenBSD's pcap_inject()
271 * returns the number of bytes written, so, for API compatibility,
272 * we return the number of bytes we were told to write.
275 #else /* no raw mode */
277 * XXX - this is a pain, because you might have to extract
278 * the address from the packet and use it in a DL_UNITDATA_REQ
279 * request. That would be dependent on the link-layer type.
281 * I also don't know what SAP you'd have to bind the descriptor
282 * to, or whether you'd need separate "receive" and "send" FDs,
283 * nor do I know whether you'd need different bindings for
284 * D/I/X Ethernet and 802.3, or for {FDDI,Token Ring} plus
285 * 802.2 and {FDDI,Token Ring} plus 802.2 plus SNAP.
287 * So, for now, we just return a "you can't send" indication,
288 * and leave it up to somebody with a DLPI-based system lacking
289 * both DLIOCRAW and DL_HP_RAWDLS to supply code to implement
290 * packet transmission on that system. If they do, they should
291 * send it to us - but should not send us code that assumes
292 * Ethernet; if the code doesn't work on non-Ethernet interfaces,
293 * it should check "p->linktype" and reject the send request if
294 * it's anything other than DLT_EN10MB.
296 strlcpy(p
->errbuf
, "send: Not supported on this version of this OS",
299 #endif /* raw mode */
304 #define DL_IPATM 0x12 /* ATM Classical IP interface */
312 #define A_GET_UNITS (('A'<<8)|118)
313 #endif /* A_GET_UNITS */
314 #ifndef A_PROMISCON_REQ
315 #define A_PROMISCON_REQ (('A'<<8)|121)
316 #endif /* A_PROMISCON_REQ */
317 #endif /* HAVE_SOLARIS */
320 pcap_cleanup_dlpi(pcap_t
*p
)
323 struct pcap_dlpi
*pd
= p
->priv
;
325 if (pd
->send_fd
>= 0) {
330 pcap_cleanup_live_common(p
);
334 open_dlpi_device(const char *name
, int *ppa
, char *errbuf
)
340 #ifndef HAVE_DEV_DLPI
346 ** Remove any "/dev/" on the front of the device.
348 cp
= strrchr(name
, '/');
350 strlcpy(dname
, name
, sizeof(dname
));
352 strlcpy(dname
, cp
+ 1, sizeof(dname
));
355 * Split the device name into a device type name and a unit number;
356 * chop off the unit number, so "dname" is just a device type name.
358 cp
= split_dname(dname
, ppa
, errbuf
);
360 return (PCAP_ERROR_NO_SUCH_DEVICE
);
364 * Use "/dev/dlpi" as the device.
366 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
367 * the "dl_mjr_num" field is for the "major number of interface
368 * driver"; that's the major of "/dev/dlpi" on the system on
369 * which I tried this, but there may be DLPI devices that
370 * use a different driver, in which case we may need to
371 * search "/dev" for the appropriate device with that major
372 * device number, rather than hardwiring "/dev/dlpi".
375 if ((fd
= open(cp
, O_RDWR
)) < 0) {
376 if (errno
== EPERM
|| errno
== EACCES
)
377 status
= PCAP_ERROR_PERM_DENIED
;
380 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
381 "%s: %s", cp
, pcap_strerror(errno
));
386 * Get a table of all PPAs for that device, and search that
387 * table for the specified device type name and unit number.
389 *ppa
= get_dlpi_ppa(fd
, dname
, *ppa
, errbuf
);
396 * If the device name begins with "/", assume it begins with
397 * the pathname of the directory containing the device to open;
398 * otherwise, concatenate the device directory name and the
402 strlcpy(dname
, name
, sizeof(dname
));
404 pcap_snprintf(dname
, sizeof(dname
), "%s/%s", PCAP_DEV_PREFIX
,
408 * Get the unit number, and a pointer to the end of the device
411 cp
= split_dname(dname
, ppa
, errbuf
);
413 return (PCAP_ERROR_NO_SUCH_DEVICE
);
416 * Make a copy of the device pathname, and then remove the unit
417 * number from the device pathname.
419 strlcpy(dname2
, dname
, sizeof(dname
));
422 /* Try device without unit number */
423 if ((fd
= open(dname
, O_RDWR
)) < 0) {
424 if (errno
!= ENOENT
) {
425 if (errno
== EPERM
|| errno
== EACCES
)
426 status
= PCAP_ERROR_PERM_DENIED
;
429 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "%s: %s", dname
,
430 pcap_strerror(errno
));
434 /* Try again with unit number */
435 if ((fd
= open(dname2
, O_RDWR
)) < 0) {
436 if (errno
== ENOENT
) {
437 status
= PCAP_ERROR_NO_SUCH_DEVICE
;
440 * We provide an error message even
441 * for this error, for diagnostic
442 * purposes (so that, for example,
443 * the app can show the message if the
446 * In it, we just report "No DLPI device
447 * found" with the device name, so people
448 * don't get confused and think, for example,
449 * that if they can't capture on "lo0"
450 * on Solaris prior to Solaris 11 the fix
451 * is to change libpcap (or the application
452 * that uses it) to look for something other
453 * than "/dev/lo0", as the fix is to use
454 * Solaris 11 or some operating system
455 * other than Solaris - you just *can't*
456 * capture on a loopback interface
457 * on Solaris prior to Solaris 11, the lack
458 * of a DLPI device for the loopback
459 * interface is just a symptom of that
462 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
463 "%s: No DLPI device found", name
);
465 if (errno
== EPERM
|| errno
== EACCES
)
466 status
= PCAP_ERROR_PERM_DENIED
;
469 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "%s: %s",
470 dname2
, pcap_strerror(errno
));
474 /* XXX Assume unit zero */
482 pcap_activate_dlpi(pcap_t
*p
)
485 struct pcap_dlpi
*pd
= p
->priv
;
493 register dl_info_ack_t
*infop
;
494 #ifdef HAVE_SYS_BUFMOD_H
497 register char *release
;
498 bpf_u_int32 osmajor
, osminor
, osmicro
;
501 bpf_u_int32 buf
[MAXDLBUF
];
503 p
->fd
= open_dlpi_device(p
->opt
.device
, &ppa
, p
->errbuf
);
511 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
512 * receiving packets on the same descriptor - you need separate
513 * descriptors for sending and receiving, bound to different SAPs.
515 * If the open fails, we just leave -1 in "pd->send_fd" and reject
516 * attempts to send packets, just as if, in pcap-bpf.c, we fail
517 * to open the BPF device for reading and writing, we just try
518 * to open it for reading only and, if that succeeds, just let
519 * the send attempts fail.
521 pd
->send_fd
= open("/dev/dlpi", O_RDWR
);
525 ** Attach if "style 2" provider
527 if (dlinforeq(p
->fd
, p
->errbuf
) < 0 ||
528 dlinfoack(p
->fd
, (char *)buf
, p
->errbuf
) < 0) {
532 infop
= &(MAKE_DL_PRIMITIVES(buf
))->info_ack
;
534 if (infop
->dl_mac_type
== DL_IPATM
)
537 if (infop
->dl_provider_style
== DL_STYLE2
) {
538 retv
= dl_doattach(p
->fd
, ppa
, p
->errbuf
);
544 if (pd
->send_fd
>= 0) {
545 retv
= dl_doattach(pd
->send_fd
, ppa
, p
->errbuf
);
556 * This device exists, but we don't support monitor mode
557 * any platforms that support DLPI.
559 status
= PCAP_ERROR_RFMON_NOTSUP
;
563 #ifdef HAVE_DLPI_PASSIVE
565 * Enable Passive mode to be able to capture on aggregated link.
566 * Not supported in all Solaris versions.
568 dlpassive(p
->fd
, p
->errbuf
);
571 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
572 ** skip if using SINIX)
574 #if !defined(HAVE_HPUX9) && !defined(HAVE_HPUX10_20_OR_LATER) && !defined(sinix)
578 ** According to IBM's AIX Support Line, the dl_sap value
579 ** should not be less than 0x600 (1536) for standard Ethernet.
580 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
581 ** format or invalid" - errors if we use 1537 on the "tr0"
582 ** device, which, given that its name starts with "tr" and that
583 ** it's IBM, probably means a Token Ring device. (Perhaps we
584 ** need to use 1537 on "/dev/dlpi/en" because that device is for
585 ** D/I/X Ethernet, the "SAP" is actually an Ethernet type, and
586 ** it rejects invalid Ethernet types.)
588 ** So if 1537 fails, we try 2, as Hyung Sik Yoon of IBM Korea
589 ** says that works on Token Ring (he says that 0 does *not*
590 ** work; perhaps that's considered an invalid LLC SAP value - I
591 ** assume the SAP value in a DLPI bind is an LLC SAP for network
592 ** types that use 802.2 LLC).
594 if ((dlbindreq(p
->fd
, 1537, p
->errbuf
) < 0 &&
595 dlbindreq(p
->fd
, 2, p
->errbuf
) < 0) ||
596 dlbindack(p
->fd
, (char *)buf
, p
->errbuf
, NULL
) < 0) {
600 #elif defined(DL_HP_RAWDLS)
602 ** HP-UX 10.0x and 10.1x.
604 if (dl_dohpuxbind(p
->fd
, p
->errbuf
) < 0) {
608 if (pd
->send_fd
>= 0) {
610 ** XXX - if this fails, just close send_fd and
611 ** set it to -1, so that you can't send but can
614 if (dl_dohpuxbind(pd
->send_fd
, p
->errbuf
) < 0) {
619 #else /* neither AIX nor HP-UX */
621 ** Not Sinix, and neither AIX nor HP-UX - Solaris, and any other
624 if (dlbindreq(p
->fd
, 0, p
->errbuf
) < 0 ||
625 dlbindack(p
->fd
, (char *)buf
, p
->errbuf
, NULL
) < 0) {
629 #endif /* AIX vs. HP-UX vs. other */
630 #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
635 ** Have to turn on some special ATM promiscuous mode
637 ** Do *NOT* turn regular promiscuous mode on; it doesn't
638 ** help, and may break things.
640 if (strioctl(p
->fd
, A_PROMISCON_REQ
, 0, NULL
) < 0) {
642 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
643 "A_PROMISCON_REQ: %s", pcap_strerror(errno
));
648 if (p
->opt
.promisc
) {
650 ** Enable promiscuous (not necessary on send FD)
652 retv
= dlpromiscon(p
, DL_PROMISC_PHYS
);
654 if (retv
== PCAP_ERROR_PERM_DENIED
)
655 status
= PCAP_ERROR_PROMISC_PERM_DENIED
;
662 ** Try to enable multicast (you would have thought
663 ** promiscuous would be sufficient). (Skip if using
664 ** HP-UX or SINIX) (Not necessary on send FD)
666 #if !defined(__hpux) && !defined(sinix)
667 retv
= dlpromiscon(p
, DL_PROMISC_MULTI
);
669 status
= PCAP_WARNING
;
673 ** Try to enable SAP promiscuity (when not in promiscuous mode
674 ** when using HP-UX, when not doing SunATM on Solaris, and never
675 ** under SINIX) (Not necessary on send FD)
679 /* HP-UX - only do this when not in promiscuous mode */
680 if (!p
->opt
.promisc
) {
681 #elif defined(HAVE_SOLARIS)
682 /* Solaris - don't do this on SunATM devices */
685 /* Everything else (except for SINIX) - always do this */
688 retv
= dlpromiscon(p
, DL_PROMISC_SAP
);
690 if (p
->opt
.promisc
) {
692 * Not fatal, since the DL_PROMISC_PHYS mode
695 * Report it as a warning, however.
697 status
= PCAP_WARNING
;
710 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
711 ** promiscuous options.
713 #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
714 if (dl_dohpuxbind(p
->fd
, p
->errbuf
) < 0) {
719 ** We don't set promiscuous mode on the send FD, but we'll defer
720 ** binding it anyway, just to keep the HP-UX 9/10.20 or later
723 if (pd
->send_fd
>= 0) {
725 ** XXX - if this fails, just close send_fd and
726 ** set it to -1, so that you can't send but can
729 if (dl_dohpuxbind(pd
->send_fd
, p
->errbuf
) < 0) {
737 ** Determine link type
738 ** XXX - get SAP length and address length as well, for use
739 ** when sending packets.
741 if (dlinforeq(p
->fd
, p
->errbuf
) < 0 ||
742 dlinfoack(p
->fd
, (char *)buf
, p
->errbuf
) < 0) {
747 infop
= &(MAKE_DL_PRIMITIVES(buf
))->info_ack
;
748 if (pcap_process_mactype(p
, infop
->dl_mac_type
) != 0) {
755 ** This is a non standard SunOS hack to get the full raw link-layer
758 if (strioctl(p
->fd
, DLIOCRAW
, 0, NULL
) < 0) {
760 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "DLIOCRAW: %s",
761 pcap_strerror(errno
));
766 #ifdef HAVE_SYS_BUFMOD_H
770 ** There is a bug in bufmod(7). When dealing with messages of
771 ** less than snaplen size it strips data from the beginning not
774 ** This bug is fixed in 5.3.2. Also, there is a patch available.
775 ** Ask for bugid 1149065.
778 release
= get_release(&osmajor
, &osminor
, &osmicro
);
779 if (osmajor
== 5 && (osminor
<= 2 || (osminor
== 3 && osmicro
< 2)) &&
780 getenv("BUFMOD_FIXED") == NULL
) {
781 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
782 "WARNING: bufmod is broken in SunOS %s; ignoring snaplen.",
785 status
= PCAP_WARNING
;
789 /* Push and configure bufmod. */
790 if (pcap_conf_bufmod(p
, ss
) != 0) {
797 ** As the last operation flush the read side.
799 if (ioctl(p
->fd
, I_FLUSH
, FLUSHR
) != 0) {
801 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "FLUSHR: %s",
802 pcap_strerror(errno
));
806 /* Allocate data buffer. */
807 if (pcap_alloc_databuf(p
) != 0) {
815 * "p->fd" is an FD for a STREAMS device, so "select()" and
816 * "poll()" should work on it.
818 p
->selectable_fd
= p
->fd
;
820 p
->read_op
= pcap_read_dlpi
;
821 p
->inject_op
= pcap_inject_dlpi
;
822 p
->setfilter_op
= install_bpf_program
; /* no kernel filtering */
823 p
->setdirection_op
= NULL
; /* Not implemented.*/
824 p
->set_datalink_op
= NULL
; /* can't change data link type */
825 p
->getnonblock_op
= pcap_getnonblock_fd
;
826 p
->setnonblock_op
= pcap_setnonblock_fd
;
827 p
->stats_op
= pcap_stats_dlpi
;
828 p
->cleanup_op
= pcap_cleanup_dlpi
;
832 pcap_cleanup_dlpi(p
);
837 * Split a device name into a device type name and a unit number;
838 * return the a pointer to the beginning of the unit number, which
839 * is the end of the device type name, and set "*unitp" to the unit
842 * Returns NULL on error, and fills "ebuf" with an error message.
845 split_dname(char *device
, int *unitp
, char *ebuf
)
852 * Look for a number at the end of the device name string.
854 cp
= device
+ strlen(device
) - 1;
855 if (*cp
< '0' || *cp
> '9') {
856 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s missing unit number",
861 /* Digits at end of string are unit number */
862 while (cp
-1 >= device
&& *(cp
-1) >= '0' && *(cp
-1) <= '9')
866 unit
= strtol(cp
, &eos
, 10);
868 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s bad unit number", device
);
871 if (errno
== ERANGE
|| unit
> INT_MAX
) {
872 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number too large",
877 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number is negative",
886 dl_doattach(int fd
, int ppa
, char *ebuf
)
889 bpf_u_int32 buf
[MAXDLBUF
];
892 req
.dl_primitive
= DL_ATTACH_REQ
;
894 if (send_request(fd
, (char *)&req
, sizeof(req
), "attach", ebuf
) < 0)
897 err
= dlokack(fd
, "attach", (char *)buf
, ebuf
);
905 dl_dohpuxbind(int fd
, char *ebuf
)
909 bpf_u_int32 buf
[MAXDLBUF
];
912 * XXX - we start at 22 because we used to use only 22, but
913 * that was just because that was the value used in some
914 * sample code from HP. With what value *should* we start?
915 * Does it matter, given that we're enabling SAP promiscuity
920 if (dlbindreq(fd
, hpsap
, ebuf
) < 0)
922 if (dlbindack(fd
, (char *)buf
, ebuf
, &uerror
) >= 0)
925 * For any error other than a UNIX EBUSY, give up.
927 if (uerror
!= EBUSY
) {
929 * dlbindack() has already filled in ebuf for
936 * For EBUSY, try the next SAP value; that means that
937 * somebody else is using that SAP. Clear ebuf so
938 * that application doesn't report the "Device busy"
939 * error as a warning.
945 "All SAPs from 22 through 100 are in use",
954 #define STRINGIFY(n) #n
957 dlpromiscon(pcap_t
*p
, bpf_u_int32 level
)
959 dl_promiscon_req_t req
;
960 bpf_u_int32 buf
[MAXDLBUF
];
963 req
.dl_primitive
= DL_PROMISCON_REQ
;
964 req
.dl_level
= level
;
965 if (send_request(p
->fd
, (char *)&req
, sizeof(req
), "promiscon",
968 err
= dlokack(p
->fd
, "promiscon" STRINGIFY(level
), (char *)buf
,
976 * Not all interfaces are DLPI interfaces, and thus not all interfaces
977 * can be opened with DLPI (for example, the loopback interface is not
978 * a DLPI interface on Solaris prior to Solaris 11), so try to open
979 * the specified interface; return 0 if we fail with PCAP_ERROR_NO_SUCH_DEVICE
983 is_dlpi_interface(const char *name
)
987 char errbuf
[PCAP_ERRBUF_SIZE
];
989 fd
= open_dlpi_device(name
, &ppa
, errbuf
);
992 * Error - was it PCAP_ERROR_NO_SUCH_DEVICE?
994 if (fd
== PCAP_ERROR_NO_SUCH_DEVICE
) {
996 * Yes, so we can't open this because it's
997 * not a DLPI interface.
1002 * No, so, in the case where there's a single DLPI
1003 * device for all interfaces of this type ("style
1004 * 2" providers?), we don't know whether it's a DLPI
1005 * interface or not, as we didn't try an attach.
1006 * Say it is a DLPI device, so that the user can at
1007 * least try to open it and report the error (which
1008 * is probably "you don't have permission to open that
1009 * DLPI device"; reporting those interfaces means
1010 * users will ask "why am I getting a permissions error
1011 * when I try to capture" rather than "why am I not
1012 * seeing any interfaces", making the underlying problem
1026 pcap_platform_finddevs(pcap_if_t
**alldevsp
, char *errbuf
)
1032 char pad
[516]; /* XXX - must be at least 513; is 516
1040 * Get the list of regular interfaces first.
1042 if (pcap_findalldevs_interfaces(alldevsp
, errbuf
, is_dlpi_interface
) == -1)
1043 return (-1); /* failure */
1047 * We may have to do special magic to get ATM devices.
1049 if ((fd
= open("/dev/ba", O_RDWR
)) < 0) {
1051 * We couldn't open the "ba" device.
1052 * For now, just give up; perhaps we should
1053 * return an error if the problem is neither
1054 * a "that device doesn't exist" error (ENOENT,
1055 * ENXIO, etc.) or a "you're not allowed to do
1056 * that" error (EPERM, EACCES).
1061 if (strioctl(fd
, A_GET_UNITS
, sizeof(buf
), (char *)&buf
) < 0) {
1062 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "A_GET_UNITS: %s",
1063 pcap_strerror(errno
));
1066 for (i
= 0; i
< buf
.nunits
; i
++) {
1067 pcap_snprintf(baname
, sizeof baname
, "ba%u", i
);
1068 if (pcap_add_if(alldevsp
, baname
, 0, NULL
, errbuf
) < 0)
1077 send_request(int fd
, char *ptr
, int len
, char *what
, char *ebuf
)
1087 if (putmsg(fd
, &ctl
, (struct strbuf
*) NULL
, flags
) < 0) {
1088 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1089 "send_request: putmsg \"%s\": %s",
1090 what
, pcap_strerror(errno
));
1097 recv_ack(int fd
, int size
, const char *what
, char *bufp
, char *ebuf
, int *uerror
)
1099 union DL_primitives
*dlp
;
1104 * Clear out "*uerror", so it's only set for DL_ERROR_ACK/DL_SYSERR,
1105 * making that the only place where EBUSY is treated specially.
1110 ctl
.maxlen
= MAXDLBUF
;
1115 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1116 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s getmsg: %s",
1117 what
, pcap_strerror(errno
));
1118 return (PCAP_ERROR
);
1121 dlp
= MAKE_DL_PRIMITIVES(ctl
.buf
);
1122 switch (dlp
->dl_primitive
) {
1127 #ifdef DL_HP_PPA_ACK
1134 switch (dlp
->error_ack
.dl_errno
) {
1138 *uerror
= dlp
->error_ack
.dl_unix_errno
;
1139 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1140 "recv_ack: %s: UNIX error - %s",
1141 what
, pcap_strerror(dlp
->error_ack
.dl_unix_errno
));
1142 if (dlp
->error_ack
.dl_unix_errno
== EPERM
||
1143 dlp
->error_ack
.dl_unix_errno
== EACCES
)
1144 return (PCAP_ERROR_PERM_DENIED
);
1148 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s: %s",
1149 what
, dlstrerror(dlp
->error_ack
.dl_errno
));
1150 if (dlp
->error_ack
.dl_errno
== DL_BADPPA
)
1151 return (PCAP_ERROR_NO_SUCH_DEVICE
);
1152 else if (dlp
->error_ack
.dl_errno
== DL_ACCESS
)
1153 return (PCAP_ERROR_PERM_DENIED
);
1156 return (PCAP_ERROR
);
1159 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1160 "recv_ack: %s: Unexpected primitive ack %s",
1161 what
, dlprim(dlp
->dl_primitive
));
1162 return (PCAP_ERROR
);
1165 if (ctl
.len
< size
) {
1166 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1167 "recv_ack: %s: Ack too small (%d < %d)",
1168 what
, ctl
.len
, size
);
1169 return (PCAP_ERROR
);
1175 dlstrerror(bpf_u_int32 dl_errno
)
1177 static char errstring
[6+2+8+1];
1182 return ("Improper permissions for request");
1185 return ("DLSAP addr in improper format or invalid");
1188 return ("Seq number not from outstand DL_CONN_IND");
1191 return ("User data exceeded provider limit");
1194 #ifdef HAVE_DEV_DLPI
1196 * With a single "/dev/dlpi" device used for all
1197 * DLPI providers, PPAs have nothing to do with
1200 return ("Specified PPA was invalid");
1203 * We have separate devices for separate devices;
1204 * the PPA is just the unit number.
1206 return ("Specified PPA (device unit) was invalid");
1210 return ("Primitive received not known by provider");
1212 case DL_BADQOSPARAM
:
1213 return ("QOS parameters contained invalid values");
1216 return ("QOS structure type is unknown/unsupported");
1219 return ("Bad LSAP selector");
1222 return ("Token used not an active stream");
1225 return ("Attempted second bind with dl_max_conind");
1228 return ("Physical link initialization failed");
1231 return ("Provider couldn't allocate alternate address");
1234 return ("Physical link not initialized");
1237 return ("Primitive issued in improper state");
1240 return ("UNIX system error occurred");
1242 case DL_UNSUPPORTED
:
1243 return ("Requested service not supplied by provider");
1245 case DL_UNDELIVERABLE
:
1246 return ("Previous data unit could not be delivered");
1248 case DL_NOTSUPPORTED
:
1249 return ("Primitive is known but not supported");
1252 return ("Limit exceeded");
1255 return ("Promiscuous mode not enabled");
1258 return ("Other streams for PPA in post-attached");
1261 return ("Automatic handling XID&TEST not supported");
1264 return ("Automatic handling of XID not supported");
1267 return ("Automatic handling of TEST not supported");
1270 return ("Automatic handling of XID response");
1273 return ("Automatic handling of TEST response");
1276 return ("Pending outstanding connect indications");
1279 sprintf(errstring
, "Error %02x", dl_errno
);
1285 dlprim(bpf_u_int32 prim
)
1287 static char primbuf
[80];
1292 return ("DL_INFO_REQ");
1295 return ("DL_INFO_ACK");
1298 return ("DL_ATTACH_REQ");
1301 return ("DL_DETACH_REQ");
1304 return ("DL_BIND_REQ");
1307 return ("DL_BIND_ACK");
1310 return ("DL_UNBIND_REQ");
1313 return ("DL_OK_ACK");
1316 return ("DL_ERROR_ACK");
1318 case DL_SUBS_BIND_REQ
:
1319 return ("DL_SUBS_BIND_REQ");
1321 case DL_SUBS_BIND_ACK
:
1322 return ("DL_SUBS_BIND_ACK");
1324 case DL_UNITDATA_REQ
:
1325 return ("DL_UNITDATA_REQ");
1327 case DL_UNITDATA_IND
:
1328 return ("DL_UNITDATA_IND");
1330 case DL_UDERROR_IND
:
1331 return ("DL_UDERROR_IND");
1334 return ("DL_UDQOS_REQ");
1336 case DL_CONNECT_REQ
:
1337 return ("DL_CONNECT_REQ");
1339 case DL_CONNECT_IND
:
1340 return ("DL_CONNECT_IND");
1342 case DL_CONNECT_RES
:
1343 return ("DL_CONNECT_RES");
1345 case DL_CONNECT_CON
:
1346 return ("DL_CONNECT_CON");
1349 return ("DL_TOKEN_REQ");
1352 return ("DL_TOKEN_ACK");
1354 case DL_DISCONNECT_REQ
:
1355 return ("DL_DISCONNECT_REQ");
1357 case DL_DISCONNECT_IND
:
1358 return ("DL_DISCONNECT_IND");
1361 return ("DL_RESET_REQ");
1364 return ("DL_RESET_IND");
1367 return ("DL_RESET_RES");
1370 return ("DL_RESET_CON");
1373 (void) sprintf(primbuf
, "unknown primitive 0x%x", prim
);
1379 dlbindreq(int fd
, bpf_u_int32 sap
, char *ebuf
)
1384 memset((char *)&req
, 0, sizeof(req
));
1385 req
.dl_primitive
= DL_BIND_REQ
;
1386 /* XXX - what if neither of these are defined? */
1387 #if defined(DL_HP_RAWDLS)
1388 req
.dl_max_conind
= 1; /* XXX magic number */
1389 req
.dl_service_mode
= DL_HP_RAWDLS
;
1390 #elif defined(DL_CLDLS)
1391 req
.dl_service_mode
= DL_CLDLS
;
1395 return (send_request(fd
, (char *)&req
, sizeof(req
), "bind", ebuf
));
1399 dlbindack(int fd
, char *bufp
, char *ebuf
, int *uerror
)
1402 return (recv_ack(fd
, DL_BIND_ACK_SIZE
, "bind", bufp
, ebuf
, uerror
));
1406 dlokack(int fd
, const char *what
, char *bufp
, char *ebuf
)
1409 return (recv_ack(fd
, DL_OK_ACK_SIZE
, what
, bufp
, ebuf
, NULL
));
1414 dlinforeq(int fd
, char *ebuf
)
1418 req
.dl_primitive
= DL_INFO_REQ
;
1420 return (send_request(fd
, (char *)&req
, sizeof(req
), "info", ebuf
));
1424 dlinfoack(int fd
, char *bufp
, char *ebuf
)
1427 return (recv_ack(fd
, DL_INFO_ACK_SIZE
, "info", bufp
, ebuf
, NULL
));
1430 #ifdef HAVE_DLPI_PASSIVE
1432 * Enable DLPI passive mode. We do not care if this request fails, as this
1433 * indicates the underlying DLPI device does not support link aggregation.
1436 dlpassive(int fd
, char *ebuf
)
1438 dl_passive_req_t req
;
1439 bpf_u_int32 buf
[MAXDLBUF
];
1441 req
.dl_primitive
= DL_PASSIVE_REQ
;
1443 if (send_request(fd
, (char *)&req
, sizeof(req
), "dlpassive", ebuf
) == 0)
1444 (void) dlokack(fd
, "dlpassive", (char *)buf
, ebuf
);
1450 * There's an ack *if* there's an error.
1453 dlrawdatareq(int fd
, const u_char
*datap
, int datalen
)
1455 struct strbuf ctl
, data
;
1456 long buf
[MAXDLBUF
]; /* XXX - char? */
1457 union DL_primitives
*dlp
;
1460 dlp
= MAKE_DL_PRIMITIVES(buf
);
1462 dlp
->dl_primitive
= DL_HP_RAWDATA_REQ
;
1463 dlen
= DL_HP_RAWDATA_REQ_SIZE
;
1466 * HP's documentation doesn't appear to show us supplying any
1467 * address pointed to by the control part of the message.
1468 * I think that's what raw mode means - you just send the raw
1469 * packet, you don't specify where to send it to, as that's
1470 * implied by the destination address.
1474 ctl
.buf
= (void *)buf
;
1478 data
.buf
= (void *)datap
;
1480 return (putmsg(fd
, &ctl
, &data
, 0));
1482 #endif /* DL_HP_RAWDLS */
1484 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
1486 get_release(bpf_u_int32
*majorp
, bpf_u_int32
*minorp
, bpf_u_int32
*microp
)
1489 static char buf
[32];
1494 if (sysinfo(SI_RELEASE
, buf
, sizeof(buf
)) < 0)
1497 if (!isdigit((unsigned char)*cp
))
1499 *majorp
= strtol(cp
, &cp
, 10);
1502 *minorp
= strtol(cp
, &cp
, 10);
1505 *microp
= strtol(cp
, &cp
, 10);
1510 #ifdef DL_HP_PPA_REQ
1512 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1517 * Determine ppa number that specifies ifname.
1519 * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
1520 * the code that's used here is the old code for HP-UX 10.x.
1522 * However, HP-UX 10.20, at least, appears to have such a member
1523 * in its "dl_hp_ppa_info_t" structure, so the new code is used.
1524 * The new code didn't work on an old 10.20 system on which Rick
1525 * Jones of HP tried it, but with later patches installed, it
1526 * worked - it appears that the older system had those members but
1527 * didn't put anything in them, so, if the search by name fails, we
1528 * do the old search.
1530 * Rick suggests that making sure your system is "up on the latest
1531 * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
1532 * that problem, as well as allowing libpcap to see packets sent
1533 * from the system on which the libpcap application is being run.
1534 * (On 10.20, in addition to getting the latest patches, you need
1535 * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
1536 * a posting to "comp.sys.hp.hpux" at
1538 * http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
1540 * says that, to see the machine's outgoing traffic, you'd need to
1541 * apply the right patches to your system, and also set that variable
1544 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1546 * which could be put in, for example, "/sbin/init.d/lan".
1548 * Setting the variable is not necessary on HP-UX 11.x.
1551 get_dlpi_ppa(register int fd
, register const char *device
, register int unit
,
1552 register char *ebuf
)
1554 register dl_hp_ppa_ack_t
*ap
;
1555 register dl_hp_ppa_info_t
*ipstart
, *ip
;
1558 register u_long majdev
;
1559 struct stat statbuf
;
1560 dl_hp_ppa_req_t req
;
1563 dl_hp_ppa_ack_t
*dlp
;
1568 memset((char *)&req
, 0, sizeof(req
));
1569 req
.dl_primitive
= DL_HP_PPA_REQ
;
1571 memset((char *)buf
, 0, sizeof(buf
));
1572 if (send_request(fd
, (char *)&req
, sizeof(req
), "hpppa", ebuf
) < 0)
1573 return (PCAP_ERROR
);
1575 ctl
.maxlen
= DL_HP_PPA_ACK_SIZE
;
1577 ctl
.buf
= (char *)buf
;
1581 * DLPI may return a big chunk of data for a DL_HP_PPA_REQ. The normal
1582 * recv_ack will fail because it set the maxlen to MAXDLBUF (8192)
1583 * which is NOT big enough for a DL_HP_PPA_REQ.
1585 * This causes libpcap applications to fail on a system with HP-APA
1588 * To figure out how big the returned data is, we first call getmsg
1589 * to get the small head and peek at the head to get the actual data
1590 * length, and then issue another getmsg to get the actual PPA data.
1592 /* get the head first */
1593 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1594 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1595 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1596 return (PCAP_ERROR
);
1599 dlp
= (dl_hp_ppa_ack_t
*)ctl
.buf
;
1600 if (dlp
->dl_primitive
!= DL_HP_PPA_ACK
) {
1601 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1602 "get_dlpi_ppa: hpppa unexpected primitive ack 0x%x",
1603 (bpf_u_int32
)dlp
->dl_primitive
);
1604 return (PCAP_ERROR
);
1607 if (ctl
.len
< DL_HP_PPA_ACK_SIZE
) {
1608 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1609 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1610 ctl
.len
, (unsigned long)DL_HP_PPA_ACK_SIZE
);
1611 return (PCAP_ERROR
);
1614 /* allocate buffer */
1615 if ((ppa_data_buf
= (char *)malloc(dlp
->dl_length
)) == NULL
) {
1616 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1617 "get_dlpi_ppa: hpppa malloc: %s", pcap_strerror(errno
));
1618 return (PCAP_ERROR
);
1620 ctl
.maxlen
= dlp
->dl_length
;
1622 ctl
.buf
= (char *)ppa_data_buf
;
1624 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1625 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1626 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1628 return (PCAP_ERROR
);
1630 if (ctl
.len
< dlp
->dl_length
) {
1631 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1632 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1633 ctl
.len
, (unsigned long)dlp
->dl_length
);
1635 return (PCAP_ERROR
);
1638 ap
= (dl_hp_ppa_ack_t
*)buf
;
1639 ipstart
= (dl_hp_ppa_info_t
*)ppa_data_buf
;
1642 #ifdef HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1
1644 * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
1645 * member that should, in theory, contain the part of the
1646 * name for the device that comes before the unit number,
1647 * and should also have a "dl_module_id_2" member that may
1648 * contain an alternate name (e.g., I think Ethernet devices
1649 * have both "lan", for "lanN", and "snap", for "snapN", with
1650 * the former being for Ethernet packets and the latter being
1651 * for 802.3/802.2 packets).
1653 * Search for the device that has the specified name and
1656 for (i
= 0; i
< ap
->dl_count
; i
++) {
1657 if ((strcmp((const char *)ip
->dl_module_id_1
, device
) == 0 ||
1658 strcmp((const char *)ip
->dl_module_id_2
, device
) == 0) &&
1659 ip
->dl_instance_num
== unit
)
1662 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1666 * We don't have that member, so the search is impossible; make it
1667 * look as if the search failed.
1672 if (i
== ap
->dl_count
) {
1674 * Well, we didn't, or can't, find the device by name.
1676 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1677 * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
1678 * doesn't seem to fill them in unless the system is
1679 * at a reasonably up-to-date patch level.
1681 * Older HP-UX 10.x systems might not have those fields
1684 * Therefore, we'll search for the entry with the major
1685 * device number of a device with the name "/dev/<dev><unit>",
1686 * if such a device exists, as the old code did.
1688 pcap_snprintf(dname
, sizeof(dname
), "/dev/%s%d", device
, unit
);
1689 if (stat(dname
, &statbuf
) < 0) {
1690 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "stat: %s: %s",
1691 dname
, pcap_strerror(errno
));
1692 return (PCAP_ERROR
);
1694 majdev
= major(statbuf
.st_rdev
);
1698 for (i
= 0; i
< ap
->dl_count
; i
++) {
1699 if (ip
->dl_mjr_num
== majdev
&&
1700 ip
->dl_instance_num
== unit
)
1703 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1706 if (i
== ap
->dl_count
) {
1707 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1708 "can't find /dev/dlpi PPA for %s%d", device
, unit
);
1709 return (PCAP_ERROR_NO_SUCH_DEVICE
);
1711 if (ip
->dl_hdw_state
== HDW_DEAD
) {
1712 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1713 "%s%d: hardware state: DOWN\n", device
, unit
);
1715 return (PCAP_ERROR
);
1725 * Under HP-UX 9, there is no good way to determine the ppa.
1726 * So punt and read it from /dev/kmem.
1728 static struct nlist nl
[] = {
1734 static char path_vmunix
[] = "/hp-ux";
1736 /* Determine ppa number that specifies ifname */
1738 get_dlpi_ppa(register int fd
, register const char *ifname
, register int unit
,
1739 register char *ebuf
)
1741 register const char *cp
;
1745 char if_name
[sizeof(ifnet
.if_name
) + 1];
1747 cp
= strrchr(ifname
, '/');
1750 if (nlist(path_vmunix
, &nl
) < 0) {
1751 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "nlist %s failed",
1755 if (nl
[NL_IFNET
].n_value
== 0) {
1756 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1757 "could't find %s kernel symbol",
1758 nl
[NL_IFNET
].n_name
);
1761 kd
= open("/dev/kmem", O_RDONLY
);
1763 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "kmem open: %s",
1764 pcap_strerror(errno
));
1767 if (dlpi_kread(kd
, nl
[NL_IFNET
].n_value
,
1768 &addr
, sizeof(addr
), ebuf
) < 0) {
1772 for (; addr
!= NULL
; addr
= ifnet
.if_next
) {
1773 if (dlpi_kread(kd
, (off_t
)addr
,
1774 &ifnet
, sizeof(ifnet
), ebuf
) < 0 ||
1775 dlpi_kread(kd
, (off_t
)ifnet
.if_name
,
1776 if_name
, sizeof(ifnet
.if_name
), ebuf
) < 0) {
1780 if_name
[sizeof(ifnet
.if_name
)] = '\0';
1781 if (strcmp(if_name
, ifname
) == 0 && ifnet
.if_unit
== unit
)
1782 return (ifnet
.if_index
);
1785 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "Can't find %s", ifname
);
1790 dlpi_kread(register int fd
, register off_t addr
,
1791 register void *buf
, register u_int len
, register char *ebuf
)
1795 if (lseek(fd
, addr
, SEEK_SET
) < 0) {
1796 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "lseek: %s",
1797 pcap_strerror(errno
));
1800 cc
= read(fd
, buf
, len
);
1802 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "read: %s",
1803 pcap_strerror(errno
));
1805 } else if (cc
!= len
) {
1806 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "short read (%d != %d)", cc
,
1815 pcap_create_interface(const char *device _U_
, char *ebuf
)
1819 struct pcap_dlpi
*pd
;
1822 p
= pcap_create_common(ebuf
, sizeof (struct pcap_dlpi
));
1828 pd
->send_fd
= -1; /* it hasn't been opened yet */
1831 p
->activate_op
= pcap_activate_dlpi
;