Lines Matching +full:no +full:- +full:can +full:- +full:fd
24 * <List-tcpdump-workers@subscriptions.pizzolato.net>,
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
38 * - It might be desirable to use pfmod(7) to filter packets in the
41 * - An older version of the HP-UX DLPI Programmer's Guide, which
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
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
110 #include "pcap-int.h"
114 #include "os-proto.h"
119 * HP-UX has a /dev/dlpi device; you open it and set the PPA of the actual
195 cc = p->cc; in pcap_read_dlpi()
197 data.buf = (char *)p->buffer + p->offset; in pcap_read_dlpi()
198 data.maxlen = p->bufsize; in pcap_read_dlpi()
204 if (p->break_loop) { in pcap_read_dlpi()
206 * Yes - clear the flag that indicates in pcap_read_dlpi()
207 * that it has, and return -2 to in pcap_read_dlpi()
211 p->break_loop = 0; in pcap_read_dlpi()
212 return (-2); in pcap_read_dlpi()
215 * XXX - check for the DLPI primitive, which in pcap_read_dlpi()
216 * would be DL_HP_RAWDATA_IND on HP-UX in pcap_read_dlpi()
222 if (getmsg(p->fd, &ctl, &data, &flags) < 0) { in pcap_read_dlpi()
233 pcapint_fmt_errmsg_for_errno(p->errbuf, in pcap_read_dlpi()
234 sizeof(p->errbuf), errno, "getmsg"); in pcap_read_dlpi()
235 return (-1); in pcap_read_dlpi()
239 bp = (u_char *)p->buffer + p->offset; in pcap_read_dlpi()
241 bp = p->bp; in pcap_read_dlpi()
250 struct pcap_dlpi *pd = p->priv; in pcap_inject_dlpi()
255 ret = write(p->fd, buf, size); in pcap_inject_dlpi()
256 if (ret == -1) { in pcap_inject_dlpi()
257 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_inject_dlpi()
259 return (-1); in pcap_inject_dlpi()
262 if (pd->send_fd < 0) { in pcap_inject_dlpi()
263 snprintf(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_inject_dlpi()
264 "send: Output FD couldn't be opened"); in pcap_inject_dlpi()
265 return (-1); in pcap_inject_dlpi()
267 ret = dlrawdatareq(pd->send_fd, buf, size); in pcap_inject_dlpi()
268 if (ret == -1) { in pcap_inject_dlpi()
269 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE, in pcap_inject_dlpi()
271 return (-1); in pcap_inject_dlpi()
274 * putmsg() returns either 0 or -1; it doesn't indicate how in pcap_inject_dlpi()
281 #else /* no raw mode */ in pcap_inject_dlpi()
283 * XXX - this is a pain, because you might have to extract in pcap_inject_dlpi()
285 * request. That would be dependent on the link-layer type. in pcap_inject_dlpi()
293 * So, for now, we just return a "you can't send" indication, in pcap_inject_dlpi()
294 * and leave it up to somebody with a DLPI-based system lacking in pcap_inject_dlpi()
297 * send it to us - but should not send us code that assumes in pcap_inject_dlpi()
298 * Ethernet; if the code doesn't work on non-Ethernet interfaces, in pcap_inject_dlpi()
299 * it should check "p->linktype" and reject the send request if in pcap_inject_dlpi()
302 pcapint_strlcpy(p->errbuf, "send: Not supported on this version of this OS", in pcap_inject_dlpi()
304 ret = -1; in pcap_inject_dlpi()
329 struct pcap_dlpi *pd = p->priv; in pcap_cleanup_dlpi()
331 if (pd->send_fd >= 0) { in pcap_cleanup_dlpi()
332 close(pd->send_fd); in pcap_cleanup_dlpi()
333 pd->send_fd = -1; in pcap_cleanup_dlpi()
345 int fd; in open_dlpi_device() local
378 * XXX - HP's DLPI Programmer's Guide for HP-UX 11.00 says that in open_dlpi_device()
387 if ((fd = open(cp, O_RDWR)) < 0) { in open_dlpi_device()
391 "Attempt to open %s failed with %s - root privilege may be required", in open_dlpi_device()
405 status = get_dlpi_ppa(fd, dname, unit, ppa, errbuf); in open_dlpi_device()
407 close(fd); in open_dlpi_device()
443 if ((fd = open(dname, O_RDWR)) < 0) { in open_dlpi_device()
448 "Attempt to open %s failed with %s - root privilege may be required", in open_dlpi_device()
461 if ((fd = open(dname2, O_RDWR)) < 0) { in open_dlpi_device()
469 * the app can show the message if the in open_dlpi_device()
472 * In it, we just report "No DLPI device in open_dlpi_device()
475 * that if they can't capture on "lo0" in open_dlpi_device()
481 * other than Solaris - you just *can't* in open_dlpi_device()
489 "%s: No DLPI device found", name); in open_dlpi_device()
494 "Attempt to open %s failed with %s - root privilege may be required", in open_dlpi_device()
511 return (fd); in open_dlpi_device()
518 struct pcap_dlpi *pd = p->priv;
536 p->fd = open_dlpi_device(p->opt.device, &ppa, p->errbuf);
537 if (p->fd < 0) {
538 status = p->fd;
544 * XXX - HP-UX 10.20 and 11.xx don't appear to support sending and
545 * receiving packets on the same descriptor - you need separate
548 * If the open fails, we just leave -1 in "pd->send_fd" and reject
549 * attempts to send packets, just as if, in pcap-bpf.c, we fail
554 pd->send_fd = open("/dev/dlpi", O_RDWR);
560 if (dlinforeq(p->fd, p->errbuf) < 0 ||
561 dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
565 infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
567 if (infop->dl_mac_type == DL_IPATM)
570 if (infop->dl_provider_style == DL_STYLE2) {
571 retv = dl_doattach(p->fd, ppa, p->errbuf);
577 if (pd->send_fd >= 0) {
578 retv = dl_doattach(pd->send_fd, ppa, p->errbuf);
587 if (p->opt.rfmon) {
601 dlpassive(p->fd, p->errbuf);
604 ** Bind (defer if using HP-UX 9 or HP-UX 10.20 or later, totally
613 ** However, we seem to get DL_BADADDR - "DLSAP addr in improper
614 ** format or invalid" - errors if we use 1537 on the "tr0"
623 ** work; perhaps that's considered an invalid LLC SAP value - I
627 if ((dlbindreq(p->fd, 1537, p->errbuf) < 0 &&
628 dlbindreq(p->fd, 2, p->errbuf) < 0) ||
629 dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
635 ** HP-UX 10.0x and 10.1x.
637 if (dl_dohpuxbind(p->fd, p->errbuf) < 0) {
641 if (pd->send_fd >= 0) {
643 ** XXX - if this fails, just close send_fd and
644 ** set it to -1, so that you can't send but can
647 if (dl_dohpuxbind(pd->send_fd, p->errbuf) < 0) {
652 #else /* neither AIX nor HP-UX */
654 ** Not Sinix, and neither AIX nor HP-UX - Solaris, and any other
657 if (dlbindreq(p->fd, 0, p->errbuf) < 0 ||
658 dlbindack(p->fd, (char *)buf, p->errbuf, NULL) < 0) {
662 #endif /* AIX vs. HP-UX vs. other */
663 #endif /* !HP-UX 9 and !HP-UX 10.20 or later and !SINIX */
673 if (p->snapshot <= 0 || p->snapshot > MAXIMUM_SNAPLEN)
674 p->snapshot = MAXIMUM_SNAPLEN;
684 if (strioctl(p->fd, A_PROMISCON_REQ, 0, NULL) < 0) {
686 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
692 if (p->opt.promisc) {
694 ** Enable promiscuous (not necessary on send FD)
708 ** HP-UX or SINIX) (Not necessary on send FD)
718 ** when using HP-UX, when not doing SunATM on Solaris, and never
719 ** under SINIX) (Not necessary on send FD)
723 /* HP-UX - only do this when not in promiscuous mode */
724 if (!p->opt.promisc) {
726 /* Solaris - don't do this on SunATM devices */
729 /* Everything else (except for SINIX) - always do this */
734 if (p->opt.promisc) {
754 ** HP-UX 9, and HP-UX 10.20 or later, must bind after setting
758 if (dl_dohpuxbind(p->fd, p->errbuf) < 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 (pd->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(pd->send_fd, p->errbuf) < 0) {
782 ** XXX - get SAP length and address length as well, for use
785 if (dlinforeq(p->fd, p->errbuf) < 0 ||
786 dlinfoack(p->fd, (char *)buf, p->errbuf) < 0) {
791 infop = &(MAKE_DL_PRIMITIVES(buf))->info_ack;
792 if (pcap_process_mactype(p, infop->dl_mac_type) != 0) {
799 ** This is a non standard SunOS hack to get the full raw link-layer
802 if (strioctl(p->fd, DLIOCRAW, 0, NULL) < 0) {
804 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
811 ss = p->snapshot;
825 snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
843 if (ioctl(p->fd, I_FLUSH, FLUSHR) != 0) {
845 pcapint_fmt_errmsg_for_errno(p->errbuf, PCAP_ERRBUF_SIZE,
859 * "p->fd" is an FD for a STREAMS device, so "select()" and
862 p->selectable_fd = p->fd;
864 p->read_op = pcap_read_dlpi;
865 p->inject_op = pcap_inject_dlpi;
866 p->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */
867 p->setdirection_op = NULL; /* Not implemented.*/
868 p->set_datalink_op = NULL; /* can't change data link type */
869 p->getnonblock_op = pcapint_getnonblock_fd;
870 p->setnonblock_op = pcapint_setnonblock_fd;
871 p->stats_op = pcap_stats_dlpi;
872 p->cleanup_op = pcap_cleanup_dlpi;
898 cp = device + strlen(device) - 1;
906 while (cp-1 >= device && *(cp-1) >= '0' && *(cp-1) <= '9')
907 cp--;
930 dl_doattach(int fd, int ppa, char *ebuf) argument
938 if (send_request(fd, (char *)&req, sizeof(req), "attach", ebuf) < 0)
941 err = dlokack(fd, "attach", (char *)buf, ebuf, NULL);
949 dl_dohpuxbind(int fd, char *ebuf) argument
956 * XXX - we start at 22 because we used to use only 22, but
960 * on the input FD?
964 if (dlbindreq(fd, hpsap, ebuf) < 0)
965 return (-1);
966 if (dlbindack(fd, (char *)buf, ebuf, &uerror) >= 0)
976 return (-1);
991 return (-1);
1010 if (send_request(p->fd, (char *)&req, sizeof(req), "promiscon",
1011 p->errbuf) < 0)
1013 err = dlokack(p->fd, "promiscon" STRINGIFY(level), (char *)buf,
1014 p->errbuf, &uerror);
1017 snprintf(p->errbuf, PCAP_ERRBUF_SIZE,
1018 "Attempt to set promiscuous mode failed with %s - root privilege may be required",
1029 * can be opened with DLPI (for example, the loopback interface is not
1037 int fd; local
1041 fd = open_dlpi_device(name, &ppa, errbuf);
1042 if (fd < 0) {
1044 * Error - was it PCAP_ERROR_NO_SUCH_DEVICE?
1046 if (fd == PCAP_ERROR_NO_SUCH_DEVICE) {
1048 * Yes, so we can't open this because it's
1054 * No, so, in the case where there's a single DLPI
1058 * Say it is a DLPI device, so that the user can at
1073 close(fd);
1081 * Nothing we can do other than mark loopback devices as "the
1084 * XXX - on Solaris, can we do what the dladm command does,
1086 * (Note that you can also get the link speed, and possibly
1104 int fd; local
1107 char pad[516]; /* XXX - must be at least 513; is 516
1118 get_if_flags) == -1)
1119 return (-1); /* failure */
1125 if ((fd = open("/dev/ba", O_RDWR)) < 0) {
1137 if (strioctl(fd, A_GET_UNITS, sizeof(buf), (char *)&buf) < 0) {
1140 return (-1);
1145 * XXX - is there a notion of "up" and "running"?
1150 return (-1);
1158 send_request(int fd, char *ptr, int len, char *what, char *ebuf) argument
1168 if (putmsg(fd, &ctl, (struct strbuf *) NULL, flags) < 0) {
1171 return (-1);
1177 recv_ack(int fd, int size, const char *what, char *bufp, char *ebuf, int *uerror) argument
1197 if (getmsg(fd, &ctl, (struct strbuf*)NULL, &flags) < 0) {
1204 switch (dlp->dl_primitive) {
1216 switch (dlp->error_ack.dl_errno) {
1220 *uerror = dlp->error_ack.dl_unix_errno;
1222 dlp->error_ack.dl_unix_errno,
1224 if (dlp->error_ack.dl_unix_errno == EPERM ||
1225 dlp->error_ack.dl_unix_errno == EACCES)
1235 dlstrerror(errmsgbuf, sizeof (errmsgbuf), dlp->error_ack.dl_errno));
1236 if (dlp->error_ack.dl_errno == DL_BADPPA)
1238 else if (dlp->error_ack.dl_errno == DL_ACCESS)
1247 what, dlprim(dlprimbuf, sizeof (dlprimbuf), dlp->dl_primitive));
1342 return ("Other streams for PPA in post-attached");
1462 dlbindreq(int fd, bpf_u_int32 sap, char *ebuf) argument
1469 /* XXX - what if neither of these are defined? */
1478 return (send_request(fd, (char *)&req, sizeof(req), "bind", ebuf));
1482 dlbindack(int fd, char *bufp, char *ebuf, int *uerror) argument
1485 return (recv_ack(fd, DL_BIND_ACK_SIZE, "bind", bufp, ebuf, uerror));
1489 dlokack(int fd, const char *what, char *bufp, char *ebuf, int *uerror) argument
1492 return (recv_ack(fd, DL_OK_ACK_SIZE, what, bufp, ebuf, uerror));
1497 dlinforeq(int fd, char *ebuf) argument
1503 return (send_request(fd, (char *)&req, sizeof(req), "info", ebuf));
1507 dlinfoack(int fd, char *bufp, char *ebuf) argument
1510 return (recv_ack(fd, DL_INFO_ACK_SIZE, "info", bufp, ebuf, NULL));
1519 dlpassive(int fd, char *ebuf) argument
1526 if (send_request(fd, (char *)&req, sizeof(req), "dlpassive", ebuf) == 0)
1527 (void) dlokack(fd, "dlpassive", (char *)buf, ebuf, NULL);
1536 dlrawdatareq(int fd, const u_char *datap, int datalen) argument
1539 long buf[MAXDLBUF]; /* XXX - char? */
1545 dlp->dl_primitive = DL_HP_RAWDATA_REQ;
1551 * I think that's what raw mode means - you just send the raw
1563 return (putmsg(fd, &ctl, &data, 0));
1596 * Under HP-UX 10 and HP-UX 11, we can ask for the ppa
1604 * the code that's used here is the old code for HP-UX 10.x.
1606 * However, HP-UX 10.20, at least, appears to have such a member
1610 * worked - it appears that the older system had those members but
1628 echo 'lanc_outbound_promisc_flag/W1' | /usr/bin/adb -w /stand/vmunix /dev/kmem
1632 * Setting the variable is not necessary on HP-UX 11.x.
1635 get_dlpi_ppa(register int fd, register const char *device, register u_int unit, argument
1655 if (send_request(fd, (char *)&req, sizeof(req), "hpppa", ebuf) < 0)
1668 * This causes libpcap applications to fail on a system with HP-APA
1676 if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
1681 if (ctl.len == -1) {
1683 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1688 if (dlp->dl_primitive != DL_HP_PPA_ACK) {
1691 (bpf_u_int32)dlp->dl_primitive);
1703 if ((ppa_data_buf = (char *)malloc(dlp->dl_length)) == NULL) {
1708 ctl.maxlen = dlp->dl_length;
1712 if (getmsg(fd, &ctl, (struct strbuf *)NULL, &flags) < 0) {
1718 if (ctl.len == -1) {
1720 "get_dlpi_ppa: hpppa getmsg: control buffer has no data");
1723 if ((u_int)ctl.len < dlp->dl_length) {
1726 ctl.len, (unsigned long)dlp->dl_length);
1749 for (i = 0; i < ap->dl_count; i++) {
1750 if ((strcmp((const char *)ip->dl_module_id_1, device) == 0 ||
1751 strcmp((const char *)ip->dl_module_id_2, device) == 0) &&
1752 ip->dl_instance_num == unit)
1755 ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
1762 i = ap->dl_count;
1765 if (i == ap->dl_count) {
1767 * Well, we didn't, or can't, find the device by name.
1769 * HP-UX 10.20, whilst it has "dl_module_id_1" and
1772 * at a reasonably up-to-date patch level.
1774 * Older HP-UX 10.x systems might not have those fields
1791 for (i = 0; i < ap->dl_count; i++) {
1792 if (ip->dl_mjr_num == majdev &&
1793 ip->dl_instance_num == unit)
1796 ip = (dl_hp_ppa_info_t *)((u_char *)ipstart + ip->dl_next_offset);
1799 if (i == ap->dl_count) {
1801 "can't find /dev/dlpi PPA for %s%u", device, unit);
1804 if (ip->dl_hdw_state == HDW_DEAD) {
1810 *ppa = ip->dl_ppa;
1818 * Under HP-UX 9, there is no good way to determine the ppa.
1827 static char path_vmunix[] = "/hp-ux";
1831 get_dlpi_ppa(register int fd, register const char *ifname, register u_int unit, argument
1880 snprintf(ebuf, PCAP_ERRBUF_SIZE, "Can't find %s", ifname);
1885 dlpi_kread(register int fd, register off_t addr, argument
1890 if (lseek(fd, addr, SEEK_SET) < 0) {
1893 return (-1);
1895 cc = read(fd, buf, len);
1899 return (-1);
1903 return (-1);
1922 pd = p->priv;
1923 pd->send_fd = -1; /* it hasn't been opened yet */
1926 p->activate_op = pcap_activate_dlpi;