]>
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) and Mark Pizzolato
24 * <List-tcpdump-workers@subscriptions.pizzolato.net>.
28 * Packet capture routine for DLPI under SunOS 5, HP-UX 9/10/11, and AIX.
32 * - The DLIOCRAW ioctl() is specific to SunOS.
34 * - There is a bug in bufmod(7) such that setting the snapshot
35 * length results in data being left of the front of the packet.
37 * - It might be desirable to use pfmod(7) to filter packets in the
38 * kernel when possible.
40 * - An older version of the HP-UX DLPI Programmer's Guide, which
41 * I think was advertised as the 10.20 version, used to be available
44 * http://docs.hp.com/hpux/onlinedocs/B2355-90093/B2355-90093.html
46 * but is no longer available; it can still be found at
48 * http://h21007.www2.hp.com/dspp/files/unprotected/Drivers/Docs/Refs/B2355-90093.pdf
52 * - The HP-UX 10.x, 11.0, and 11i v1.6 version of the HP-UX DLPI
53 * Programmer's Guide, which I think was once advertised as the
54 * 11.00 version is available at
56 * http://docs.hp.com/en/B2355-90139/index.html
58 * - The HP-UX 11i v2 version of the HP-UX DLPI Programmer's Guide
61 * http://docs.hp.com/en/B2355-90871/index.html
63 * - All of the HP documents describe raw-mode services, which are
64 * what we use if DL_HP_RAWDLS is defined.
68 static const char rcsid
[] _U_
=
69 "@(#) $Header: /tcpdump/master/libpcap/pcap-dlpi.c,v 1.108.2.1 2005-04-10 18:04:51 hannes Exp $ (LBL)";
76 #include <sys/types.h>
78 #ifdef HAVE_SYS_BUFMOD_H
79 #include <sys/bufmod.h>
82 #ifdef HAVE_SYS_DLPI_EXT_H
83 #include <sys/dlpi_ext.h>
86 #include <sys/socket.h>
91 #include <sys/stream.h>
92 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
93 #include <sys/systeminfo.h>
116 #define INT_MAX 2147483647
119 #include "pcap-int.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
135 #ifdef HAVE_SYS_BUFMOD_H
138 * Size of a bufmod chunk to pass upstream; that appears to be the biggest
139 * value to which you can set it, and setting it to that value (which
140 * is bigger than what appears to be the Solaris default of 8192)
141 * reduces the number of packet drops.
143 #define CHUNKSIZE 65536
146 * Size of the buffer to allocate for packet data we read; it must be
147 * large enough to hold a chunk.
149 #define PKTBUFSIZE CHUNKSIZE
151 #else /* HAVE_SYS_BUFMOD_H */
154 * Size of the buffer to allocate for packet data we read; this is
155 * what the value used to be - there's no particular reason why it
156 * should be tied to MAXDLBUF, but we'll leave it as this for now.
158 #define PKTBUFSIZE (MAXDLBUF * sizeof(bpf_u_int32))
163 static char *split_dname(char *, int *, char *);
164 static int dl_doattach(int, int, char *);
165 static int dlattachreq(int, bpf_u_int32
, char *);
166 static int dlbindreq(int, bpf_u_int32
, char *);
167 static int dlbindack(int, char *, char *);
168 static int dlpromisconreq(int, bpf_u_int32
, char *);
169 static int dlokack(int, const char *, char *, char *);
170 static int dlinforeq(int, char *);
171 static int dlinfoack(int, char *, char *);
173 static int dlrawdatareq(int, const u_char
*, int);
175 static int recv_ack(int, int, const char *, char *, char *);
176 static char *dlstrerror(bpf_u_int32
);
177 static char *dlprim(bpf_u_int32
);
178 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
179 static char *get_release(bpf_u_int32
*, bpf_u_int32
*, bpf_u_int32
*);
181 static int send_request(int, char *, int, char *, char *);
182 #ifdef HAVE_SYS_BUFMOD_H
183 static int strioctl(int, int, int, char *);
186 static int dlpi_kread(int, off_t
, void *, u_int
, char *);
189 static int get_dlpi_ppa(int, const char *, int, char *);
193 pcap_stats_dlpi(pcap_t
*p
, struct pcap_stat
*ps
)
197 * "ps_recv" counts packets handed to the filter, not packets
198 * that passed the filter. As filtering is done in userland,
199 * this would not include packets dropped because we ran out
200 * of buffer space; in order to make this more like other
201 * platforms (Linux 2.4 and later, BSDs with BPF), where the
202 * "packets received" count includes packets received but dropped
203 * due to running out of buffer space, and to keep from confusing
204 * applications that, for example, compute packet drop percentages,
205 * we also make it count packets dropped by "bufmod" (otherwise we
206 * might run the risk of the packet drop count being bigger than
207 * the received-packet count).
209 * "ps_drop" counts packets dropped by "bufmod" because of
210 * flow control requirements or resource exhaustion; it doesn't
211 * count packets dropped by the interface driver, or packets
212 * dropped upstream. As filtering is done in userland, it counts
213 * packets regardless of whether they would've passed the filter.
215 * These statistics don't include packets not yet read from
216 * the kernel by libpcap, but they may include packets not
217 * yet read from libpcap by the application.
222 * Add in the drop count, as per the above comment.
224 ps
->ps_recv
+= ps
->ps_drop
;
228 /* XXX Needed by HP-UX (at least) */
229 static bpf_u_int32 ctlbuf
[MAXDLBUF
];
230 static struct strbuf ctl
= {
237 pcap_read_dlpi(pcap_t
*p
, int cnt
, pcap_handler callback
, u_char
*user
)
239 register int cc
, n
, caplen
, origlen
;
240 register u_char
*bp
, *ep
, *pk
;
241 register struct bpf_insn
*fcode
;
242 #ifdef HAVE_SYS_BUFMOD_H
243 register struct sb_hdr
*sbp
;
250 struct pcap_pkthdr pkthdr
;
255 data
.buf
= (char *)p
->buffer
+ p
->offset
;
256 data
.maxlen
= p
->bufsize
;
260 * Has "pcap_breakloop()" been called?
264 * Yes - clear the flag that indicates
265 * that it has, and return -2 to
266 * indicate that we were told to
267 * break out of the loop.
273 * XXX - check for the DLPI primitive, which
274 * would be DL_HP_RAWDATA_IND on HP-UX
275 * if we're in raw mode?
277 if (getmsg(p
->fd
, &ctl
, &data
, &flags
) < 0) {
278 /* Don't choke when we get ptraced */
288 strlcpy(p
->errbuf
, pcap_strerror(errno
),
294 bp
= p
->buffer
+ p
->offset
;
298 /* Loop through packets */
299 fcode
= p
->fcode
.bf_insns
;
302 #ifdef HAVE_SYS_BUFMOD_H
305 * Has "pcap_breakloop()" been called?
306 * If so, return immediately - if we haven't read any
307 * packets, clear the flag and return -2 to indicate
308 * that we were told to break out of the loop, otherwise
309 * leave the flag set, so that the *next* call will break
310 * out of the loop without having read any packets, and
311 * return the number of packets we've processed so far.
326 memcpy(sbp
, bp
, sizeof(*sbp
));
329 sbp
= (struct sb_hdr
*)bp
;
330 p
->md
.stat
.ps_drop
= sbp
->sbh_drops
;
331 pk
= bp
+ sizeof(*sbp
);
332 bp
+= sbp
->sbh_totlen
;
333 origlen
= sbp
->sbh_origlen
;
334 caplen
= sbp
->sbh_msglen
;
337 caplen
= min(p
->snapshot
, cc
);
341 ++p
->md
.stat
.ps_recv
;
342 if (bpf_filter(fcode
, pk
, origlen
, caplen
)) {
343 #ifdef HAVE_SYS_BUFMOD_H
344 pkthdr
.ts
.tv_sec
= sbp
->sbh_timestamp
.tv_sec
;
345 pkthdr
.ts
.tv_usec
= sbp
->sbh_timestamp
.tv_usec
;
347 (void)gettimeofday(&pkthdr
.ts
, NULL
);
349 pkthdr
.len
= origlen
;
350 pkthdr
.caplen
= caplen
;
351 /* Insure caplen does not exceed snapshot */
352 if (pkthdr
.caplen
> p
->snapshot
)
353 pkthdr
.caplen
= p
->snapshot
;
354 (*callback
)(user
, &pkthdr
, pk
);
355 if (++n
>= cnt
&& cnt
>= 0) {
361 #ifdef HAVE_SYS_BUFMOD_H
369 pcap_inject_dlpi(pcap_t
*p
, const void *buf
, size_t size
)
373 #if defined(DLIOCRAW)
374 ret
= write(p
->fd
, buf
, size
);
376 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
377 pcap_strerror(errno
));
380 #elif defined(DL_HP_RAWDLS)
381 if (p
->send_fd
< 0) {
382 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
383 "send: Output FD couldn't be opened");
386 ret
= dlrawdatareq(p
->send_fd
, buf
, size
);
388 snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
, "send: %s",
389 pcap_strerror(errno
));
392 #else /* no raw mode */
394 * XXX - this is a pain, because you might have to extract
395 * the address from the packet and use it in a DL_UNITDATA_REQ
396 * request. That would be dependent on the link-layer type.
398 * I also don't know what SAP you'd have to bind the descriptor
399 * to, or whether you'd need separate "receive" and "send" FDs,
400 * nor do I know whether you'd need different bindings for
401 * D/I/X Ethernet and 802.3, or for {FDDI,Token Ring} plus
402 * 802.2 and {FDDI,Token Ring} plus 802.2 plus SNAP.
404 * So, for now, we just return a "you can't send" indication,
405 * and leave it up to somebody with a DLPI-based system lacking
406 * both DLIOCRAW and DL_HP_RAWDLS to supply code to implement
407 * packet transmission on that system. If they do, they should
408 * send it to us - but should not send us code that assumes
409 * Ethernet; if the code doesn't work on non-Ethernet interfaces,
410 * it should check "p->linktype" and reject the send request if
411 * it's anything other than DLT_EN10MB.
413 strlcpy(p
->errbuf
, "send: Not supported on this version of this OS",
416 #endif /* raw mode */
421 #define DL_IPATM 0x12 /* ATM Classical IP interface */
429 #define A_GET_UNITS (('A'<<8)|118)
430 #endif /* A_GET_UNITS */
431 #ifndef A_PROMISCON_REQ
432 #define A_PROMISCON_REQ (('A'<<8)|121)
433 #endif /* A_PROMISCON_REQ */
434 #endif /* HAVE_SOLARIS */
437 pcap_close_dlpi(pcap_t
*p
)
439 pcap_close_common(p
);
445 pcap_open_live(const char *device
, int snaplen
, int promisc
, int to_ms
,
454 register dl_info_ack_t
*infop
;
455 #ifdef HAVE_SYS_BUFMOD_H
456 bpf_u_int32 ss
, chunksize
;
458 register char *release
;
459 bpf_u_int32 osmajor
, osminor
, osmicro
;
462 bpf_u_int32 buf
[MAXDLBUF
];
464 #ifndef HAVE_DEV_DLPI
468 p
= (pcap_t
*)malloc(sizeof(*p
));
470 strlcpy(ebuf
, pcap_strerror(errno
), PCAP_ERRBUF_SIZE
);
473 memset(p
, 0, sizeof(*p
));
474 p
->fd
= -1; /* indicate that it hasn't been opened yet */
479 ** Remove any "/dev/" on the front of the device.
481 cp
= strrchr(device
, '/');
483 strlcpy(dname
, device
, sizeof(dname
));
485 strlcpy(dname
, cp
+ 1, sizeof(dname
));
488 * Split the device name into a device type name and a unit number;
489 * chop off the unit number, so "dname" is just a device type name.
491 cp
= split_dname(dname
, &ppa
, ebuf
);
497 * Use "/dev/dlpi" as the device.
499 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
500 * the "dl_mjr_num" field is for the "major number of interface
501 * driver"; that's the major of "/dev/dlpi" on the system on
502 * which I tried this, but there may be DLPI devices that
503 * use a different driver, in which case we may need to
504 * search "/dev" for the appropriate device with that major
505 * device number, rather than hardwiring "/dev/dlpi".
508 if ((p
->fd
= open(cp
, O_RDWR
)) < 0) {
509 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
510 "%s: %s", cp
, pcap_strerror(errno
));
516 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
517 * receiving packets on the same descriptor - you have to bind the
518 * descriptor on which you receive to a SAP of 22 and bind the
519 * descriptor on which you send to a SAP of 24.
521 * If the open fails, we just leave -1 in "p->send_fd" and reject
522 * attempts to send packets, just as if, in pcap-bpf.c, we fail
523 * to open the BPF device for reading and writing, we just try
524 * to open it for reading only and, if that succeeds, just let
525 * the send attempts fail.
527 p
->send_fd
= open(cp
, O_RDWR
);
531 * Get a table of all PPAs for that device, and search that
532 * table for the specified device type name and unit number.
534 ppa
= get_dlpi_ppa(p
->fd
, dname
, ppa
, ebuf
);
539 * If the device name begins with "/", assume it begins with
540 * the pathname of the directory containing the device to open;
541 * otherwise, concatenate the device directory name and the
545 strlcpy(dname
, device
, sizeof(dname
));
547 snprintf(dname
, sizeof(dname
), "%s/%s", PCAP_DEV_PREFIX
,
551 * Get the unit number, and a pointer to the end of the device
554 cp
= split_dname(dname
, &ppa
, ebuf
);
559 * Make a copy of the device pathname, and then remove the unit
560 * number from the device pathname.
562 strlcpy(dname2
, dname
, sizeof(dname
));
565 /* Try device without unit number */
566 if ((p
->fd
= open(dname
, O_RDWR
)) < 0) {
567 if (errno
!= ENOENT
) {
568 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s: %s", dname
,
569 pcap_strerror(errno
));
573 /* Try again with unit number */
574 if ((p
->fd
= open(dname2
, O_RDWR
)) < 0) {
575 if (errno
== ENOENT
) {
577 * We just report "No DLPI device found"
578 * with the device name, so people don't
579 * get confused and think, for example,
580 * that if they can't capture on "lo0"
581 * on Solaris the fix is to change libpcap
582 * (or the application that uses it) to
583 * look for something other than "/dev/lo0",
584 * as the fix is to look for an operating
585 * system other than Solaris - you just
586 * *can't* capture on a loopback interface
587 * on Solaris, the lack of a DLPI device
588 * for the loopback interface is just a
589 * symptom of that inability.
591 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
592 "%s: No DLPI device found", device
);
594 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s: %s",
595 dname2
, pcap_strerror(errno
));
599 /* XXX Assume unit zero */
604 p
->snapshot
= snaplen
;
607 ** Attach if "style 2" provider
609 if (dlinforeq(p
->fd
, ebuf
) < 0 ||
610 dlinfoack(p
->fd
, (char *)buf
, ebuf
) < 0)
612 infop
= &((union DL_primitives
*)buf
)->info_ack
;
614 if (infop
->dl_mac_type
== DL_IPATM
)
617 if (infop
->dl_provider_style
== DL_STYLE2
) {
618 if (dl_doattach(p
->fd
, ppa
, ebuf
) < 0)
621 if (p
->send_fd
>= 0) {
622 if (dl_doattach(p
->send_fd
, ppa
, ebuf
) < 0)
629 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
630 ** skip if using SINIX)
632 #if !defined(HAVE_HPUX9) && !defined(HAVE_HPUX10_20_OR_LATER) && !defined(sinix)
634 /* According to IBM's AIX Support Line, the dl_sap value
635 ** should not be less than 0x600 (1536) for standard Ethernet.
636 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
637 ** format or invalid" - errors if we use 1537 on the "tr0"
638 ** device, which, given that its name starts with "tr" and that
639 ** it's IBM, probably means a Token Ring device. (Perhaps we
640 ** need to use 1537 on "/dev/dlpi/en" because that device is for
641 ** D/I/X Ethernet, the "SAP" is actually an Ethernet type, and
642 ** it rejects invalid Ethernet types.)
644 ** So if 1537 fails, we try 2, as Hyung Sik Yoon of IBM Korea
645 ** says that works on Token Ring (he says that 0 does *not*
646 ** work; perhaps that's considered an invalid LLC SAP value - I
647 ** assume the SAP value in a DLPI bind is an LLC SAP for network
648 ** types that use 802.2 LLC).
650 if ((dlbindreq(p
->fd
, 1537, ebuf
) < 0 &&
651 dlbindreq(p
->fd
, 2, ebuf
) < 0) ||
652 dlbindack(p
->fd
, (char *)buf
, ebuf
) < 0)
654 #elif defined(DL_HP_RAWDLS)
656 ** This is the descriptor on which we receive packets; we
657 ** bind it to 22, as that's INSAP, as per the HP-UX DLPI
658 ** Programmer's Guide.
660 ** XXX - is the SAP relevant? Apparently, if some application
661 ** is already bound to that SAP, this fails with a DL_ERROR_ACK
662 ** message of type DL_SYSERR with an errno of EBUSY, and
663 ** the primitives we use already imply raw mode. Should we,
664 ** instead, just keep trying SAPs from some set of SAPs until
665 ** we don't fail with EBUSY?
667 if (dlbindreq(p
->fd
, 22, ebuf
) < 0 ||
668 dlbindack(p
->fd
, (char *)buf
, ebuf
) < 0)
671 if (p
->send_fd
>= 0) {
673 ** This is the descriptor on which we send packets; we
674 ** bind it to 24, as that's OUTSAP, as per the HP-UX
675 ** DLPI Programmer's Guide.
677 if (dlbindreq(p
->send_fd
, 24, ebuf
) < 0 ||
678 dlbindack(p
->send_fd
, (char *)buf
, ebuf
) < 0)
681 #else /* neither AIX nor HP-UX */
682 if (dlbindreq(p
->fd
, 0, ebuf
) < 0 ||
683 dlbindack(p
->fd
, (char *)buf
, ebuf
) < 0)
685 #endif /* SAP to bind to */
686 #endif /* HP-UX 9 or 10.20 or SINIX */
691 ** Have to turn on some special ATM promiscuous mode
693 ** Do *NOT* turn regular promiscuous mode on; it doesn't
694 ** help, and may break things.
696 if (strioctl(p
->fd
, A_PROMISCON_REQ
, 0, NULL
) < 0) {
697 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "A_PROMISCON_REQ: %s",
698 pcap_strerror(errno
));
705 ** Enable promiscuous (not necessary on send FD)
707 if (dlpromisconreq(p
->fd
, DL_PROMISC_PHYS
, ebuf
) < 0 ||
708 dlokack(p
->fd
, "promisc_phys", (char *)buf
, ebuf
) < 0)
712 ** Try to enable multicast (you would have thought
713 ** promiscuous would be sufficient). (Skip if using
714 ** HP-UX or SINIX) (Not necessary on send FD)
716 #if !defined(__hpux) && !defined(sinix)
717 if (dlpromisconreq(p
->fd
, DL_PROMISC_MULTI
, ebuf
) < 0 ||
718 dlokack(p
->fd
, "promisc_multi", (char *)buf
, ebuf
) < 0)
720 "WARNING: DL_PROMISC_MULTI failed (%s)\n", ebuf
);
724 ** Try to enable sap (when not in promiscuous mode when using
725 ** using HP-UX, when not doing SunATM on Solaris, and never
726 ** under SINIX) (Not necessary on send FD)
736 (dlpromisconreq(p
->fd
, DL_PROMISC_SAP
, ebuf
) < 0 ||
737 dlokack(p
->fd
, "promisc_sap", (char *)buf
, ebuf
) < 0)) {
738 /* Not fatal if promisc since the DL_PROMISC_PHYS worked */
741 "WARNING: DL_PROMISC_SAP failed (%s)\n", ebuf
);
748 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
749 ** promiscuous options)
751 #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
752 if (dlbindreq(p
->fd
, 0, ebuf
) < 0 ||
753 dlbindack(p
->fd
, (char *)buf
, ebuf
) < 0)
758 ** Determine link type
759 ** XXX - get SAP length and address length as well, for use
760 ** when sending packets.
762 if (dlinforeq(p
->fd
, ebuf
) < 0 ||
763 dlinfoack(p
->fd
, (char *)buf
, ebuf
) < 0)
766 infop
= &((union DL_primitives
*)buf
)->info_ack
;
767 switch (infop
->dl_mac_type
) {
771 p
->linktype
= DLT_EN10MB
;
774 * This is (presumably) a real Ethernet capture; give it a
775 * link-layer-type list with DLT_EN10MB and DLT_DOCSIS, so
776 * that an application can let you choose it, in case you're
777 * capturing DOCSIS traffic that a Cisco Cable Modem
778 * Termination System is putting out onto an Ethernet (it
779 * doesn't put an Ethernet header onto the wire, it puts raw
780 * DOCSIS frames out on the wire inside the low-level
783 p
->dlt_list
= (u_int
*) malloc(sizeof(u_int
) * 2);
785 * If that fails, just leave the list empty.
787 if (p
->dlt_list
!= NULL
) {
788 p
->dlt_list
[0] = DLT_EN10MB
;
789 p
->dlt_list
[1] = DLT_DOCSIS
;
795 p
->linktype
= DLT_FDDI
;
801 * XXX - what about DL_TPB? Is that Token Bus?
803 p
->linktype
= DLT_IEEE802
;
809 p
->linktype
= DLT_SUNATM
;
810 p
->offset
= 0; /* works for LANE and LLC encapsulation */
815 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "unknown mac type %lu",
816 (unsigned long)infop
->dl_mac_type
);
822 ** This is a non standard SunOS hack to get the full raw link-layer
825 if (strioctl(p
->fd
, DLIOCRAW
, 0, NULL
) < 0) {
826 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "DLIOCRAW: %s",
827 pcap_strerror(errno
));
832 #ifdef HAVE_SYS_BUFMOD_H
834 ** Another non standard call to get the data nicely buffered
836 if (ioctl(p
->fd
, I_PUSH
, "bufmod") != 0) {
837 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "I_PUSH bufmod: %s",
838 pcap_strerror(errno
));
843 ** Now that the bufmod is pushed lets configure it.
845 ** There is a bug in bufmod(7). When dealing with messages of
846 ** less than snaplen size it strips data from the beginning not
849 ** This bug is supposed to be fixed in 5.3.2. Also, there is a
850 ** patch available. Ask for bugid 1149065.
854 release
= get_release(&osmajor
, &osminor
, &osmicro
);
855 if (osmajor
== 5 && (osminor
<= 2 || (osminor
== 3 && osmicro
< 2)) &&
856 getenv("BUFMOD_FIXED") == NULL
) {
858 "WARNING: bufmod is broken in SunOS %s; ignoring snaplen.\n",
864 strioctl(p
->fd
, SBIOCSSNAP
, sizeof(ss
), (char *)&ss
) != 0) {
865 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSSNAP: %s",
866 pcap_strerror(errno
));
871 ** Set up the bufmod timeout
876 to
.tv_sec
= to_ms
/ 1000;
877 to
.tv_usec
= (to_ms
* 1000) % 1000000;
878 if (strioctl(p
->fd
, SBIOCSTIME
, sizeof(to
), (char *)&to
) != 0) {
879 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSTIME: %s",
880 pcap_strerror(errno
));
886 ** Set the chunk length.
888 chunksize
= CHUNKSIZE
;
889 if (strioctl(p
->fd
, SBIOCSCHUNK
, sizeof(chunksize
), (char *)&chunksize
)
891 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "SBIOCSCHUNKP: %s",
892 pcap_strerror(errno
));
898 ** As the last operation flush the read side.
900 if (ioctl(p
->fd
, I_FLUSH
, FLUSHR
) != 0) {
901 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "FLUSHR: %s",
902 pcap_strerror(errno
));
906 /* Allocate data buffer */
907 p
->bufsize
= PKTBUFSIZE
;
908 p
->buffer
= (u_char
*)malloc(p
->bufsize
+ p
->offset
);
909 if (p
->buffer
== NULL
) {
910 strlcpy(ebuf
, pcap_strerror(errno
), PCAP_ERRBUF_SIZE
);
915 * "p->fd" is an FD for a STREAMS device, so "select()" and
916 * "poll()" should work on it.
918 p
->selectable_fd
= p
->fd
;
920 p
->read_op
= pcap_read_dlpi
;
921 p
->inject_op
= pcap_inject_dlpi
;
922 p
->setfilter_op
= install_bpf_program
; /* no kernel filtering */
923 p
->set_datalink_op
= NULL
; /* can't change data link type */
924 p
->getnonblock_op
= pcap_getnonblock_fd
;
925 p
->setnonblock_op
= pcap_setnonblock_fd
;
926 p
->stats_op
= pcap_stats_dlpi
;
927 p
->close_op
= pcap_close_dlpi
;
936 * Get rid of any link-layer type list we allocated.
938 if (p
->dlt_list
!= NULL
)
945 * Split a device name into a device type name and a unit number;
946 * return the a pointer to the beginning of the unit number, which
947 * is the end of the device type name, and set "*unitp" to the unit
950 * Returns NULL on error, and fills "ebuf" with an error message.
953 split_dname(char *device
, int *unitp
, char *ebuf
)
960 * Look for a number at the end of the device name string.
962 cp
= device
+ strlen(device
) - 1;
963 if (*cp
< '0' || *cp
> '9') {
964 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s missing unit number",
969 /* Digits at end of string are unit number */
970 while (cp
-1 >= device
&& *(cp
-1) >= '0' && *(cp
-1) <= '9')
974 unit
= strtol(cp
, &eos
, 10);
976 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s bad unit number", device
);
979 if (errno
== ERANGE
|| unit
> INT_MAX
) {
980 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number too large",
985 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number is negative",
994 dl_doattach(int fd
, int ppa
, char *ebuf
)
996 bpf_u_int32 buf
[MAXDLBUF
];
998 if (dlattachreq(fd
, ppa
, ebuf
) < 0 ||
999 dlokack(fd
, "attach", (char *)buf
, ebuf
) < 0)
1005 pcap_platform_finddevs(pcap_if_t
**alldevsp
, char *errbuf
)
1011 char pad
[516]; /* XXX - must be at least 513; is 516
1018 * We may have to do special magic to get ATM devices.
1020 if ((fd
= open("/dev/ba", O_RDWR
)) < 0) {
1022 * We couldn't open the "ba" device.
1023 * For now, just give up; perhaps we should
1024 * return an error if the problem is neither
1025 * a "that device doesn't exist" error (ENOENT,
1026 * ENXIO, etc.) or a "you're not allowed to do
1027 * that" error (EPERM, EACCES).
1032 if (strioctl(fd
, A_GET_UNITS
, sizeof(buf
), (char *)&buf
) < 0) {
1033 snprintf(errbuf
, PCAP_ERRBUF_SIZE
, "A_GET_UNITS: %s",
1034 pcap_strerror(errno
));
1037 for (i
= 0; i
< buf
.nunits
; i
++) {
1038 snprintf(baname
, sizeof baname
, "ba%u", i
);
1039 if (pcap_add_if(alldevsp
, baname
, 0, NULL
, errbuf
) < 0)
1048 send_request(int fd
, char *ptr
, int len
, char *what
, char *ebuf
)
1058 if (putmsg(fd
, &ctl
, (struct strbuf
*) NULL
, flags
) < 0) {
1059 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1060 "send_request: putmsg \"%s\": %s",
1061 what
, pcap_strerror(errno
));
1068 recv_ack(int fd
, int size
, const char *what
, char *bufp
, char *ebuf
)
1070 union DL_primitives
*dlp
;
1074 ctl
.maxlen
= MAXDLBUF
;
1079 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1080 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s getmsg: %s",
1081 what
, pcap_strerror(errno
));
1085 dlp
= (union DL_primitives
*) ctl
.buf
;
1086 switch (dlp
->dl_primitive
) {
1091 #ifdef DL_HP_PPA_ACK
1098 switch (dlp
->error_ack
.dl_errno
) {
1101 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1102 "recv_ack: %s: UNIX error - %s",
1103 what
, pcap_strerror(dlp
->error_ack
.dl_unix_errno
));
1107 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "recv_ack: %s: %s",
1108 what
, dlstrerror(dlp
->error_ack
.dl_errno
));
1114 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1115 "recv_ack: %s: Unexpected primitive ack %s",
1116 what
, dlprim(dlp
->dl_primitive
));
1120 if (ctl
.len
< size
) {
1121 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1122 "recv_ack: %s: Ack too small (%d < %d)",
1123 what
, ctl
.len
, size
);
1130 dlstrerror(bpf_u_int32 dl_errno
)
1132 static char errstring
[6+2+8+1];
1137 return ("Improper permissions for request");
1140 return ("DLSAP addr in improper format or invalid");
1143 return ("Seq number not from outstand DL_CONN_IND");
1146 return ("User data exceeded provider limit");
1149 #ifdef HAVE_DEV_DLPI
1151 * With a single "/dev/dlpi" device used for all
1152 * DLPI providers, PPAs have nothing to do with
1155 return ("Specified PPA was invalid");
1158 * We have separate devices for separate devices;
1159 * the PPA is just the unit number.
1161 return ("Specified PPA (device unit) was invalid");
1165 return ("Primitive received not known by provider");
1167 case DL_BADQOSPARAM
:
1168 return ("QOS parameters contained invalid values");
1171 return ("QOS structure type is unknown/unsupported");
1174 return ("Bad LSAP selector");
1177 return ("Token used not an active stream");
1180 return ("Attempted second bind with dl_max_conind");
1183 return ("Physical link initialization failed");
1186 return ("Provider couldn't allocate alternate address");
1189 return ("Physical link not initialized");
1192 return ("Primitive issued in improper state");
1195 return ("UNIX system error occurred");
1197 case DL_UNSUPPORTED
:
1198 return ("Requested service not supplied by provider");
1200 case DL_UNDELIVERABLE
:
1201 return ("Previous data unit could not be delivered");
1203 case DL_NOTSUPPORTED
:
1204 return ("Primitive is known but not supported");
1207 return ("Limit exceeded");
1210 return ("Promiscuous mode not enabled");
1213 return ("Other streams for PPA in post-attached");
1216 return ("Automatic handling XID&TEST not supported");
1219 return ("Automatic handling of XID not supported");
1222 return ("Automatic handling of TEST not supported");
1225 return ("Automatic handling of XID response");
1228 return ("Automatic handling of TEST response");
1231 return ("Pending outstanding connect indications");
1234 sprintf(errstring
, "Error %02x", dl_errno
);
1240 dlprim(bpf_u_int32 prim
)
1242 static char primbuf
[80];
1247 return ("DL_INFO_REQ");
1250 return ("DL_INFO_ACK");
1253 return ("DL_ATTACH_REQ");
1256 return ("DL_DETACH_REQ");
1259 return ("DL_BIND_REQ");
1262 return ("DL_BIND_ACK");
1265 return ("DL_UNBIND_REQ");
1268 return ("DL_OK_ACK");
1271 return ("DL_ERROR_ACK");
1273 case DL_SUBS_BIND_REQ
:
1274 return ("DL_SUBS_BIND_REQ");
1276 case DL_SUBS_BIND_ACK
:
1277 return ("DL_SUBS_BIND_ACK");
1279 case DL_UNITDATA_REQ
:
1280 return ("DL_UNITDATA_REQ");
1282 case DL_UNITDATA_IND
:
1283 return ("DL_UNITDATA_IND");
1285 case DL_UDERROR_IND
:
1286 return ("DL_UDERROR_IND");
1289 return ("DL_UDQOS_REQ");
1291 case DL_CONNECT_REQ
:
1292 return ("DL_CONNECT_REQ");
1294 case DL_CONNECT_IND
:
1295 return ("DL_CONNECT_IND");
1297 case DL_CONNECT_RES
:
1298 return ("DL_CONNECT_RES");
1300 case DL_CONNECT_CON
:
1301 return ("DL_CONNECT_CON");
1304 return ("DL_TOKEN_REQ");
1307 return ("DL_TOKEN_ACK");
1309 case DL_DISCONNECT_REQ
:
1310 return ("DL_DISCONNECT_REQ");
1312 case DL_DISCONNECT_IND
:
1313 return ("DL_DISCONNECT_IND");
1316 return ("DL_RESET_REQ");
1319 return ("DL_RESET_IND");
1322 return ("DL_RESET_RES");
1325 return ("DL_RESET_CON");
1328 (void) sprintf(primbuf
, "unknown primitive 0x%x", prim
);
1334 dlattachreq(int fd
, bpf_u_int32 ppa
, char *ebuf
)
1336 dl_attach_req_t req
;
1338 req
.dl_primitive
= DL_ATTACH_REQ
;
1341 return (send_request(fd
, (char *)&req
, sizeof(req
), "attach", ebuf
));
1345 dlbindreq(int fd
, bpf_u_int32 sap
, char *ebuf
)
1350 memset((char *)&req
, 0, sizeof(req
));
1351 req
.dl_primitive
= DL_BIND_REQ
;
1353 req
.dl_max_conind
= 1; /* XXX magic number */
1354 /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */
1356 req
.dl_service_mode
= DL_HP_RAWDLS
;
1360 req
.dl_service_mode
= DL_CLDLS
;
1364 return (send_request(fd
, (char *)&req
, sizeof(req
), "bind", ebuf
));
1368 dlbindack(int fd
, char *bufp
, char *ebuf
)
1371 return (recv_ack(fd
, DL_BIND_ACK_SIZE
, "bind", bufp
, ebuf
));
1375 dlpromisconreq(int fd
, bpf_u_int32 level
, char *ebuf
)
1377 dl_promiscon_req_t req
;
1379 req
.dl_primitive
= DL_PROMISCON_REQ
;
1380 req
.dl_level
= level
;
1382 return (send_request(fd
, (char *)&req
, sizeof(req
), "promiscon", ebuf
));
1386 dlokack(int fd
, const char *what
, char *bufp
, char *ebuf
)
1389 return (recv_ack(fd
, DL_OK_ACK_SIZE
, what
, bufp
, ebuf
));
1394 dlinforeq(int fd
, char *ebuf
)
1398 req
.dl_primitive
= DL_INFO_REQ
;
1400 return (send_request(fd
, (char *)&req
, sizeof(req
), "info", ebuf
));
1404 dlinfoack(int fd
, char *bufp
, char *ebuf
)
1407 return (recv_ack(fd
, DL_INFO_ACK_SIZE
, "info", bufp
, ebuf
));
1412 * There's an ack *if* there's an error.
1415 dlrawdatareq(int fd
, const u_char
*datap
, int datalen
)
1417 struct strbuf ctl
, data
;
1418 long buf
[MAXDLBUF
]; /* XXX - char? */
1419 union DL_primitives
*dlp
;
1422 dlp
= (union DL_primitives
*) buf
;
1424 dlp
->dl_primitive
= DL_HP_RAWDATA_REQ
;
1425 dlen
= DL_HP_RAWDATA_REQ_SIZE
;
1428 * HP's documentation doesn't appear to show us supplying any
1429 * address pointed to by the control part of the message.
1430 * I think that's what raw mode means - you just send the raw
1431 * packet, you don't specify where to send it to, as that's
1432 * implied by the destination address.
1436 ctl
.buf
= (void *)buf
;
1440 data
.buf
= (void *)datap
;
1442 return (putmsg(fd
, &ctl
, &data
, 0));
1444 #endif /* DL_HP_RAWDLS */
1446 #ifdef HAVE_SYS_BUFMOD_H
1448 strioctl(int fd
, int cmd
, int len
, char *dp
)
1450 struct strioctl str
;
1457 rc
= ioctl(fd
, I_STR
, &str
);
1462 return (str
.ic_len
);
1466 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
1468 get_release(bpf_u_int32
*majorp
, bpf_u_int32
*minorp
, bpf_u_int32
*microp
)
1471 static char buf
[32];
1476 if (sysinfo(SI_RELEASE
, buf
, sizeof(buf
)) < 0)
1479 if (!isdigit((unsigned char)*cp
))
1481 *majorp
= strtol(cp
, &cp
, 10);
1484 *minorp
= strtol(cp
, &cp
, 10);
1487 *microp
= strtol(cp
, &cp
, 10);
1492 #ifdef DL_HP_PPA_REQ
1494 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1499 * Determine ppa number that specifies ifname.
1501 * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
1502 * the code that's used here is the old code for HP-UX 10.x.
1504 * However, HP-UX 10.20, at least, appears to have such a member
1505 * in its "dl_hp_ppa_info_t" structure, so the new code is used.
1506 * The new code didn't work on an old 10.20 system on which Rick
1507 * Jones of HP tried it, but with later patches installed, it
1508 * worked - it appears that the older system had those members but
1509 * didn't put anything in them, so, if the search by name fails, we
1510 * do the old search.
1512 * Rick suggests that making sure your system is "up on the latest
1513 * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
1514 * that problem, as well as allowing libpcap to see packets sent
1515 * from the system on which the libpcap application is being run.
1516 * (On 10.20, in addition to getting the latest patches, you need
1517 * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
1518 * a posting to "comp.sys.hp.hpux" at
1520 * http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
1522 * says that, to see the machine's outgoing traffic, you'd need to
1523 * apply the right patches to your system, and also set that variable
1526 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1528 * which could be put in, for example, "/sbin/init.d/lan".
1530 * Setting the variable is not necessary on HP-UX 11.x.
1533 get_dlpi_ppa(register int fd
, register const char *device
, register int unit
,
1534 register char *ebuf
)
1536 register dl_hp_ppa_ack_t
*ap
;
1537 register dl_hp_ppa_info_t
*ipstart
, *ip
;
1540 register u_long majdev
;
1541 struct stat statbuf
;
1542 dl_hp_ppa_req_t req
;
1545 dl_hp_ppa_ack_t
*dlp
;
1550 memset((char *)&req
, 0, sizeof(req
));
1551 req
.dl_primitive
= DL_HP_PPA_REQ
;
1553 memset((char *)buf
, 0, sizeof(buf
));
1554 if (send_request(fd
, (char *)&req
, sizeof(req
), "hpppa", ebuf
) < 0)
1557 ctl
.maxlen
= DL_HP_PPA_ACK_SIZE
;
1559 ctl
.buf
= (char *)buf
;
1563 * DLPI may return a big chunk of data for a DL_HP_PPA_REQ. The normal
1564 * recv_ack will fail because it set the maxlen to MAXDLBUF (8192)
1565 * which is NOT big enough for a DL_HP_PPA_REQ.
1567 * This causes libpcap applications to fail on a system with HP-APA
1570 * To figure out how big the returned data is, we first call getmsg
1571 * to get the small head and peek at the head to get the actual data
1572 * length, and then issue another getmsg to get the actual PPA data.
1574 /* get the head first */
1575 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1576 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1577 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1581 dlp
= (dl_hp_ppa_ack_t
*)ctl
.buf
;
1582 if (dlp
->dl_primitive
!= DL_HP_PPA_ACK
) {
1583 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1584 "get_dlpi_ppa: hpppa unexpected primitive ack 0x%x",
1585 (bpf_u_int32
)dlp
->dl_primitive
);
1589 if (ctl
.len
< DL_HP_PPA_ACK_SIZE
) {
1590 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1591 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1592 ctl
.len
, (unsigned long)DL_HP_PPA_ACK_SIZE
);
1596 /* allocate buffer */
1597 if ((ppa_data_buf
= (char *)malloc(dlp
->dl_length
)) == NULL
) {
1598 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1599 "get_dlpi_ppa: hpppa malloc: %s", pcap_strerror(errno
));
1602 ctl
.maxlen
= dlp
->dl_length
;
1604 ctl
.buf
= (char *)ppa_data_buf
;
1606 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1607 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1608 "get_dlpi_ppa: hpppa getmsg: %s", pcap_strerror(errno
));
1612 if (ctl
.len
< dlp
->dl_length
) {
1613 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1614 "get_dlpi_ppa: hpppa ack too small (%d < %d)",
1615 ctl
.len
, dlp
->dl_length
);
1620 ap
= (dl_hp_ppa_ack_t
*)buf
;
1621 ipstart
= (dl_hp_ppa_info_t
*)ppa_data_buf
;
1624 #ifdef HAVE_HP_PPA_INFO_T_DL_MODULE_ID_1
1626 * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
1627 * member that should, in theory, contain the part of the
1628 * name for the device that comes before the unit number,
1629 * and should also have a "dl_module_id_2" member that may
1630 * contain an alternate name (e.g., I think Ethernet devices
1631 * have both "lan", for "lanN", and "snap", for "snapN", with
1632 * the former being for Ethernet packets and the latter being
1633 * for 802.3/802.2 packets).
1635 * Search for the device that has the specified name and
1638 for (i
= 0; i
< ap
->dl_count
; i
++) {
1639 if ((strcmp((const char *)ip
->dl_module_id_1
, device
) == 0 ||
1640 strcmp((const char *)ip
->dl_module_id_2
, device
) == 0) &&
1641 ip
->dl_instance_num
== unit
)
1644 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1648 * We don't have that member, so the search is impossible; make it
1649 * look as if the search failed.
1654 if (i
== ap
->dl_count
) {
1656 * Well, we didn't, or can't, find the device by name.
1658 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1659 * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
1660 * doesn't seem to fill them in unless the system is
1661 * at a reasonably up-to-date patch level.
1663 * Older HP-UX 10.x systems might not have those fields
1666 * Therefore, we'll search for the entry with the major
1667 * device number of a device with the name "/dev/<dev><unit>",
1668 * if such a device exists, as the old code did.
1670 snprintf(dname
, sizeof(dname
), "/dev/%s%d", device
, unit
);
1671 if (stat(dname
, &statbuf
) < 0) {
1672 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "stat: %s: %s",
1673 dname
, pcap_strerror(errno
));
1676 majdev
= major(statbuf
.st_rdev
);
1680 for (i
= 0; i
< ap
->dl_count
; i
++) {
1681 if (ip
->dl_mjr_num
== majdev
&&
1682 ip
->dl_instance_num
== unit
)
1685 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1688 if (i
== ap
->dl_count
) {
1689 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1690 "can't find /dev/dlpi PPA for %s%d", device
, unit
);
1693 if (ip
->dl_hdw_state
== HDW_DEAD
) {
1694 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1695 "%s%d: hardware state: DOWN\n", device
, unit
);
1707 * Under HP-UX 9, there is no good way to determine the ppa.
1708 * So punt and read it from /dev/kmem.
1710 static struct nlist nl
[] = {
1716 static char path_vmunix
[] = "/hp-ux";
1718 /* Determine ppa number that specifies ifname */
1720 get_dlpi_ppa(register int fd
, register const char *ifname
, register int unit
,
1721 register char *ebuf
)
1723 register const char *cp
;
1727 char if_name
[sizeof(ifnet
.if_name
) + 1];
1729 cp
= strrchr(ifname
, '/');
1732 if (nlist(path_vmunix
, &nl
) < 0) {
1733 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "nlist %s failed",
1737 if (nl
[NL_IFNET
].n_value
== 0) {
1738 snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1739 "could't find %s kernel symbol",
1740 nl
[NL_IFNET
].n_name
);
1743 kd
= open("/dev/kmem", O_RDONLY
);
1745 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "kmem open: %s",
1746 pcap_strerror(errno
));
1749 if (dlpi_kread(kd
, nl
[NL_IFNET
].n_value
,
1750 &addr
, sizeof(addr
), ebuf
) < 0) {
1754 for (; addr
!= NULL
; addr
= ifnet
.if_next
) {
1755 if (dlpi_kread(kd
, (off_t
)addr
,
1756 &ifnet
, sizeof(ifnet
), ebuf
) < 0 ||
1757 dlpi_kread(kd
, (off_t
)ifnet
.if_name
,
1758 if_name
, sizeof(ifnet
.if_name
), ebuf
) < 0) {
1762 if_name
[sizeof(ifnet
.if_name
)] = '\0';
1763 if (strcmp(if_name
, ifname
) == 0 && ifnet
.if_unit
== unit
)
1764 return (ifnet
.if_index
);
1767 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "Can't find %s", ifname
);
1772 dlpi_kread(register int fd
, register off_t addr
,
1773 register void *buf
, register u_int len
, register char *ebuf
)
1777 if (lseek(fd
, addr
, SEEK_SET
) < 0) {
1778 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "lseek: %s",
1779 pcap_strerror(errno
));
1782 cc
= read(fd
, buf
, len
);
1784 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "read: %s",
1785 pcap_strerror(errno
));
1787 } else if (cc
!= len
) {
1788 snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "short read (%d != %d)", cc
,