~ubuntu-branches/debian/sid/lldpd/sid

« back to all changes in this revision

Viewing changes to src/daemon/priv-linux.c

  • Committer: Package Import Robot
  • Author(s): Vincent Bernat
  • Date: 2014-07-26 10:19:24 UTC
  • mfrom: (1.1.20)
  • Revision ID: package-import@ubuntu.com-20140726101924-v6jtds7xures4txm
Tags: 0.7.10-1
* New upstream version.
   + Update symbols.

Show diffs side-by-side

added added

removed removed

Lines of Context:
158
158
        if ((*fd = socket(PF_PACKET, SOCK_RAW,
159
159
                    htons(ETH_P_ALL))) < 0) {
160
160
                rc = errno;
161
 
                must_write(PRIV_PRIVILEGED, &rc, sizeof(rc));
162
161
                return rc;
163
162
        }
164
163
 
259
258
        fclose(fp);
260
259
        return 0;
261
260
}
 
261
 
 
262
int
 
263
asroot_iface_promisc_os(const char *name)
 
264
{
 
265
        int s, rc;
 
266
        if ((s = socket(PF_PACKET, SOCK_RAW,
 
267
                    htons(ETH_P_ALL))) < 0) {
 
268
                rc = errno;
 
269
                log_warn("privsep", "unable to open raw socket");
 
270
                return rc;
 
271
        }
 
272
 
 
273
        struct ifreq ifr = {};
 
274
        strlcpy(ifr.ifr_name, name, sizeof(ifr.ifr_name));
 
275
 
 
276
        if (ioctl(s, SIOCGIFFLAGS, &ifr) == -1) {
 
277
                rc = errno;
 
278
                log_warn("privsep", "unable to get interface flags for %s",
 
279
                    name);
 
280
                close(s);
 
281
                return rc;
 
282
        }
 
283
 
 
284
        if (ifr.ifr_flags & IFF_PROMISC) {
 
285
                close(s);
 
286
                return 0;
 
287
        }
 
288
        ifr.ifr_flags |= IFF_PROMISC;
 
289
        if (ioctl(s, SIOCSIFFLAGS, &ifr) == -1) {
 
290
                rc = errno;
 
291
                log_warn("privsep", "unable to set promisc mode for %s",
 
292
                    name);
 
293
                close(s);
 
294
                return rc;
 
295
        }
 
296
        log_info("privsep", "promiscuous mode enabled for %s", name);
 
297
        close(s);
 
298
        return 0;
 
299
}