]>
The Tcpdump Group git mirrors - libpcap/blob - pcap-dlpi.c
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 * and Mark C. Brown (mbrown@hp.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
72 static const char rcsid
[] _U_
=
73 "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.108.2.7 2006-04-04 05:33:02 guy Exp $ (LBL)";
80 #include <sys/types.h>
82 #ifdef HAVE_SYS_BUFMOD_H
83 #include <sys/bufmod.h>
86 #ifdef HAVE_SYS_DLPI_EXT_H
87 #include <sys/dlpi_ext.h>
90 #include <sys/socket.h>
95 #include <sys/stream.h>
96 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
97 #include <sys/systeminfo.h>
120 #define INT_MAX 2147483647
123 #include "pcap-int.h"
125 #ifdef HAVE_OS_PROTO_H
126 #include "os-proto.h"
129 #ifndef PCAP_DEV_PREFIX
131 #define PCAP_DEV_PREFIX "/dev/dlpi"
133 #define PCAP_DEV_PREFIX "/dev"
137 #define MAXDLBUF 8192
139 #ifdef HAVE_SYS_BUFMOD_H
142 * Size of a bufmod chunk to pass upstream; that appears to be the biggest
143 * value to which you can set it, and setting it to that value (which
144 * is bigger than what appears to be the Solaris default of 8192)
145 * reduces the number of packet drops.
147 #define CHUNKSIZE 65536
150 * Size of the buffer to allocate for packet data we read; it must be
151 * large enough to hold a chunk.
153 #define PKTBUFSIZE CHUNKSIZE
155 #else /* HAVE_SYS_BUFMOD_H */
158 * Size of the buffer to allocate for packet data we read; this is
159 * what the value used to be - there's no particular reason why it
160 * should be tied to MAXDLBUF, but we'll leave it as this for now.
162 #define PKTBUFSIZE (MAXDLBUF * sizeof(bpf_u_int32))
167 static char *split_dname(char *, int *, char *);
168 static int dl_doattach(int, int, char *);
170 static int dl_dohpuxbind(int, char *);
172 static int dlattachreq(int, bpf_u_int32
, char *);
173 static int dlbindreq(int, bpf_u_int32
, char *);
174 static int dlbindack(int, char *, char *, int *);
175 static int dlpromisconreq(int, bpf_u_int32
, char *);
176 static int dlokack(int, const char *, char *, char *);
177 static int dlinforeq(int, char *);
178 static int dlinfoack(int, char *, char *);
180 static int dlrawdatareq(int, const u_char
*, int);
182 static int recv_ack(int, int, const char *, char *, char *, int *);
183 static char *dlstrerror(bpf_u_int32
);
184 static char *dlprim(bpf_u_int32
);
185 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
186 static char *get_release(bpf_u_int32
*, bpf_u_int32
*, bpf_u_int32
*);
188 static int send_request(int, char *, int, char *, char *);
189 #ifdef HAVE_SYS_BUFMOD_H
190 static int strioctl(int, int, int, char *);
193 static int dlpi_kread(int, off_t
, void *, u_int
, char *);
196 static int get_dlpi_ppa(int, const char *, int, char *);
200 pcap_stats_dlpi(pcap_t
*p
, struct pcap_stat
*ps
)
204 * "ps_recv" counts packets handed to the filter, not packets
205 * that passed the filter. As filtering is done in userland,
206 * this would not include packets dropped because we ran out
207 * of buffer space; in order to make this more like other
208 * platforms (Linux 2.4 and later, BSDs with BPF), where the
209 * "packets received" count includes packets received but dropped
210 * due to running out of buffer space, and to keep from confusing
211 * applications that, for example, compute packet drop percentages,
212 * we also make it count packets dropped by "bufmod" (otherwise we
213 * might run the risk of the packet drop count being bigger than
214 * the received-packet count).
216 * "ps_drop" counts packets dropped by "bufmod" because of
217 * flow control requirements or resource exhaustion; it doesn't
218 * count packets dropped by the interface driver, or packets
219 * dropped upstream. As filtering is done in userland, it counts
220 * packets regardless of whether they would've passed the filter.
222 * These statistics don't include packets not yet read from
223 * the kernel by libpcap, but they may include packets not
224 * yet read from libpcap by the application.
229 * Add in the drop count, as per the above comment.
231 ps
->ps_recv
+= ps
->ps_drop
;
235 /* XXX Needed by HP-UX (at least) */
236 static bpf_u_int32 ctlbuf
[MAXDLBUF
];
237 static struct strbuf ctl
= {
244 pcap_read_dlpi(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
246 register int cc
, n
, caplen
, origlen
;
247 register u_char
*bp
, *ep
, *pk
;
248 register struct bpf_insn
*fcode
;
249 #ifdef HAVE_SYS_BUFMOD_H
250 register struct sb_hdr
*sbp
;
257 struct pcap_pkthdr pkthdr
;
262 data
.buf
= (char *)p
->buffer
+ p
->offset
;
263 data
.maxlen
= p
->bufsize
;
267 * Has "pcap_breakloop()" been called?
271 * Yes - clear the flag that indicates
272 * that it has, and return -2 to
273 * indicate that we were told to
274 * break out of the loop.
280 * XXX - check for the DLPI primitive, which
281 * would be DL_HP_RAWDATA_IND on HP-UX
282 * if we're in raw mode?
284 if (getmsg(p
->fd
, &ctl
, &data
, &flags
) < 0) {
285 /* Don't choke when we get ptraced */
295 strlcpy(p
->errbuf
, pcap_strerror(errno
),
301 bp
= p
->buffer
+ p
->offset
;
305 /* Loop through packets */
306 fcode
= p
->fcode
.bf_insns
;
309 #ifdef HAVE_SYS_BUFMOD_H
312 * Has "pcap_breakloop()" been called?
313 * If so, return immediately - if we haven't read any
314 * packets, clear the flag and return -2 to indicate
315 * that we were told to break out of the loop, otherwise
316 * leave the flag set, so that the *next* call will break
317 * out of the loop without having read any packets, and
318 * return the number of packets we've processed so far.
333 memcpy(sbp
, bp
, sizeof(*sbp
));
336 sbp
= (struct sb_hdr
*)bp
;
337 p
->md
.stat
.ps_drop
= sbp
->sbh_drops
;
338 pk
= bp
+ sizeof(*sbp
);
339 bp
+= sbp
->sbh_totlen
;
340 origlen
= sbp
->sbh_origlen
;
341 caplen
= sbp
->sbh_msglen
;
344 caplen
= min(p
->snapshot
, cc
);
348 ++p
->md
.stat
.ps_recv
;
349 if (bpf_filter(fcode
, pk
, origlen
, caplen
)) {
350 #ifdef HAVE_SYS_BUFMOD_H
351 pkthdr
.ts
.tv_sec
= sbp
->sbh_timestamp
.tv_sec
;
352 pkthdr
.ts
.tv_usec
= sbp
->sbh_timestamp
.tv_usec
;
354 (void)gettimeofday(&pkthdr
.ts
, NULL
);
356 pkthdr
.len
= origlen
;
357 pkthdr
.caplen
= caplen
;
358 /* Insure caplen does not exceed snapshot */
359 if (pkthdr
.caplen
> p
->snapshot
)
360 pkthdr
.caplen
= p
->snapshot
;
361 (*callback
)(user
, &pkthdr
, pk
);
362 if (++n
>= cnt
&& cnt
>= 0) {
368 #ifdef HAVE_SYS_BUFMOD_H
376 pcap_inject_dlpi(pcap_t
*p
, const void *buf
, size_t size
)
380 #if defined(DLIOCRAW)
381 ret
= write(p
->fd
, buf
, size
);
383 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
384 pcap_strerror(errno
));
387 #elif defined(DL_HP_RAWDLS)
388 if (p
->send_fd
< 0) {
389 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
390 "send: Output FD couldn't be opened");
393 ret
= dlrawdatareq(p
->send_fd
, buf
, size
);
395 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
396 pcap_strerror(errno
));
400 * putmsg() returns either 0 or -1; it doesn't indicate how
401 * many bytes were written (presumably they were all written
402 * or none of them were written). OpenBSD's pcap_inject()
403 * returns the number of bytes written, so, for API compatibility,
404 * we return the number of bytes we were told to write.
407 #else /* no raw mode */
409 * XXX - this is a pain, because you might have to extract
410 * the address from the packet and use it in a DL_UNITDATA_REQ
411 * request. That would be dependent on the link-layer type.
413 * I also don't know what SAP you'd have to bind the descriptor
414 * to, or whether you'd need separate "receive" and "send" FDs,
415 * nor do I know whether you'd need different bindings for
416 * D/I/X Ethernet and 802.3, or for {FDDI,Token Ring} plus
417 * 802.2 and {FDDI,Token Ring} plus 802.2 plus SNAP.
419 * So, for now, we just return a "you can't send" indication,
420 * and leave it up to somebody with a DLPI-based system lacking
421 * both DLIOCRAW and DL_HP_RAWDLS to supply code to implement
422 * packet transmission on that system. If they do, they should
423 * send it to us - but should not send us code that assumes
424 * Ethernet; if the code doesn't work on non-Ethernet interfaces,
425 * it should check "p->linktype" and reject the send request if
426 * it's anything other than DLT_EN10MB.
428 strlcpy(p
->errbuf
, "send: Not supported on this version of this OS",
431 #endif /* raw mode */
436 #define DL_IPATM 0x12 /* ATM Classical IP interface */
444 #define A_GET_UNITS (('A'<<8)|118)
445 #endif /* A_GET_UNITS */
446 #ifndef A_PROMISCON_REQ
447 #define A_PROMISCON_REQ (('A'<<8)|121)
448 #endif /* A_PROMISCON_REQ */
449 #endif /* HAVE_SOLARIS */
452 pcap_close_dlpi(pcap_t
*p
)
454 pcap_close_common(p
);
460 pcap_open_live(const char *device
, int snaplen
, int promisc
, int to_ms
,
469 register dl_info_ack_t
*infop
;
470 #ifdef HAVE_SYS_BUFMOD_H
471 bpf_u_int32 ss
, chunksize
;
473 register char *release
;
474 bpf_u_int32 osmajor
, osminor
, osmicro
;
477 bpf_u_int32 buf
[MAXDLBUF
];
479 #ifndef HAVE_DEV_DLPI
483 p
= (pcap_t
*)malloc(sizeof(*p
));
485 strlcpy(ebuf
, pcap_strerror(errno
), PCAP_ERRBUF_SIZE
);
488 memset(p
, 0, sizeof(*p
));
489 p
->fd
= -1; /* indicate that it hasn't been opened yet */
494 ** Remove any "/dev/" on the front of the device.
496 cp
= strrchr(device
, '/');
498 strlcpy(dname
, device
, sizeof(dname
));
500 strlcpy(dname
, cp
+ 1, sizeof(dname
));
503 * Split the device name into a device type name and a unit number;
504 * chop off the unit number, so "dname" is just a device type name.
506 cp
= split_dname(dname
, &ppa
, ebuf
);
512 * Use "/dev/dlpi" as the device.
514 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
515 * the "dl_mjr_num" field is for the "major number of interface
516 * driver"; that's the major of "/dev/dlpi" on the system on
517 * which I tried this, but there may be DLPI devices that
518 * use a different driver, in which case we may need to
519 * search "/dev" for the appropriate device with that major
520 * device number, rather than hardwiring "/dev/dlpi".
523 if ((p
->fd
= open(cp
, O_RDWR
)) < 0) {
524 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
525 "%s: %s", cp
, pcap_strerror(errno
));
531 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
532 * receiving packets on the same descriptor - you need separate
533 * descriptors for sending and receiving, bound to different SAPs.
535 * If the open fails, we just leave -1 in "p->send_fd" and reject
536 * attempts to send packets, just as if, in pcap-bpf.c, we fail
537 * to open the BPF device for reading and writing, we just try
538 * to open it for reading only and, if that succeeds, just let
539 * the send attempts fail.
541 p
->send_fd
= open(cp
, O_RDWR
);
545 * Get a table of all PPAs for that device, and search that
546 * table for the specified device type name and unit number.
548 ppa
= get_dlpi_ppa(p
->fd
, dname
, ppa
, ebuf
);
553 * If the device name begins with "/", assume it begins with
554 * the pathname of the directory containing the device to open;
555 * otherwise, concatenate the device directory name and the
559 strlcpy(dname
, device
, sizeof(dname
));
561 snprintf(dname
, sizeof(dname
), "%s/%s", PCAP_DEV_PREFIX
,
565 * Get the unit number, and a pointer to the end of the device
568 cp
= split_dname(dname
, &ppa
, ebuf
);
573 * Make a copy of the device pathname, and then remove the unit
574 * number from the device pathname.
576 strlcpy(dname2
, dname
, sizeof(dname
));
579 /* Try device without unit number */
580 if ((p
->fd
= open(dname
, O_RDWR
)) < 0) {
581 if (errno
!= ENOENT
) {
582 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s: %s", dname
,
583 pcap_strerror(errno
));
587 /* Try again with unit number */
588 if ((p
->fd
= open(dname2
, O_RDWR
)) < 0) {
589 if (errno
== ENOENT
) {
591 * We just report "No DLPI device found"
592 * with the device name, so people don't
593 * get confused and think, for example,
594 * that if they can't capture on "lo0"
595 * on Solaris the fix is to change libpcap
596 * (or the application that uses it) to
597 * look for something other than "/dev/lo0",
598 * as the fix is to look for an operating
599 * system other than Solaris - you just
600 * *can't* capture on a loopback interface
601 * on Solaris, the lack of a DLPI device
602 * for the loopback interface is just a
603 * symptom of that inability.
605 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
606 "%s: No DLPI device found", device
);
608 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s: %s",
609 dname2
, pcap_strerror(errno
));
613 /* XXX Assume unit zero */
618 p
->snapshot
= snaplen
;
621 ** Attach if "style 2" provider
623 if (dlinforeq(p
->fd
, ebuf
) < 0 ||
624 dlinfoack(p
->fd
, (char *)buf
, ebuf
) < 0)
626 infop
= &((union DL_primitives
*)buf
)->info_ack
;
628 if (infop
->dl_mac_type
== DL_IPATM
)
631 if (infop
->dl_provider_style
== DL_STYLE2
) {
632 if (dl_doattach(p
->fd
, ppa
, ebuf
) < 0)
635 if (p
->send_fd
>= 0) {
636 if (dl_doattach(p
->send_fd
, ppa
, ebuf
) < 0)
643 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
644 ** skip if using SINIX)
646 #if !defined(HAVE_HPUX9) && !defined(HAVE_HPUX10_20_OR_LATER) && !defined(sinix)
650 ** According to IBM's AIX Support Line, the dl_sap value
651 ** should not be less than 0x600 (1536) for standard Ethernet.
652 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
653 ** format or invalid" - errors if we use 1537 on the "tr0"
654 ** device, which, given that its name starts with "tr" and that
655 ** it's IBM, probably means a Token Ring device. (Perhaps we
656 ** need to use 1537 on "/dev/dlpi/en" because that device is for
657 ** D/I/X Ethernet, the "SAP" is actually an Ethernet type, and
658 ** it rejects invalid Ethernet types.)
660 ** So if 1537 fails, we try 2, as Hyung Sik Yoon of IBM Korea
661 ** says that works on Token Ring (he says that 0 does *not*
662 ** work; perhaps that's considered an invalid LLC SAP value - I
663 ** assume the SAP value in a DLPI bind is an LLC SAP for network
664 ** types that use 802.2 LLC).
666 if ((dlbindreq(p
->fd
, 1537, ebuf
) < 0 &&
667 dlbindreq(p
->fd
, 2, ebuf
) < 0) ||
668 dlbindack(p
->fd
, (char *)buf
, ebuf
, NULL
) < 0)
670 #elif defined(DL_HP_RAWDLS)
672 ** HP-UX 10.0x and 10.1x.
674 if (dl_dohpuxbind(p
->fd
, ebuf
) < 0)
676 if (p
->send_fd
>= 0) {
678 ** XXX - if this fails, just close send_fd and
679 ** set it to -1, so that you can't send but can
682 if (dl_dohpuxbind(p
->send_fd
, ebuf
) < 0)
685 #else /* neither AIX nor HP-UX */
687 ** Not Sinix, and neither AIX nor HP-UX - Solaris, and any other
690 if (dlbindreq(p
->fd
, 0, ebuf
) < 0 ||
691 dlbindack(p
->fd
, (char *)buf
, ebuf
, NULL
) < 0)
693 #endif /* AIX vs. HP-UX vs. other */
694 #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
699 ** Have to turn on some special ATM promiscuous mode
701 ** Do *NOT* turn regular promiscuous mode on; it doesn't
702 ** help, and may break things.
704 if (strioctl(p
->fd
, A_PROMISCON_REQ
, 0, NULL
) < 0) {
705 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "A_PROMISCON_REQ: %s",
706 pcap_strerror(errno
));
713 ** Enable promiscuous (not necessary on send FD)
715 if (dlpromisconreq(p
->fd
, DL_PROMISC_PHYS
, ebuf
) < 0 ||
716 dlokack(p
->fd
, "promisc_phys", (char *)buf
, ebuf
) < 0)
720 ** Try to enable multicast (you would have thought
721 ** promiscuous would be sufficient). (Skip if using
722 ** HP-UX or SINIX) (Not necessary on send FD)
724 #if !defined(__hpux) && !defined(sinix)
725 if (dlpromisconreq(p
->fd
, DL_PROMISC_MULTI
, ebuf
) < 0 ||
726 dlokack(p
->fd
, "promisc_multi", (char *)buf
, ebuf
) < 0)
728 "WARNING: DL_PROMISC_MULTI failed (%s)\n", ebuf
);
732 ** Try to enable SAP promiscuity (when not in promiscuous mode
733 ** when using HP-UX, when not doing SunATM on Solaris, and never
734 ** under SINIX) (Not necessary on send FD)
744 (dlpromisconreq(p
->fd
, DL_PROMISC_SAP
, ebuf
) < 0 ||
745 dlokack(p
->fd
, "promisc_sap", (char *)buf
, ebuf
) < 0)) {
746 /* Not fatal if promisc since the DL_PROMISC_PHYS worked */
749 "WARNING: DL_PROMISC_SAP failed (%s)\n", ebuf
);
756 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
757 ** promiscuous options.
759 #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
760 if (dl_dohpuxbind(p
->fd
, ebuf
) < 0)
763 ** We don't set promiscuous mode on the send FD, but we'll defer
764 ** binding it anyway, just to keep the HP-UX 9/10.20 or later
767 if (p
->send_fd
>= 0) {
769 ** XXX - if this fails, just close send_fd and
770 ** set it to -1, so that you can't send but can
773 if (dl_dohpuxbind(p
->send_fd
, ebuf
) < 0)
779 ** Determine link type
780 ** XXX - get SAP length and address length as well, for use
781 ** when sending packets.
783 if (dlinforeq(p
->fd
, ebuf
) < 0 ||
784 dlinfoack(p
->fd
, (char *)buf
, ebuf
) < 0)
787 infop
= &((union DL_primitives
*)buf
)->info_ack
;
788 switch (infop
->dl_mac_type
) {
792 p
->linktype
= DLT_EN10MB
;
795 * This is (presumably) a real Ethernet capture; give it a
796 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
797 * that an application can let you choose it, in case you're
798 * capturing DOCSIS traffic that a Cisco Cable Modem
799 * Termination System is putting out onto an Ethernet (it
800 * doesn't put an Ethernet header onto the wire, it puts raw
801 * DOCSIS frames out on the wire inside the low-level
804 p
->dlt_list
= (u_int
*) malloc(sizeof(u_int
) * 2);
806 * If that fails, just leave the list empty.
808 if (p
->dlt_list
!= NULL
) {
809 p
->dlt_list
[0] = DLT_EN10MB
;
810 p
->dlt_list
[1] = DLT_DOCSIS
;
816 p
->linktype
= DLT_FDDI
;
822 * XXX - what about DL_TPB? Is that Token Bus?
824 p
->linktype
= DLT_IEEE802
;
830 p
->linktype
= DLT_SUNATM
;
831 p
->offset
= 0; /* works for LANE and LLC encapsulation */
836 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "unknown mac type %lu",
837 (unsigned long)infop
->dl_mac_type
);
843 ** This is a non standard SunOS hack to get the full raw link-layer
846 if (strioctl(p
->fd
, DLIOCRAW
, 0, NULL
) < 0) {
847 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "DLIOCRAW: %s",
848 pcap_strerror(errno
));
853 #ifdef HAVE_SYS_BUFMOD_H
855 ** Another non standard call to get the data nicely buffered
857 if (ioctl(p
->fd
, I_PUSH
, "bufmod") != 0) {
858 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "I_PUSH bufmod: %s",
859 pcap_strerror(errno
));
864 ** Now that the bufmod is pushed lets configure it.
866 ** There is a bug in bufmod(7). When dealing with messages of
867 ** less than snaplen size it strips data from the beginning not
870 ** This bug is supposed to be fixed in 5.3.2. Also, there is a
871 ** patch available. Ask for bugid 1149065.
875 release
= get_release(&osmajor
, &osminor
, &osmicro
);
876 if (osmajor
== 5 && (osminor
<= 2 || (osminor
== 3 && osmicro
< 2)) &&
877 getenv("BUFMOD_FIXED") == NULL
) {
879 "WARNING: bufmod is broken in SunOS %s; ignoring snaplen.\n",
885 strioctl(p
->fd
, SBIOCSSNAP
, sizeof(ss
), (char *)&ss
) != 0) {
886 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSSNAP: %s",
887 pcap_strerror(errno
));
892 ** Set up the bufmod timeout
897 to
.tv_sec
= to_ms
/ 1000;
898 to
.tv_usec
= (to_ms
* 1000) % 1000000;
899 if (strioctl(p
->fd
, SBIOCSTIME
, sizeof(to
), (char *)&to
) != 0) {
900 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSTIME: %s",
901 pcap_strerror(errno
));
907 ** Set the chunk length.
909 chunksize
= CHUNKSIZE
;
910 if (strioctl(p
->fd
, SBIOCSCHUNK
, sizeof(chunksize
), (char *)&chunksize
)
912 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSCHUNKP: %s",
913 pcap_strerror(errno
));
919 ** As the last operation flush the read side.
921 if (ioctl(p
->fd
, I_FLUSH
, FLUSHR
) != 0) {
922 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "FLUSHR: %s",
923 pcap_strerror(errno
));
927 /* Allocate data buffer */
928 p
->bufsize
= PKTBUFSIZE
;
929 p
->buffer
= (u_char
*)malloc(p
->bufsize
+ p
->offset
);
930 if (p
->buffer
== NULL
) {
931 strlcpy(ebuf
, pcap_strerror(errno
), PCAP_ERRBUF_SIZE
);
936 * "p->fd" is an FD for a STREAMS device, so "select()" and
937 * "poll()" should work on it.
939 p
->selectable_fd
= p
->fd
;
941 p
->read_op
= pcap_read_dlpi
;
942 p
->inject_op
= pcap_inject_dlpi
;
943 p
->setfilter_op
= install_bpf_program
; /* no kernel filtering */
944 p
->setdirection_op
= NULL
; /* Not implemented.*/
945 p
->set_datalink_op
= NULL
; /* can't change data link type */
946 p
->getnonblock_op
= pcap_getnonblock_fd
;
947 p
->setnonblock_op
= pcap_setnonblock_fd
;
948 p
->stats_op
= pcap_stats_dlpi
;
949 p
->close_op
= pcap_close_dlpi
;
958 * Get rid of any link-layer type list we allocated.
960 if (p
->dlt_list
!= NULL
)
967 * Split a device name into a device type name and a unit number;
968 * return the a pointer to the beginning of the unit number, which
969 * is the end of the device type name, and set "*unitp" to the unit
972 * Returns NULL on error, and fills "ebuf" with an error message.
975 split_dname(char *device
, int *unitp
, char *ebuf
)
982 * Look for a number at the end of the device name string.
984 cp
= device
+ strlen(device
) - 1;
985 if (*cp
< '0' || *cp
> '9') {
986 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s missing unit number",
991 /* Digits at end of string are unit number */
992 while (cp
-1 >= device
&& *(cp
-1) >= '0' && *(cp
-1) <= '9')
996 unit
= strtol(cp
, &eos
, 10);
998 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s bad unit number", device
);
1001 if (errno
== ERANGE
|| unit
> INT_MAX
) {
1002 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number too large",
1007 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number is negative",
1016 dl_doattach(int fd
, int ppa
, char *ebuf
)
1018 bpf_u_int32 buf
[MAXDLBUF
];
1020 if (dlattachreq(fd
, ppa
, ebuf
) < 0 ||
1021 dlokack(fd
, "attach", (char *)buf
, ebuf
) < 0)
1028 dl_dohpuxbind(int fd
, char *ebuf
)
1032 bpf_u_int32 buf
[MAXDLBUF
];
1035 * XXX - we start at 22 because we used to use only 22, but
1036 * that was just because that was the value used in some
1037 * sample code from HP. With what value *should* we start?
1038 * Does it matter, given that we're enabling SAP promiscuity
1043 if (dlbindreq(fd
, hpsap
, ebuf
) < 0)
1045 if (dlbindack(fd
, (char *)buf
, ebuf
, &uerror
) >= 0)
1048 * For any error other than a UNIX EBUSY, give up.
1050 if (uerror
!= EBUSY
) {
1052 * dlbindack() has already filled in ebuf for
1059 * For EBUSY, try the next SAP value; that means that
1060 * somebody else is using that SAP. Clear ebuf so
1061 * that application doesn't report the "Device busy"
1062 * error as a warning.
1068 "All SAPs from 22 through 100 are in use",
1078 pcap_platform_finddevs(pcap_if_t
**alldevsp
, char *errbuf
)
1084 char pad
[516]; /* XXX - must be at least 513; is 516
1091 * We may have to do special magic to get ATM devices.
1093 if ((fd
= open("/dev/ba", O_RDWR
)) < 0) {
1095 * We couldn't open the "ba" device.
1096 * For now, just give up; perhaps we should
1097 * return an error if the problem is neither
1098 * a "that device doesn't exist" error (ENOENT,
1099 * ENXIO, etc.) or a "you're not allowed to do
1100 * that" error (EPERM, EACCES).
1105 if (strioctl(fd
, A_GET_UNITS
, sizeof(buf
), (char *)&buf
) < 0) {
1106 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "A_GET_UNITS: %s",
1107 pcap_strerror(errno
));
1110 for (i
= 0; i
< buf
.nunits
; i
++) {
1111 snprintf(baname
, sizeof baname
, "ba%u", i
);
1112 if (pcap_add_if(alldevsp
, baname
, 0, NULL
, errbuf
) < 0)
1121 send_request(int fd
, char *ptr
, int len
, char *what
, char *ebuf
)
1131 if (putmsg(fd
, &ctl
, (struct strbuf
*) NULL
, flags
) < 0) {
1132 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1133 "send_request: putmsg \"%s\": %s",
1134 what
, pcap_strerror(errno
));
1141 recv_ack(int fd
, int size
, const char *what
, char *bufp
, char *ebuf
, int *uerror
)
1143 union DL_primitives
*dlp
;
1148 * Clear out "*uerror", so it's only set for DL_ERROR_ACK/DL_SYSERR,
1149 * making that the only place where EBUSY is treated specially.
1154 ctl
.maxlen
= MAXDLBUF
;
1159 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1160 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s getmsg: %s",
1161 what
, pcap_strerror(errno
));
1165 dlp
= (union DL_primitives
*) ctl
.buf
;
1166 switch (dlp
->dl_primitive
) {
1171 #ifdef DL_HP_PPA_ACK
1178 switch (dlp
->error_ack
.dl_errno
) {
1182 *uerror
= dlp
->error_ack
.dl_unix_errno
;
1183 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1184 "recv_ack: %s: UNIX error - %s",
1185 what
, pcap_strerror(dlp
->error_ack
.dl_unix_errno
));
1189 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s: %s",
1190 what
, dlstrerror(dlp
->error_ack
.dl_errno
));
1196 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1197 "recv_ack: %s: Unexpected primitive ack %s",
1198 what
, dlprim(dlp
->dl_primitive
));
1202 if (ctl
.len
< size
) {
1203 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1204 "recv_ack: %s: Ack too small (%d < %d)",
1205 what
, ctl
.len
, size
);
1212 dlstrerror(bpf_u_int32 dl_errno
)
1214 static char errstring
[6+2+8+1];
1219 return ("Improper permissions for request");
1222 return ("DLSAP addr in improper format or invalid");
1225 return ("Seq number not from outstand DL_CONN_IND");
1228 return ("User data exceeded provider limit");
1231 #ifdef HAVE_DEV_DLPI
1233 * With a single "/dev/dlpi" device used for all
1234 * DLPI providers, PPAs have nothing to do with
1237 return ("Specified PPA was invalid");
1240 * We have separate devices for separate devices;
1241 * the PPA is just the unit number.
1243 return ("Specified PPA (device unit) was invalid");
1247 return ("Primitive received not known by provider");
1249 case DL_BADQOSPARAM
:
1250 return ("QOS parameters contained invalid values");
1253 return ("QOS structure type is unknown/unsupported");
1256 return ("Bad LSAP selector");
1259 return ("Token used not an active stream");
1262 return ("Attempted second bind with dl_max_conind");
1265 return ("Physical link initialization failed");
1268 return ("Provider couldn't allocate alternate address");
1271 return ("Physical link not initialized");
1274 return ("Primitive issued in improper state");
1277 return ("UNIX system error occurred");
1279 case DL_UNSUPPORTED
:
1280 return ("Requested service not supplied by provider");
1282 case DL_UNDELIVERABLE
:
1283 return ("Previous data unit could not be delivered");
1285 case DL_NOTSUPPORTED
:
1286 return ("Primitive is known but not supported");
1289 return ("Limit exceeded");
1292 return ("Promiscuous mode not enabled");
1295 return ("Other streams for PPA in post-attached");
1298 return ("Automatic handling XID&TEST not supported");
1301 return ("Automatic handling of XID not supported");
1304 return ("Automatic handling of TEST not supported");
1307 return ("Automatic handling of XID response");
1310 return ("Automatic handling of TEST response");
1313 return ("Pending outstanding connect indications");
1316 sprintf(errstring
, "Error %02x", dl_errno
);
1322 dlprim(bpf_u_int32 prim
)
1324 static char primbuf
[80];
1329 return ("DL_INFO_REQ");
1332 return ("DL_INFO_ACK");
1335 return ("DL_ATTACH_REQ");
1338 return ("DL_DETACH_REQ");
1341 return ("DL_BIND_REQ");
1344 return ("DL_BIND_ACK");
1347 return ("DL_UNBIND_REQ");
1350 return ("DL_OK_ACK");
1353 return ("DL_ERROR_ACK");
1355 case DL_SUBS_BIND_REQ
:
1356 return ("DL_SUBS_BIND_REQ");
1358 case DL_SUBS_BIND_ACK
:
1359 return ("DL_SUBS_BIND_ACK");
1361 case DL_UNITDATA_REQ
:
1362 return ("DL_UNITDATA_REQ");
1364 case DL_UNITDATA_IND
:
1365 return ("DL_UNITDATA_IND");
1367 case DL_UDERROR_IND
:
1368 return ("DL_UDERROR_IND");
1371 return ("DL_UDQOS_REQ");
1373 case DL_CONNECT_REQ
:
1374 return ("DL_CONNECT_REQ");
1376 case DL_CONNECT_IND
:
1377 return ("DL_CONNECT_IND");
1379 case DL_CONNECT_RES
:
1380 return ("DL_CONNECT_RES");
1382 case DL_CONNECT_CON
:
1383 return ("DL_CONNECT_CON");
1386 return ("DL_TOKEN_REQ");
1389 return ("DL_TOKEN_ACK");
1391 case DL_DISCONNECT_REQ
:
1392 return ("DL_DISCONNECT_REQ");
1394 case DL_DISCONNECT_IND
:
1395 return ("DL_DISCONNECT_IND");
1398 return ("DL_RESET_REQ");
1401 return ("DL_RESET_IND");
1404 return ("DL_RESET_RES");
1407 return ("DL_RESET_CON");
1410 (void) sprintf(primbuf
, "unknown primitive 0x%x", prim
);
1416 dlattachreq(int fd
, bpf_u_int32 ppa
, char *ebuf
)
1418 dl_attach_req_t req
;
1420 req
.dl_primitive
= DL_ATTACH_REQ
;
1423 return (send_request(fd
, (char *)&req
, sizeof(req
), "attach", ebuf
));
1427 dlbindreq(int fd
, bpf_u_int32 sap
, char *ebuf
)
1432 memset((char *)&req
, 0, sizeof(req
));
1433 req
.dl_primitive
= DL_BIND_REQ
;
1434 /* XXX - what if neither of these are defined? */
1435 #if defined(DL_HP_RAWDLS)
1436 req
.dl_max_conind
= 1; /* XXX magic number */
1437 req
.dl_service_mode
= DL_HP_RAWDLS
;
1438 #elif defined(DL_CLDLS)
1439 req
.dl_service_mode
= DL_CLDLS
;
1443 return (send_request(fd
, (char *)&req
, sizeof(req
), "bind", ebuf
));
1447 dlbindack(int fd
, char *bufp
, char *ebuf
, int *uerror
)
1450 return (recv_ack(fd
, DL_BIND_ACK_SIZE
, "bind", bufp
, ebuf
, uerror
));
1454 dlpromisconreq(int fd
, bpf_u_int32 level
, char *ebuf
)
1456 dl_promiscon_req_t req
;
1458 req
.dl_primitive
= DL_PROMISCON_REQ
;
1459 req
.dl_level
= level
;
1461 return (send_request(fd
, (char *)&req
, sizeof(req
), "promiscon", ebuf
));
1465 dlokack(int fd
, const char *what
, char *bufp
, char *ebuf
)
1468 return (recv_ack(fd
, DL_OK_ACK_SIZE
, what
, bufp
, ebuf
, NULL
));
1473 dlinforeq(int fd
, char *ebuf
)
1477 req
.dl_primitive
= DL_INFO_REQ
;
1479 return (send_request(fd
, (char *)&req
, sizeof(req
), "info", ebuf
));
1483 dlinfoack(int fd
, char *bufp
, char *ebuf
)
1486 return (recv_ack(fd
, DL_INFO_ACK_SIZE
, "info", bufp
, ebuf
, NULL
));
1491 * There's an ack *if* there's an error.
1494 dlrawdatareq(int fd
, const u_char
*datap
, int datalen
)
1496 struct strbuf ctl
, data
;
1497 long buf
[MAXDLBUF
]; /* XXX - char? */
1498 union DL_primitives
*dlp
;
1501 dlp
= (union DL_primitives
*) buf
;
1503 dlp
->dl_primitive
= DL_HP_RAWDATA_REQ
;
1504 dlen
= DL_HP_RAWDATA_REQ_SIZE
;
1507 * HP's documentation doesn't appear to show us supplying any
1508 * address pointed to by the control part of the message.
1509 * I think that's what raw mode means - you just send the raw
1510 * packet, you don't specify where to send it to, as that's
1511 * implied by the destination address.
1515 ctl
.buf
= (void *)buf
;
1519 data
.buf
= (void *)datap
;
1521 return (putmsg(fd
, &ctl
, &data
, 0));
1523 #endif /* DL_HP_RAWDLS */
1525 #ifdef HAVE_SYS_BUFMOD_H
1527 strioctl(int fd
, int cmd
, int len
, char *dp
)
1529 struct strioctl str
;
1536 rc
= ioctl(fd
, I_STR
, &str
);
1541 return (str
.ic_len
);
1545 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
1547 get_release(bpf_u_int32
*majorp
, bpf_u_int32
*minorp
, bpf_u_int32
*microp
)
1550 static char buf
[32];
1555 if (sysinfo(SI_RELEASE
, buf
, sizeof(buf
)) < 0)
1558 if (!isdigit((unsigned char)*cp
))
1560 *majorp
= strtol(cp
, &cp
, 10);
1563 *minorp
= strtol(cp
, &cp
, 10);
1566 *microp
= strtol(cp
, &cp
, 10);
1571 #ifdef DL_HP_PPA_REQ
1573 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1578 * Determine ppa number that specifies ifname.
1580 * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
1581 * the code that's used here is the old code for HP-UX 10.x.
1583 * However, HP-UX 10.20, at least, appears to have such a member
1584 * in its "dl_hp_ppa_info_t" structure, so the new code is used.
1585 * The new code didn't work on an old 10.20 system on which Rick
1586 * Jones of HP tried it, but with later patches installed, it
1587 * worked - it appears that the older system had those members but
1588 * didn't put anything in them, so, if the search by name fails, we
1589 * do the old search.
1591 * Rick suggests that making sure your system is "up on the latest
1592 * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
1593 * that problem, as well as allowing libpcap to see packets sent
1594 * from the system on which the libpcap application is being run.
1595 * (On 10.20, in addition to getting the latest patches, you need
1596 * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
1597 * a posting to "comp.sys.hp.hpux" at
1599 * http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
1601 * says that, to see the machine's outgoing traffic, you'd need to
1602 * apply the right patches to your system, and also set that variable
1605 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1607 * which could be put in, for example, "/sbin/init.d/lan".
1609 * Setting the variable is not necessary on HP-UX 11.x.
1612 get_dlpi_ppa(register int fd
, register const char *device
, register int unit
,
1613 register char *ebuf
)
1615 register dl_hp_ppa_ack_t
*ap
;
1616 register dl_hp_ppa_info_t
*ipstart
, *ip
;
1619 register u_long majdev
;
1620 struct stat statbuf
;
1621 dl_hp_ppa_req_t req
;
1624 dl_hp_ppa_ack_t
*dlp
;
1629 memset((char *)&req
, 0, sizeof(req
));
1630 req
.dl_primitive
= DL_HP_PPA_REQ
;
1632 memset((char *)buf
, 0, sizeof(buf
));
1633 if (send_request(fd
, (char *)&req
, sizeof(req
), "hpppa", ebuf
) < 0)
1636 ctl
.maxlen
= DL_HP_PPA_ACK_SIZE
;
1638 ctl
.buf
= (char *)buf
;
1642 * DLPI may return a big chunk of data for a DL_HP_PPA_REQ. The normal
1643 * recv_ack will fail because it set the maxlen to MAXDLBUF (8192)
1644 * which is NOT big enough for a DL_HP_PPA_REQ.
1646 * This causes libpcap applications to fail on a system with HP-APA
1649 * To figure out how big the returned data is, we first call getmsg
1650 * to get the small head and peek at the head to get the actual data
1651 * length, and then issue another getmsg to get the actual PPA data.
1653 /* get the head first */
1654 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1655 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1656 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1660 dlp
= (dl_hp_ppa_ack_t
*)ctl
.buf
;
1661 if (dlp
->dl_primitive
!= DL_HP_PPA_ACK
) {
1662 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1663 "get_dlpi_ppa: hpppa unexpected primitive ack 0x%x",
1664 (bpf_u_int32
)dlp
->dl_primitive
);
1668 if (ctl
.len
< DL_HP_PPA_ACK_SIZE
) {
1669 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1670 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1671 ctl
.len
, (unsigned long)DL_HP_PPA_ACK_SIZE
);
1675 /* allocate buffer */
1676 if ((ppa_data_buf
= (char *)malloc(dlp
->dl_length
)) == NULL
) {
1677 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1678 "get_dlpi_ppa: hpppa malloc: %s", pcap_strerror(errno
));
1681 ctl
.maxlen
= dlp
->dl_length
;
1683 ctl
.buf
= (char *)ppa_data_buf
;
1685 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1686 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1687 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1691 if (ctl
.len
< dlp
->dl_length
) {
1692 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1693 "get_dlpi_ppa: hpppa ack too small (%d < %d)",
1694 ctl
.len
, dlp
->dl_length
);
1699 ap
= (dl_hp_ppa_ack_t
*)buf
;
1700 ipstart
= (dl_hp_ppa_info_t
*)ppa_data_buf
;
1703 #ifdef HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1
1705 * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
1706 * member that should, in theory, contain the part of the
1707 * name for the device that comes before the unit number,
1708 * and should also have a "dl_module_id_2" member that may
1709 * contain an alternate name (e.g., I think Ethernet devices
1710 * have both "lan", for "lanN", and "snap", for "snapN", with
1711 * the former being for Ethernet packets and the latter being
1712 * for 802.3/802.2 packets).
1714 * Search for the device that has the specified name and
1717 for (i
= 0; i
< ap
->dl_count
; i
++) {
1718 if ((strcmp((const char *)ip
->dl_module_id_1
, device
) == 0 ||
1719 strcmp((const char *)ip
->dl_module_id_2
, device
) == 0) &&
1720 ip
->dl_instance_num
== unit
)
1723 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1727 * We don't have that member, so the search is impossible; make it
1728 * look as if the search failed.
1733 if (i
== ap
->dl_count
) {
1735 * Well, we didn't, or can't, find the device by name.
1737 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1738 * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
1739 * doesn't seem to fill them in unless the system is
1740 * at a reasonably up-to-date patch level.
1742 * Older HP-UX 10.x systems might not have those fields
1745 * Therefore, we'll search for the entry with the major
1746 * device number of a device with the name "/dev/<dev><unit>",
1747 * if such a device exists, as the old code did.
1749 snprintf(dname
, sizeof(dname
), "/dev/%s%d", device
, unit
);
1750 if (stat(dname
, &statbuf
) < 0) {
1751 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "stat: %s: %s",
1752 dname
, pcap_strerror(errno
));
1755 majdev
= major(statbuf
.st_rdev
);
1759 for (i
= 0; i
< ap
->dl_count
; i
++) {
1760 if (ip
->dl_mjr_num
== majdev
&&
1761 ip
->dl_instance_num
== unit
)
1764 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1767 if (i
== ap
->dl_count
) {
1768 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1769 "can't find /dev/dlpi PPA for %s%d", device
, unit
);
1772 if (ip
->dl_hdw_state
== HDW_DEAD
) {
1773 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1774 "%s%d: hardware state: DOWN\n", device
, unit
);
1786 * Under HP-UX 9, there is no good way to determine the ppa.
1787 * So punt and read it from /dev/kmem.
1789 static struct nlist nl
[] = {
1795 static char path_vmunix
[] = "/hp-ux";
1797 /* Determine ppa number that specifies ifname */
1799 get_dlpi_ppa(register int fd
, register const char *ifname
, register int unit
,
1800 register char *ebuf
)
1802 register const char *cp
;
1806 char if_name
[sizeof(ifnet
.if_name
) + 1];
1808 cp
= strrchr(ifname
, '/');
1811 if (nlist(path_vmunix
, &nl
) < 0) {
1812 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "nlist %s failed",
1816 if (nl
[NL_IFNET
].n_value
== 0) {
1817 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1818 "could't find %s kernel symbol",
1819 nl
[NL_IFNET
].n_name
);
1822 kd
= open("/dev/kmem", O_RDONLY
);
1824 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "kmem open: %s",
1825 pcap_strerror(errno
));
1828 if (dlpi_kread(kd
, nl
[NL_IFNET
].n_value
,
1829 &addr
, sizeof(addr
), ebuf
) < 0) {
1833 for (; addr
!= NULL
; addr
= ifnet
.if_next
) {
1834 if (dlpi_kread(kd
, (off_t
)addr
,
1835 &ifnet
, sizeof(ifnet
), ebuf
) < 0 ||
1836 dlpi_kread(kd
, (off_t
)ifnet
.if_name
,
1837 if_name
, sizeof(ifnet
.if_name
), ebuf
) < 0) {
1841 if_name
[sizeof(ifnet
.if_name
)] = '\0';
1842 if (strcmp(if_name
, ifname
) == 0 && ifnet
.if_unit
== unit
)
1843 return (ifnet
.if_index
);
1846 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "Can't find %s", ifname
);
1851 dlpi_kread(register int fd
, register off_t addr
,
1852 register void *buf
, register u_int len
, register char *ebuf
)
1856 if (lseek(fd
, addr
, SEEK_SET
) < 0) {
1857 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "lseek: %s",
1858 pcap_strerror(errno
));
1861 cc
= read(fd
, buf
, len
);
1863 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "read: %s",
1864 pcap_strerror(errno
));
1866 } else if (cc
!= len
) {
1867 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "short read (%d != %d)", cc
,