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>
113 #include "pcap-int.h"
114 #include "dlpisubs.h"
116 #ifdef HAVE_OS_PROTO_H
117 #include "os-proto.h"
122 * HP-UX has a /dev/dlpi device; you open it and set the PPA of the actual
123 * network device you want.
125 #define HAVE_DEV_DLPI
128 * AIX has a /dev/dlpi directory, with devices named after the interfaces
131 #define PCAP_DEV_PREFIX "/dev/dlpi"
132 #elif defined(HAVE_SOLARIS)
134 * Solaris has devices named after the interfaces underneath /dev.
136 #define PCAP_DEV_PREFIX "/dev"
139 #define MAXDLBUF 8192
142 static char *split_dname(char *, u_int
*, char *);
143 static int dl_doattach(int, int, char *);
145 static int dl_dohpuxbind(int, char *);
147 static int dlpromiscon(pcap_t
*, bpf_u_int32
);
148 static int dlbindreq(int, bpf_u_int32
, char *);
149 static int dlbindack(int, char *, char *, int *);
150 static int dlokack(int, const char *, char *, char *);
151 static int dlinforeq(int, char *);
152 static int dlinfoack(int, char *, char *);
154 #ifdef HAVE_DL_PASSIVE_REQ_T
155 static void dlpassive(int, char *);
159 static int dlrawdatareq(int, const u_char
*, int);
161 static int recv_ack(int, int, const char *, char *, char *, int *);
162 static char *dlstrerror(char *, size_t, bpf_u_int32
);
163 static char *dlprim(char *, size_t, bpf_u_int32
);
164 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
165 #define GET_RELEASE_BUFSIZE 32
166 static void get_release(char *, size_t, bpf_u_int32
*, bpf_u_int32
*,
169 static int send_request(int, char *, int, char *, char *);
171 static int dlpi_kread(int, off_t
, void *, u_int
, char *);
174 static int get_dlpi_ppa(int, const char *, u_int
, u_int
*, char *);
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
)
189 bpf_u_int32 ctlbuf
[MAXDLBUF
];
190 struct strbuf ctl
= {
200 data
.buf
= (char *)p
->buffer
+ p
->offset
;
201 data
.maxlen
= p
->bufsize
;
205 * Has "pcap_breakloop()" been called?
209 * Yes - clear the flag that indicates
210 * that it has, and return -2 to
211 * indicate that we were told to
212 * break out of the loop.
218 * XXX - check for the DLPI primitive, which
219 * would be DL_HP_RAWDATA_IND on HP-UX
220 * if we're in raw mode?
222 ctl
.buf
= (char *)ctlbuf
;
223 ctl
.maxlen
= MAXDLBUF
;
225 if (getmsg(p
->fd
, &ctl
, &data
, &flags
) < 0) {
226 /* Don't choke when we get ptraced */
236 pcap_fmt_errmsg_for_errno(p
->errbuf
,
237 sizeof(p
->errbuf
), errno
, "getmsg");
242 bp
= (u_char
*)p
->buffer
+ p
->offset
;
246 return (pcap_process_pkts(p
, callback
, user
, cnt
, bp
, cc
));
250 pcap_inject_dlpi(pcap_t
*p
, const void *buf
, int size
)
253 struct pcap_dlpi
*pd
= p
->priv
;
257 #if defined(DLIOCRAW)
258 ret
= write(p
->fd
, buf
, size
);
260 pcap_fmt_errmsg_for_errno(p
->errbuf
, PCAP_ERRBUF_SIZE
,
264 #elif defined(DL_HP_RAWDLS)
265 if (pd
->send_fd
< 0) {
266 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
267 "send: Output FD couldn't be opened");
270 ret
= dlrawdatareq(pd
->send_fd
, buf
, size
);
272 pcap_fmt_errmsg_for_errno(p
->errbuf
, PCAP_ERRBUF_SIZE
,
277 * putmsg() returns either 0 or -1; it doesn't indicate how
278 * many bytes were written (presumably they were all written
279 * or none of them were written). OpenBSD's pcap_inject()
280 * returns the number of bytes written, so, for API compatibility,
281 * we return the number of bytes we were told to write.
284 #else /* no raw mode */
286 * XXX - this is a pain, because you might have to extract
287 * the address from the packet and use it in a DL_UNITDATA_REQ
288 * request. That would be dependent on the link-layer type.
290 * I also don't know what SAP you'd have to bind the descriptor
291 * to, or whether you'd need separate "receive" and "send" FDs,
292 * nor do I know whether you'd need different bindings for
293 * D/I/X Ethernet and 802.3, or for {FDDI,Token Ring} plus
294 * 802.2 and {FDDI,Token Ring} plus 802.2 plus SNAP.
296 * So, for now, we just return a "you can't send" indication,
297 * and leave it up to somebody with a DLPI-based system lacking
298 * both DLIOCRAW and DL_HP_RAWDLS to supply code to implement
299 * packet transmission on that system. If they do, they should
300 * send it to us - but should not send us code that assumes
301 * Ethernet; if the code doesn't work on non-Ethernet interfaces,
302 * it should check "p->linktype" and reject the send request if
303 * it's anything other than DLT_EN10MB.
305 pcap_strlcpy(p
->errbuf
, "send: Not supported on this version of this OS",
308 #endif /* raw mode */
313 #define DL_IPATM 0x12 /* ATM Classical IP interface */
321 #define A_GET_UNITS (('A'<<8)|118)
322 #endif /* A_GET_UNITS */
323 #ifndef A_PROMISCON_REQ
324 #define A_PROMISCON_REQ (('A'<<8)|121)
325 #endif /* A_PROMISCON_REQ */
326 #endif /* HAVE_SOLARIS */
329 pcap_cleanup_dlpi(pcap_t
*p
)
332 struct pcap_dlpi
*pd
= p
->priv
;
334 if (pd
->send_fd
>= 0) {
339 pcap_cleanup_live_common(p
);
343 open_dlpi_device(const char *name
, u_int
*ppa
, char *errbuf
)
357 ** Remove any "/dev/" on the front of the device.
359 cp
= strrchr(name
, '/');
361 pcap_strlcpy(dname
, name
, sizeof(dname
));
363 pcap_strlcpy(dname
, cp
+ 1, sizeof(dname
));
366 * Split the device name into a device type name and a unit number;
367 * chop off the unit number, so "dname" is just a device type name.
369 cp
= split_dname(dname
, &unit
, errbuf
);
371 return (PCAP_ERROR_NO_SUCH_DEVICE
);
375 * Use "/dev/dlpi" as the device.
377 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that
378 * the "dl_mjr_num" field is for the "major number of interface
379 * driver"; that's the major of "/dev/dlpi" on the system on
380 * which I tried this, but there may be DLPI devices that
381 * use a different driver, in which case we may need to
382 * search "/dev" for the appropriate device with that major
383 * device number, rather than hardwiring "/dev/dlpi".
386 if ((fd
= open(cp
, O_RDWR
)) < 0) {
387 if (errno
== EPERM
|| errno
== EACCES
)
388 status
= PCAP_ERROR_PERM_DENIED
;
391 pcap_fmt_errmsg_for_errno(errbuf
, PCAP_ERRBUF_SIZE
,
397 * Get a table of all PPAs for that device, and search that
398 * table for the specified device type name and unit number.
400 status
= get_dlpi_ppa(fd
, dname
, unit
, ppa
, errbuf
);
407 * If the device name begins with "/", assume it begins with
408 * the pathname of the directory containing the device to open;
409 * otherwise, concatenate the device directory name and the
413 pcap_strlcpy(dname
, name
, sizeof(dname
));
415 pcap_snprintf(dname
, sizeof(dname
), "%s/%s", PCAP_DEV_PREFIX
,
419 * Get the unit number, and a pointer to the end of the device
422 cp
= split_dname(dname
, ppa
, errbuf
);
424 return (PCAP_ERROR_NO_SUCH_DEVICE
);
427 * Make a copy of the device pathname, and then remove the unit
428 * number from the device pathname.
430 pcap_strlcpy(dname2
, dname
, sizeof(dname
));
433 /* Try device without unit number */
434 if ((fd
= open(dname
, O_RDWR
)) < 0) {
435 if (errno
!= ENOENT
) {
436 if (errno
== EPERM
|| errno
== EACCES
)
437 status
= PCAP_ERROR_PERM_DENIED
;
440 pcap_fmt_errmsg_for_errno(errbuf
, PCAP_ERRBUF_SIZE
,
445 /* Try again with unit number */
446 if ((fd
= open(dname2
, O_RDWR
)) < 0) {
447 if (errno
== ENOENT
) {
448 status
= PCAP_ERROR_NO_SUCH_DEVICE
;
451 * We provide an error message even
452 * for this error, for diagnostic
453 * purposes (so that, for example,
454 * the app can show the message if the
457 * In it, we just report "No DLPI device
458 * found" with the device name, so people
459 * don't get confused and think, for example,
460 * that if they can't capture on "lo0"
461 * on Solaris prior to Solaris 11 the fix
462 * is to change libpcap (or the application
463 * that uses it) to look for something other
464 * than "/dev/lo0", as the fix is to use
465 * Solaris 11 or some operating system
466 * other than Solaris - you just *can't*
467 * capture on a loopback interface
468 * on Solaris prior to Solaris 11, the lack
469 * of a DLPI device for the loopback
470 * interface is just a symptom of that
473 pcap_snprintf(errbuf
, PCAP_ERRBUF_SIZE
,
474 "%s: No DLPI device found", name
);
476 if (errno
== EPERM
|| errno
== EACCES
)
477 status
= PCAP_ERROR_PERM_DENIED
;
480 pcap_fmt_errmsg_for_errno(errbuf
,
481 PCAP_ERRBUF_SIZE
, errno
, "%s", dname2
);
485 /* XXX Assume unit zero */
493 pcap_activate_dlpi(pcap_t
*p
)
496 struct pcap_dlpi
*pd
= p
->priv
;
504 register dl_info_ack_t
*infop
;
505 #ifdef HAVE_SYS_BUFMOD_H
508 char release
[GET_RELEASE_BUFSIZE
];
509 bpf_u_int32 osmajor
, osminor
, osmicro
;
512 bpf_u_int32 buf
[MAXDLBUF
];
514 p
->fd
= open_dlpi_device(p
->opt
.device
, &ppa
, p
->errbuf
);
522 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
523 * receiving packets on the same descriptor - you need separate
524 * descriptors for sending and receiving, bound to different SAPs.
526 * If the open fails, we just leave -1 in "pd->send_fd" and reject
527 * attempts to send packets, just as if, in pcap-bpf.c, we fail
528 * to open the BPF device for reading and writing, we just try
529 * to open it for reading only and, if that succeeds, just let
530 * the send attempts fail.
532 pd
->send_fd
= open("/dev/dlpi", O_RDWR
);
536 ** Attach if "style 2" provider
538 if (dlinforeq(p
->fd
, p
->errbuf
) < 0 ||
539 dlinfoack(p
->fd
, (char *)buf
, p
->errbuf
) < 0) {
543 infop
= &(MAKE_DL_PRIMITIVES(buf
))->info_ack
;
545 if (infop
->dl_mac_type
== DL_IPATM
)
548 if (infop
->dl_provider_style
== DL_STYLE2
) {
549 retv
= dl_doattach(p
->fd
, ppa
, p
->errbuf
);
555 if (pd
->send_fd
>= 0) {
556 retv
= dl_doattach(pd
->send_fd
, ppa
, p
->errbuf
);
567 * This device exists, but we don't support monitor mode
568 * any platforms that support DLPI.
570 status
= PCAP_ERROR_RFMON_NOTSUP
;
574 #ifdef HAVE_DL_PASSIVE_REQ_T
576 * Enable Passive mode to be able to capture on aggregated link.
577 * Not supported in all Solaris versions.
579 dlpassive(p
->fd
, p
->errbuf
);
582 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
583 ** skip if using SINIX)
585 #if !defined(HAVE_HPUX9) && !defined(HAVE_HPUX10_20_OR_LATER) && !defined(sinix)
589 ** According to IBM's AIX Support Line, the dl_sap value
590 ** should not be less than 0x600 (1536) for standard Ethernet.
591 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
592 ** format or invalid" - errors if we use 1537 on the "tr0"
593 ** device, which, given that its name starts with "tr" and that
594 ** it's IBM, probably means a Token Ring device. (Perhaps we
595 ** need to use 1537 on "/dev/dlpi/en" because that device is for
596 ** D/I/X Ethernet, the "SAP" is actually an Ethernet type, and
597 ** it rejects invalid Ethernet types.)
599 ** So if 1537 fails, we try 2, as Hyung Sik Yoon of IBM Korea
600 ** says that works on Token Ring (he says that 0 does *not*
601 ** work; perhaps that's considered an invalid LLC SAP value - I
602 ** assume the SAP value in a DLPI bind is an LLC SAP for network
603 ** types that use 802.2 LLC).
605 if ((dlbindreq(p
->fd
, 1537, p
->errbuf
) < 0 &&
606 dlbindreq(p
->fd
, 2, p
->errbuf
) < 0) ||
607 dlbindack(p
->fd
, (char *)buf
, p
->errbuf
, NULL
) < 0) {
611 #elif defined(DL_HP_RAWDLS)
613 ** HP-UX 10.0x and 10.1x.
615 if (dl_dohpuxbind(p
->fd
, p
->errbuf
) < 0) {
619 if (pd
->send_fd
>= 0) {
621 ** XXX - if this fails, just close send_fd and
622 ** set it to -1, so that you can't send but can
625 if (dl_dohpuxbind(pd
->send_fd
, p
->errbuf
) < 0) {
630 #else /* neither AIX nor HP-UX */
632 ** Not Sinix, and neither AIX nor HP-UX - Solaris, and any other
635 if (dlbindreq(p
->fd
, 0, p
->errbuf
) < 0 ||
636 dlbindack(p
->fd
, (char *)buf
, p
->errbuf
, NULL
) < 0) {
640 #endif /* AIX vs. HP-UX vs. other */
641 #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
644 * Turn a negative snapshot value (invalid), a snapshot value of
645 * 0 (unspecified), or a value bigger than the normal maximum
646 * value, into the maximum allowed value.
648 * If some application really *needs* a bigger snapshot
649 * length, we should just increase MAXIMUM_SNAPLEN.
651 if (p
->snapshot
<= 0 || p
->snapshot
> MAXIMUM_SNAPLEN
)
652 p
->snapshot
= MAXIMUM_SNAPLEN
;
657 ** Have to turn on some special ATM promiscuous mode
659 ** Do *NOT* turn regular promiscuous mode on; it doesn't
660 ** help, and may break things.
662 if (strioctl(p
->fd
, A_PROMISCON_REQ
, 0, NULL
) < 0) {
664 pcap_fmt_errmsg_for_errno(p
->errbuf
, PCAP_ERRBUF_SIZE
,
665 errno
, "A_PROMISCON_REQ");
670 if (p
->opt
.promisc
) {
672 ** Enable promiscuous (not necessary on send FD)
674 retv
= dlpromiscon(p
, DL_PROMISC_PHYS
);
676 if (retv
== PCAP_ERROR_PERM_DENIED
)
677 status
= PCAP_ERROR_PROMISC_PERM_DENIED
;
684 ** Try to enable multicast (you would have thought
685 ** promiscuous would be sufficient). (Skip if using
686 ** HP-UX or SINIX) (Not necessary on send FD)
688 #if !defined(__hpux) && !defined(sinix)
689 retv
= dlpromiscon(p
, DL_PROMISC_MULTI
);
691 status
= PCAP_WARNING
;
695 ** Try to enable SAP promiscuity (when not in promiscuous mode
696 ** when using HP-UX, when not doing SunATM on Solaris, and never
697 ** under SINIX) (Not necessary on send FD)
701 /* HP-UX - only do this when not in promiscuous mode */
702 if (!p
->opt
.promisc
) {
703 #elif defined(HAVE_SOLARIS)
704 /* Solaris - don't do this on SunATM devices */
707 /* Everything else (except for SINIX) - always do this */
710 retv
= dlpromiscon(p
, DL_PROMISC_SAP
);
712 if (p
->opt
.promisc
) {
714 * Not fatal, since the DL_PROMISC_PHYS mode
717 * Report it as a warning, however.
719 status
= PCAP_WARNING
;
732 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
733 ** promiscuous options.
735 #if defined(HAVE_HPUX9) || defined(HAVE_HPUX10_20_OR_LATER)
736 if (dl_dohpuxbind(p
->fd
, p
->errbuf
) < 0) {
741 ** We don't set promiscuous mode on the send FD, but we'll defer
742 ** binding it anyway, just to keep the HP-UX 9/10.20 or later
745 if (pd
->send_fd
>= 0) {
747 ** XXX - if this fails, just close send_fd and
748 ** set it to -1, so that you can't send but can
751 if (dl_dohpuxbind(pd
->send_fd
, p
->errbuf
) < 0) {
759 ** Determine link type
760 ** XXX - get SAP length and address length as well, for use
761 ** when sending packets.
763 if (dlinforeq(p
->fd
, p
->errbuf
) < 0 ||
764 dlinfoack(p
->fd
, (char *)buf
, p
->errbuf
) < 0) {
769 infop
= &(MAKE_DL_PRIMITIVES(buf
))->info_ack
;
770 if (pcap_process_mactype(p
, infop
->dl_mac_type
) != 0) {
777 ** This is a non standard SunOS hack to get the full raw link-layer
780 if (strioctl(p
->fd
, DLIOCRAW
, 0, NULL
) < 0) {
782 pcap_fmt_errmsg_for_errno(p
->errbuf
, PCAP_ERRBUF_SIZE
,
788 #ifdef HAVE_SYS_BUFMOD_H
792 ** There is a bug in bufmod(7). When dealing with messages of
793 ** less than snaplen size it strips data from the beginning not
796 ** This bug is fixed in 5.3.2. Also, there is a patch available.
797 ** Ask for bugid 1149065.
800 get_release(release
, sizeof (release
), &osmajor
, &osminor
, &osmicro
);
801 if (osmajor
== 5 && (osminor
<= 2 || (osminor
== 3 && osmicro
< 2)) &&
802 getenv("BUFMOD_FIXED") == NULL
) {
803 pcap_snprintf(p
->errbuf
, PCAP_ERRBUF_SIZE
,
804 "WARNING: bufmod is broken in SunOS %s; ignoring snaplen.",
807 status
= PCAP_WARNING
;
811 /* Push and configure bufmod. */
812 if (pcap_conf_bufmod(p
, ss
) != 0) {
819 ** As the last operation flush the read side.
821 if (ioctl(p
->fd
, I_FLUSH
, FLUSHR
) != 0) {
823 pcap_fmt_errmsg_for_errno(p
->errbuf
, PCAP_ERRBUF_SIZE
,
828 /* Allocate data buffer. */
829 if (pcap_alloc_databuf(p
) != 0) {
837 * "p->fd" is an FD for a STREAMS device, so "select()" and
838 * "poll()" should work on it.
840 p
->selectable_fd
= p
->fd
;
842 p
->read_op
= pcap_read_dlpi
;
843 p
->inject_op
= pcap_inject_dlpi
;
844 p
->setfilter_op
= install_bpf_program
; /* no kernel filtering */
845 p
->setdirection_op
= NULL
; /* Not implemented.*/
846 p
->set_datalink_op
= NULL
; /* can't change data link type */
847 p
->getnonblock_op
= pcap_getnonblock_fd
;
848 p
->setnonblock_op
= pcap_setnonblock_fd
;
849 p
->stats_op
= pcap_stats_dlpi
;
850 p
->cleanup_op
= pcap_cleanup_dlpi
;
854 pcap_cleanup_dlpi(p
);
859 * Split a device name into a device type name and a unit number;
860 * return the a pointer to the beginning of the unit number, which
861 * is the end of the device type name, and set "*unitp" to the unit
864 * Returns NULL on error, and fills "ebuf" with an error message.
867 split_dname(char *device
, u_int
*unitp
, char *ebuf
)
874 * Look for a number at the end of the device name string.
876 cp
= device
+ strlen(device
) - 1;
877 if (*cp
< '0' || *cp
> '9') {
878 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s missing unit number",
883 /* Digits at end of string are unit number */
884 while (cp
-1 >= device
&& *(cp
-1) >= '0' && *(cp
-1) <= '9')
888 unit
= strtol(cp
, &eos
, 10);
890 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s bad unit number", device
);
893 if (errno
== ERANGE
|| unit
> INT_MAX
) {
894 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number too large",
899 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "%s unit number is negative",
903 *unitp
= (u_int
)unit
;
908 dl_doattach(int fd
, int ppa
, char *ebuf
)
911 bpf_u_int32 buf
[MAXDLBUF
];
914 req
.dl_primitive
= DL_ATTACH_REQ
;
916 if (send_request(fd
, (char *)&req
, sizeof(req
), "attach", ebuf
) < 0)
919 err
= dlokack(fd
, "attach", (char *)buf
, ebuf
);
927 dl_dohpuxbind(int fd
, char *ebuf
)
931 bpf_u_int32 buf
[MAXDLBUF
];
934 * XXX - we start at 22 because we used to use only 22, but
935 * that was just because that was the value used in some
936 * sample code from HP. With what value *should* we start?
937 * Does it matter, given that we're enabling SAP promiscuity
942 if (dlbindreq(fd
, hpsap
, ebuf
) < 0)
944 if (dlbindack(fd
, (char *)buf
, ebuf
, &uerror
) >= 0)
947 * For any error other than a UNIX EBUSY, give up.
949 if (uerror
!= EBUSY
) {
951 * dlbindack() has already filled in ebuf for
958 * For EBUSY, try the next SAP value; that means that
959 * somebody else is using that SAP. Clear ebuf so
960 * that application doesn't report the "Device busy"
961 * error as a warning.
967 "All SAPs from 22 through 100 are in use",
976 #define STRINGIFY(n) #n
979 dlpromiscon(pcap_t
*p
, bpf_u_int32 level
)
981 dl_promiscon_req_t req
;
982 bpf_u_int32 buf
[MAXDLBUF
];
985 req
.dl_primitive
= DL_PROMISCON_REQ
;
986 req
.dl_level
= level
;
987 if (send_request(p
->fd
, (char *)&req
, sizeof(req
), "promiscon",
990 err
= dlokack(p
->fd
, "promiscon" STRINGIFY(level
), (char *)buf
,
998 * Not all interfaces are DLPI interfaces, and thus not all interfaces
999 * can be opened with DLPI (for example, the loopback interface is not
1000 * a DLPI interface on Solaris prior to Solaris 11), so try to open
1001 * the specified interface; return 0 if we fail with PCAP_ERROR_NO_SUCH_DEVICE
1005 is_dlpi_interface(const char *name
)
1009 char errbuf
[PCAP_ERRBUF_SIZE
];
1011 fd
= open_dlpi_device(name
, &ppa
, errbuf
);
1014 * Error - was it PCAP_ERROR_NO_SUCH_DEVICE?
1016 if (fd
== PCAP_ERROR_NO_SUCH_DEVICE
) {
1018 * Yes, so we can't open this because it's
1019 * not a DLPI interface.
1024 * No, so, in the case where there's a single DLPI
1025 * device for all interfaces of this type ("style
1026 * 2" providers?), we don't know whether it's a DLPI
1027 * interface or not, as we didn't try an attach.
1028 * Say it is a DLPI device, so that the user can at
1029 * least try to open it and report the error (which
1030 * is probably "you don't have permission to open that
1031 * DLPI device"; reporting those interfaces means
1032 * users will ask "why am I getting a permissions error
1033 * when I try to capture" rather than "why am I not
1034 * seeing any interfaces", making the underlying problem
1048 get_if_flags(const char *name _U_
, bpf_u_int32
*flags _U_
, char *errbuf _U_
)
1051 * Nothing we can do other than mark loopback devices as "the
1052 * connected/disconnected status doesn't apply".
1054 * XXX - on Solaris, can we do what the dladm command does,
1055 * i.e. get a connected/disconnected indication from a kstat?
1056 * (Note that you can also get the link speed, and possibly
1057 * other information, from a kstat as well.)
1059 if (*flags
& PCAP_IF_LOOPBACK
) {
1061 * Loopback devices aren't wireless, and "connected"/
1062 * "disconnected" doesn't apply to them.
1064 *flags
|= PCAP_IF_CONNECTION_STATUS_NOT_APPLICABLE
;
1071 pcap_platform_finddevs(pcap_if_list_t
*devlistp
, char *errbuf
)
1077 char pad
[516]; /* XXX - must be at least 513; is 516
1085 * Get the list of regular interfaces first.
1087 if (pcap_findalldevs_interfaces(devlistp
, errbuf
, is_dlpi_interface
,
1088 get_if_flags
) == -1)
1089 return (-1); /* failure */
1093 * We may have to do special magic to get ATM devices.
1095 if ((fd
= open("/dev/ba", O_RDWR
)) < 0) {
1097 * We couldn't open the "ba" device.
1098 * For now, just give up; perhaps we should
1099 * return an error if the problem is neither
1100 * a "that device doesn't exist" error (ENOENT,
1101 * ENXIO, etc.) or a "you're not allowed to do
1102 * that" error (EPERM, EACCES).
1107 if (strioctl(fd
, A_GET_UNITS
, sizeof(buf
), (char *)&buf
) < 0) {
1108 pcap_fmt_errmsg_for_errno(errbuf
, PCAP_ERRBUF_SIZE
,
1109 errno
, "A_GET_UNITS");
1112 for (i
= 0; i
< buf
.nunits
; i
++) {
1113 pcap_snprintf(baname
, sizeof baname
, "ba%u", i
);
1115 * XXX - is there a notion of "up" and "running"?
1116 * And is there a way to determine whether the
1117 * interface is plugged into a network?
1119 if (add_dev(devlistp
, baname
, 0, NULL
, errbuf
) == NULL
)
1128 send_request(int fd
, char *ptr
, int len
, char *what
, char *ebuf
)
1138 if (putmsg(fd
, &ctl
, (struct strbuf
*) NULL
, flags
) < 0) {
1139 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1140 errno
, "send_request: putmsg \"%s\"", what
);
1147 recv_ack(int fd
, int size
, const char *what
, char *bufp
, char *ebuf
, int *uerror
)
1149 union DL_primitives
*dlp
;
1152 char errmsgbuf
[PCAP_ERRBUF_SIZE
];
1156 * Clear out "*uerror", so it's only set for DL_ERROR_ACK/DL_SYSERR,
1157 * making that the only place where EBUSY is treated specially.
1162 ctl
.maxlen
= MAXDLBUF
;
1167 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1168 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1169 errno
, "recv_ack: %s getmsg", what
);
1170 return (PCAP_ERROR
);
1173 dlp
= MAKE_DL_PRIMITIVES(ctl
.buf
);
1174 switch (dlp
->dl_primitive
) {
1179 #ifdef DL_HP_PPA_ACK
1186 switch (dlp
->error_ack
.dl_errno
) {
1190 *uerror
= dlp
->error_ack
.dl_unix_errno
;
1191 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1192 dlp
->error_ack
.dl_unix_errno
,
1193 "recv_ack: %s: UNIX error", what
);
1194 if (dlp
->error_ack
.dl_unix_errno
== EPERM
||
1195 dlp
->error_ack
.dl_unix_errno
== EACCES
)
1196 return (PCAP_ERROR_PERM_DENIED
);
1200 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1201 "recv_ack: %s: %s", what
,
1202 dlstrerror(errmsgbuf
, sizeof (errmsgbuf
), dlp
->error_ack
.dl_errno
));
1203 if (dlp
->error_ack
.dl_errno
== DL_BADPPA
)
1204 return (PCAP_ERROR_NO_SUCH_DEVICE
);
1205 else if (dlp
->error_ack
.dl_errno
== DL_ACCESS
)
1206 return (PCAP_ERROR_PERM_DENIED
);
1209 return (PCAP_ERROR
);
1212 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1213 "recv_ack: %s: Unexpected primitive ack %s",
1214 what
, dlprim(dlprimbuf
, sizeof (dlprimbuf
), dlp
->dl_primitive
));
1215 return (PCAP_ERROR
);
1218 if (ctl
.len
< size
) {
1219 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1220 "recv_ack: %s: Ack too small (%d < %d)",
1221 what
, ctl
.len
, size
);
1222 return (PCAP_ERROR
);
1228 dlstrerror(char *errbuf
, size_t errbufsize
, bpf_u_int32 dl_errno
)
1233 return ("Improper permissions for request");
1236 return ("DLSAP addr in improper format or invalid");
1239 return ("Seq number not from outstand DL_CONN_IND");
1242 return ("User data exceeded provider limit");
1245 #ifdef HAVE_DEV_DLPI
1247 * With a single "/dev/dlpi" device used for all
1248 * DLPI providers, PPAs have nothing to do with
1251 return ("Specified PPA was invalid");
1254 * We have separate devices for separate devices;
1255 * the PPA is just the unit number.
1257 return ("Specified PPA (device unit) was invalid");
1261 return ("Primitive received not known by provider");
1263 case DL_BADQOSPARAM
:
1264 return ("QOS parameters contained invalid values");
1267 return ("QOS structure type is unknown/unsupported");
1270 return ("Bad LSAP selector");
1273 return ("Token used not an active stream");
1276 return ("Attempted second bind with dl_max_conind");
1279 return ("Physical link initialization failed");
1282 return ("Provider couldn't allocate alternate address");
1285 return ("Physical link not initialized");
1288 return ("Primitive issued in improper state");
1291 return ("UNIX system error occurred");
1293 case DL_UNSUPPORTED
:
1294 return ("Requested service not supplied by provider");
1296 case DL_UNDELIVERABLE
:
1297 return ("Previous data unit could not be delivered");
1299 case DL_NOTSUPPORTED
:
1300 return ("Primitive is known but not supported");
1303 return ("Limit exceeded");
1306 return ("Promiscuous mode not enabled");
1309 return ("Other streams for PPA in post-attached");
1312 return ("Automatic handling XID&TEST not supported");
1315 return ("Automatic handling of XID not supported");
1318 return ("Automatic handling of TEST not supported");
1321 return ("Automatic handling of XID response");
1324 return ("Automatic handling of TEST response");
1327 return ("Pending outstanding connect indications");
1330 pcap_snprintf(errbuf
, errbufsize
, "Error %02x", dl_errno
);
1336 dlprim(char *primbuf
, size_t primbufsize
, bpf_u_int32 prim
)
1341 return ("DL_INFO_REQ");
1344 return ("DL_INFO_ACK");
1347 return ("DL_ATTACH_REQ");
1350 return ("DL_DETACH_REQ");
1353 return ("DL_BIND_REQ");
1356 return ("DL_BIND_ACK");
1359 return ("DL_UNBIND_REQ");
1362 return ("DL_OK_ACK");
1365 return ("DL_ERROR_ACK");
1367 case DL_SUBS_BIND_REQ
:
1368 return ("DL_SUBS_BIND_REQ");
1370 case DL_SUBS_BIND_ACK
:
1371 return ("DL_SUBS_BIND_ACK");
1373 case DL_UNITDATA_REQ
:
1374 return ("DL_UNITDATA_REQ");
1376 case DL_UNITDATA_IND
:
1377 return ("DL_UNITDATA_IND");
1379 case DL_UDERROR_IND
:
1380 return ("DL_UDERROR_IND");
1383 return ("DL_UDQOS_REQ");
1385 case DL_CONNECT_REQ
:
1386 return ("DL_CONNECT_REQ");
1388 case DL_CONNECT_IND
:
1389 return ("DL_CONNECT_IND");
1391 case DL_CONNECT_RES
:
1392 return ("DL_CONNECT_RES");
1394 case DL_CONNECT_CON
:
1395 return ("DL_CONNECT_CON");
1398 return ("DL_TOKEN_REQ");
1401 return ("DL_TOKEN_ACK");
1403 case DL_DISCONNECT_REQ
:
1404 return ("DL_DISCONNECT_REQ");
1406 case DL_DISCONNECT_IND
:
1407 return ("DL_DISCONNECT_IND");
1410 return ("DL_RESET_REQ");
1413 return ("DL_RESET_IND");
1416 return ("DL_RESET_RES");
1419 return ("DL_RESET_CON");
1422 pcap_snprintf(primbuf
, primbufsize
, "unknown primitive 0x%x",
1429 dlbindreq(int fd
, bpf_u_int32 sap
, char *ebuf
)
1434 memset((char *)&req
, 0, sizeof(req
));
1435 req
.dl_primitive
= DL_BIND_REQ
;
1436 /* XXX - what if neither of these are defined? */
1437 #if defined(DL_HP_RAWDLS)
1438 req
.dl_max_conind
= 1; /* XXX magic number */
1439 req
.dl_service_mode
= DL_HP_RAWDLS
;
1440 #elif defined(DL_CLDLS)
1441 req
.dl_service_mode
= DL_CLDLS
;
1445 return (send_request(fd
, (char *)&req
, sizeof(req
), "bind", ebuf
));
1449 dlbindack(int fd
, char *bufp
, char *ebuf
, int *uerror
)
1452 return (recv_ack(fd
, DL_BIND_ACK_SIZE
, "bind", bufp
, ebuf
, uerror
));
1456 dlokack(int fd
, const char *what
, char *bufp
, char *ebuf
)
1459 return (recv_ack(fd
, DL_OK_ACK_SIZE
, what
, bufp
, ebuf
, NULL
));
1464 dlinforeq(int fd
, char *ebuf
)
1468 req
.dl_primitive
= DL_INFO_REQ
;
1470 return (send_request(fd
, (char *)&req
, sizeof(req
), "info", ebuf
));
1474 dlinfoack(int fd
, char *bufp
, char *ebuf
)
1477 return (recv_ack(fd
, DL_INFO_ACK_SIZE
, "info", bufp
, ebuf
, NULL
));
1480 #ifdef HAVE_DL_PASSIVE_REQ_T
1482 * Enable DLPI passive mode. We do not care if this request fails, as this
1483 * indicates the underlying DLPI device does not support link aggregation.
1486 dlpassive(int fd
, char *ebuf
)
1488 dl_passive_req_t req
;
1489 bpf_u_int32 buf
[MAXDLBUF
];
1491 req
.dl_primitive
= DL_PASSIVE_REQ
;
1493 if (send_request(fd
, (char *)&req
, sizeof(req
), "dlpassive", ebuf
) == 0)
1494 (void) dlokack(fd
, "dlpassive", (char *)buf
, ebuf
);
1500 * There's an ack *if* there's an error.
1503 dlrawdatareq(int fd
, const u_char
*datap
, int datalen
)
1505 struct strbuf ctl
, data
;
1506 long buf
[MAXDLBUF
]; /* XXX - char? */
1507 union DL_primitives
*dlp
;
1510 dlp
= MAKE_DL_PRIMITIVES(buf
);
1512 dlp
->dl_primitive
= DL_HP_RAWDATA_REQ
;
1513 dlen
= DL_HP_RAWDATA_REQ_SIZE
;
1516 * HP's documentation doesn't appear to show us supplying any
1517 * address pointed to by the control part of the message.
1518 * I think that's what raw mode means - you just send the raw
1519 * packet, you don't specify where to send it to, as that's
1520 * implied by the destination address.
1524 ctl
.buf
= (void *)buf
;
1528 data
.buf
= (void *)datap
;
1530 return (putmsg(fd
, &ctl
, &data
, 0));
1532 #endif /* DL_HP_RAWDLS */
1534 #if defined(HAVE_SOLARIS) && defined(HAVE_SYS_BUFMOD_H)
1536 get_release(char *buf
, size_t bufsize
, bpf_u_int32
*majorp
,
1537 bpf_u_int32
*minorp
, bpf_u_int32
*microp
)
1544 if (sysinfo(SI_RELEASE
, buf
, bufsize
) < 0) {
1545 pcap_strlcpy(buf
, "?", bufsize
);
1549 if (!isdigit((unsigned char)*cp
))
1551 *majorp
= strtol(cp
, &cp
, 10);
1554 *minorp
= strtol(cp
, &cp
, 10);
1557 *microp
= strtol(cp
, &cp
, 10);
1561 #ifdef DL_HP_PPA_REQ
1563 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1568 * Determine ppa number that specifies ifname.
1570 * If the "dl_hp_ppa_info_t" doesn't have a "dl_module_id_1" member,
1571 * the code that's used here is the old code for HP-UX 10.x.
1573 * However, HP-UX 10.20, at least, appears to have such a member
1574 * in its "dl_hp_ppa_info_t" structure, so the new code is used.
1575 * The new code didn't work on an old 10.20 system on which Rick
1576 * Jones of HP tried it, but with later patches installed, it
1577 * worked - it appears that the older system had those members but
1578 * didn't put anything in them, so, if the search by name fails, we
1579 * do the old search.
1581 * Rick suggests that making sure your system is "up on the latest
1582 * lancommon/DLPI/driver patches" is probably a good idea; it'd fix
1583 * that problem, as well as allowing libpcap to see packets sent
1584 * from the system on which the libpcap application is being run.
1585 * (On 10.20, in addition to getting the latest patches, you need
1586 * to turn the kernel "lanc_outbound_promisc_flag" flag on with ADB;
1587 * a posting to "comp.sys.hp.hpux" at
1589 * http://www.deja.com/[ST_rn=ps]/getdoc.xp?AN=558092266
1591 * says that, to see the machine's outgoing traffic, you'd need to
1592 * apply the right patches to your system, and also set that variable
1595 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1597 * which could be put in, for example, "/sbin/init.d/lan".
1599 * Setting the variable is not necessary on HP-UX 11.x.
1602 get_dlpi_ppa(register int fd
, register const char *device
, register u_int unit
,
1603 u_int
*ppa
, register char *ebuf
)
1605 register dl_hp_ppa_ack_t
*ap
;
1606 register dl_hp_ppa_info_t
*ipstart
, *ip
;
1609 register u_long majdev
;
1610 struct stat statbuf
;
1611 dl_hp_ppa_req_t req
;
1614 dl_hp_ppa_ack_t
*dlp
;
1618 memset((char *)&req
, 0, sizeof(req
));
1619 req
.dl_primitive
= DL_HP_PPA_REQ
;
1621 memset((char *)buf
, 0, sizeof(buf
));
1622 if (send_request(fd
, (char *)&req
, sizeof(req
), "hpppa", ebuf
) < 0)
1623 return (PCAP_ERROR
);
1625 ctl
.maxlen
= DL_HP_PPA_ACK_SIZE
;
1627 ctl
.buf
= (char *)buf
;
1631 * DLPI may return a big chunk of data for a DL_HP_PPA_REQ. The normal
1632 * recv_ack will fail because it set the maxlen to MAXDLBUF (8192)
1633 * which is NOT big enough for a DL_HP_PPA_REQ.
1635 * This causes libpcap applications to fail on a system with HP-APA
1638 * To figure out how big the returned data is, we first call getmsg
1639 * to get the small head and peek at the head to get the actual data
1640 * length, and then issue another getmsg to get the actual PPA data.
1642 /* get the head first */
1643 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1644 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1645 errno
, "get_dlpi_ppa: hpppa getmsg");
1646 return (PCAP_ERROR
);
1648 if (ctl
.len
== -1) {
1649 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1650 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1651 return (PCAP_ERROR
);
1654 dlp
= (dl_hp_ppa_ack_t
*)ctl
.buf
;
1655 if (dlp
->dl_primitive
!= DL_HP_PPA_ACK
) {
1656 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1657 "get_dlpi_ppa: hpppa unexpected primitive ack 0x%x",
1658 (bpf_u_int32
)dlp
->dl_primitive
);
1659 return (PCAP_ERROR
);
1662 if ((size_t)ctl
.len
< DL_HP_PPA_ACK_SIZE
) {
1663 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1664 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1665 ctl
.len
, (unsigned long)DL_HP_PPA_ACK_SIZE
);
1666 return (PCAP_ERROR
);
1669 /* allocate buffer */
1670 if ((ppa_data_buf
= (char *)malloc(dlp
->dl_length
)) == NULL
) {
1671 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1672 errno
, "get_dlpi_ppa: hpppa malloc");
1673 return (PCAP_ERROR
);
1675 ctl
.maxlen
= dlp
->dl_length
;
1677 ctl
.buf
= (char *)ppa_data_buf
;
1679 if (getmsg(fd
, &ctl
, (struct strbuf
*)NULL
, &flags
) < 0) {
1680 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1681 errno
, "get_dlpi_ppa: hpppa getmsg");
1683 return (PCAP_ERROR
);
1685 if (ctl
.len
== -1) {
1686 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1687 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1688 return (PCAP_ERROR
);
1690 if ((u_int
)ctl
.len
< dlp
->dl_length
) {
1691 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1692 "get_dlpi_ppa: hpppa ack too small (%d < %lu)",
1693 ctl
.len
, (unsigned long)dlp
->dl_length
);
1695 return (PCAP_ERROR
);
1698 ap
= (dl_hp_ppa_ack_t
*)buf
;
1699 ipstart
= (dl_hp_ppa_info_t
*)ppa_data_buf
;
1702 #ifdef HAVE_DL_HP_PPA_INFO_T_DL_MODULE_ID_1
1704 * The "dl_hp_ppa_info_t" structure has a "dl_module_id_1"
1705 * member that should, in theory, contain the part of the
1706 * name for the device that comes before the unit number,
1707 * and should also have a "dl_module_id_2" member that may
1708 * contain an alternate name (e.g., I think Ethernet devices
1709 * have both "lan", for "lanN", and "snap", for "snapN", with
1710 * the former being for Ethernet packets and the latter being
1711 * for 802.3/802.2 packets).
1713 * Search for the device that has the specified name and
1716 for (i
= 0; i
< ap
->dl_count
; i
++) {
1717 if ((strcmp((const char *)ip
->dl_module_id_1
, device
) == 0 ||
1718 strcmp((const char *)ip
->dl_module_id_2
, device
) == 0) &&
1719 ip
->dl_instance_num
== unit
)
1722 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1726 * We don't have that member, so the search is impossible; make it
1727 * look as if the search failed.
1732 if (i
== ap
->dl_count
) {
1734 * Well, we didn't, or can't, find the device by name.
1736 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1737 * "dl_module_id_2" fields in the "dl_hp_ppa_info_t",
1738 * doesn't seem to fill them in unless the system is
1739 * at a reasonably up-to-date patch level.
1741 * Older HP-UX 10.x systems might not have those fields
1744 * Therefore, we'll search for the entry with the major
1745 * device number of a device with the name "/dev/<dev><unit>",
1746 * if such a device exists, as the old code did.
1748 pcap_snprintf(dname
, sizeof(dname
), "/dev/%s%u", device
, unit
);
1749 if (stat(dname
, &statbuf
) < 0) {
1750 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1751 errno
, "stat: %s", dname
);
1752 return (PCAP_ERROR
);
1754 majdev
= major(statbuf
.st_rdev
);
1758 for (i
= 0; i
< ap
->dl_count
; i
++) {
1759 if (ip
->dl_mjr_num
== majdev
&&
1760 ip
->dl_instance_num
== unit
)
1763 ip
= (dl_hp_ppa_info_t
*)((u_char
*)ipstart
+ ip
->dl_next_offset
);
1766 if (i
== ap
->dl_count
) {
1767 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1768 "can't find /dev/dlpi PPA for %s%u", device
, unit
);
1769 return (PCAP_ERROR_NO_SUCH_DEVICE
);
1771 if (ip
->dl_hdw_state
== HDW_DEAD
) {
1772 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1773 "%s%d: hardware state: DOWN\n", device
, unit
);
1775 return (PCAP_ERROR
);
1785 * Under HP-UX 9, there is no good way to determine the ppa.
1786 * So punt and read it from /dev/kmem.
1788 static struct nlist nl
[] = {
1794 static char path_vmunix
[] = "/hp-ux";
1796 /* Determine ppa number that specifies ifname */
1798 get_dlpi_ppa(register int fd
, register const char *ifname
, register u_int unit
,
1799 u_int
*ppa
, register char *ebuf
)
1801 register const char *cp
;
1805 char if_name
[sizeof(ifnet
.if_name
) + 1];
1807 cp
= strrchr(ifname
, '/');
1810 if (nlist(path_vmunix
, &nl
) < 0) {
1811 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "nlist %s failed",
1813 return (PCAP_ERROR
);
1815 if (nl
[NL_IFNET
].n_value
== 0) {
1816 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
,
1817 "could't find %s kernel symbol",
1818 nl
[NL_IFNET
].n_name
);
1819 return (PCAP_ERROR
);
1821 kd
= open("/dev/kmem", O_RDONLY
);
1823 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1824 errno
, "kmem open");
1825 return (PCAP_ERROR
);
1827 if (dlpi_kread(kd
, nl
[NL_IFNET
].n_value
,
1828 &addr
, sizeof(addr
), ebuf
) < 0) {
1830 return (PCAP_ERROR
);
1832 for (; addr
!= NULL
; addr
= ifnet
.if_next
) {
1833 if (dlpi_kread(kd
, (off_t
)addr
,
1834 &ifnet
, sizeof(ifnet
), ebuf
) < 0 ||
1835 dlpi_kread(kd
, (off_t
)ifnet
.if_name
,
1836 if_name
, sizeof(ifnet
.if_name
), ebuf
) < 0) {
1838 return (PCAP_ERROR
);
1840 if_name
[sizeof(ifnet
.if_name
)] = '\0';
1841 if (strcmp(if_name
, ifname
) == 0 && ifnet
.if_unit
== unit
) {
1842 *ppa
= ifnet
.if_index
;
1847 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "Can't find %s", ifname
);
1848 return (PCAP_ERROR_NO_SUCH_DEVICE
);
1852 dlpi_kread(register int fd
, register off_t addr
,
1853 register void *buf
, register u_int len
, register char *ebuf
)
1857 if (lseek(fd
, addr
, SEEK_SET
) < 0) {
1858 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1862 cc
= read(fd
, buf
, len
);
1864 pcap_fmt_errmsg_for_errno(ebuf
, PCAP_ERRBUF_SIZE
,
1867 } else if (cc
!= len
) {
1868 pcap_snprintf(ebuf
, PCAP_ERRBUF_SIZE
, "short read (%d != %d)", cc
,
1877 pcap_create_interface(const char *device _U_
, char *ebuf
)
1881 struct pcap_dlpi
*pd
;
1884 p
= pcap_create_common(ebuf
, sizeof (struct pcap_dlpi
));
1890 pd
->send_fd
= -1; /* it hasn't been opened yet */
1893 p
->activate_op
= pcap_activate_dlpi
;
1898 * Libpcap version string.
1901 pcap_lib_version(void)
1903 return (PCAP_VERSION_STRING
);