diff options
author | Guy Harris <guy@alum.mit.edu> | 2010-09-21 02:07:05 -0700 |
---|---|---|
committer | Guy Harris <guy@alum.mit.edu> | 2010-09-21 02:07:05 -0700 |
commit | 74b7b4259fde15dbb07cde3a5920e9f7e0ed4484 (patch) | |
tree | c7281be68f5536401eec53bbe0245b0fe79c2232 /pcap-dlpi.c | |
parent | b26d8d2aa849c8021cdfa872901e82fb469460ef (diff) |
Return PCAP_ERROR_PROMISC_PERM_DENIED if you have permission to open the
DLPI device but don't have permission to put the interface in
promiscuous mode; some systems using DLPI work that way.
Change the libdlpi code to return a warning if you *are* using
physical promiscuous mode and you fail to turn on SAP promiscuous mode,
not if you *aren't* using physical promiscuous mode and you fail to turn
on SAP promiscuous mode; that matches with the no-libdlpi code does, and
matches what the comment says.
Pull dlattachreq up into dl_doattach().
Diffstat (limited to 'pcap-dlpi.c')
-rw-r--r-- | pcap-dlpi.c | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/pcap-dlpi.c b/pcap-dlpi.c index 8f938fe1..ec2f32dd 100644 --- a/pcap-dlpi.c +++ b/pcap-dlpi.c @@ -143,10 +143,9 @@ static int dl_doattach(int, int, char *); #ifdef DL_HP_RAWDLS static int dl_dohpuxbind(int, char *); #endif -static int dlattachreq(int, bpf_u_int32, char *); +static int dlpromiscon(pcap_t *, bpf_u_int32); static int dlbindreq(int, bpf_u_int32, char *); static int dlbindack(int, char *, char *, int *); -static int dlpromisconreq(int, bpf_u_int32, char *); static int dlokack(int, const char *, char *, char *); static int dlinforeq(int, char *); static int dlinfoack(int, char *, char *); @@ -610,9 +609,12 @@ pcap_activate_dlpi(pcap_t *p) /* ** Enable promiscuous (not necessary on send FD) */ - if (dlpromisconreq(p->fd, DL_PROMISC_PHYS, p->errbuf) < 0 || - dlokack(p->fd, "promisc_phys", (char *)buf, p->errbuf) < 0) + status = dlpromiscon(p, DL_PROMISC_PHYS); + if (status < 0) { + if (status == PCAP_ERROR_PERM_DENIED) + status = PCAP_ERROR_PROMISC_PERM_DENIED; goto bad; + } /* ** Try to enable multicast (you would have thought @@ -620,8 +622,8 @@ pcap_activate_dlpi(pcap_t *p) ** HP-UX or SINIX) (Not necessary on send FD) */ #if !defined(__hpux) && !defined(sinix) - if (dlpromisconreq(p->fd, DL_PROMISC_MULTI, p->errbuf) < 0 || - dlokack(p->fd, "promisc_multi", (char *)buf, p->errbuf) < 0) + status = dlpromiscon(p, DL_PROMISC_MULTI); + if (status < 0) status = PCAP_WARNING; #endif } @@ -636,15 +638,20 @@ pcap_activate_dlpi(pcap_t *p) !p->opt.promisc && #endif #ifdef HAVE_SOLARIS - !isatm && + !isatm #endif - (dlpromisconreq(p->fd, DL_PROMISC_SAP, p->errbuf) < 0 || - dlokack(p->fd, "promisc_sap", (char *)buf, p->errbuf) < 0)) { - /* Not fatal if promisc since the DL_PROMISC_PHYS worked */ - if (p->opt.promisc) - status = PCAP_WARNING; - else - goto bad; + ) { + status = dlpromiscon(p, DL_PROMISC_SAP); + if (status < 0) { + /* + * Not fatal, since the DL_PROMISC_PHYS mode worked. + * Report it as a warning, however. + */ + if (p->opt.promisc) + status = PCAP_WARNING; + else + goto bad; + } } #endif /* sinix */ @@ -815,11 +822,15 @@ split_dname(char *device, int *unitp, char *ebuf) static int dl_doattach(int fd, int ppa, char *ebuf) { + dl_attach_req_t req; bpf_u_int32 buf[MAXDLBUF]; int err; - if (dlattachreq(fd, ppa, ebuf) < 0) + req.dl_primitive = DL_ATTACH_REQ; + req.dl_ppa = ppa; + if (send_request(fd, (char *)&req, sizeof(req), "attach", ebuf) < 0) return (PCAP_ERROR); + err = dlokack(fd, "attach", (char *)buf, ebuf); if (err < 0) return (err); @@ -877,6 +888,27 @@ dl_dohpuxbind(int fd, char *ebuf) } #endif +#define STRINGIFY(n) #n + +static int +dlpromiscon(pcap_t *p, bpf_u_int32 level) +{ + dl_promiscon_req_t req; + bpf_u_int32 buf[MAXDLBUF]; + int err; + + req.dl_primitive = DL_PROMISCON_REQ; + req.dl_level = level; + if (send_request(p->fd, (char *)&req, sizeof(req), "promiscon", + p->errbuf) < 0) + return (PCAP_ERROR); + err = dlokack(p->fd, "promiscon" STRINGIFY(level), (char *)buf, + p->errbuf); + if (err < 0) + return (err); + return (0); +} + int pcap_platform_finddevs(pcap_if_t **alldevsp, char *errbuf) { @@ -1222,17 +1254,6 @@ dlprim(bpf_u_int32 prim) } static int -dlattachreq(int fd, bpf_u_int32 ppa, char *ebuf) -{ - dl_attach_req_t req; - - req.dl_primitive = DL_ATTACH_REQ; - req.dl_ppa = ppa; - - return (send_request(fd, (char *)&req, sizeof(req), "attach", ebuf)); -} - -static int dlbindreq(int fd, bpf_u_int32 sap, char *ebuf) { @@ -1260,17 +1281,6 @@ dlbindack(int fd, char *bufp, char *ebuf, int *uerror) } static int -dlpromisconreq(int fd, bpf_u_int32 level, char *ebuf) -{ - dl_promiscon_req_t req; - - req.dl_primitive = DL_PROMISCON_REQ; - req.dl_level = level; - - return (send_request(fd, (char *)&req, sizeof(req), "promiscon", ebuf)); -} - -static int dlokack(int fd, const char *what, char *bufp, char *ebuf) { |