static int pcap_open(void *data) { struct pcap_data *pri = data; __u32 netmask; int err; if (pri->pcap == NULL) return -ENODEV; if (pri->filter != NULL) { err = dev_netmask(pri->dev, &netmask); if (err < 0) { printk(UM_KERN_ERR "pcap_open : dev_netmask failed\n"); return -EIO; } pri->compiled = uml_kmalloc(sizeof(struct bpf_program), UM_GFP_KERNEL); if (pri->compiled == NULL) { printk(UM_KERN_ERR "pcap_open : kmalloc failed\n"); return -ENOMEM; } err = pcap_compile(pri->pcap, (struct bpf_program *) pri->compiled, pri->filter, pri->optimize, netmask); if (err < 0) { printk(UM_KERN_ERR "pcap_open : pcap_compile failed - " "'%s'\n", pcap_geterr(pri->pcap)); goto out; } err = pcap_setfilter(pri->pcap, pri->compiled); if (err < 0) { printk(UM_KERN_ERR "pcap_open : pcap_setfilter " "failed - '%s'\n", pcap_geterr(pri->pcap)); goto out; } } return PCAP_FD(pri->pcap); out: kfree(pri->compiled); return -EIO; }
static int pcap_open(void *data) { struct pcap_data *pri = data; __u32 netmask; int err; if(pri->pcap == NULL) return(-ENODEV); if(pri->filter != NULL){ err = dev_netmask(pri->dev, &netmask); if(err < 0){ printk("pcap_open : dev_netmask failed\n"); return(-EIO); } pri->compiled = um_kmalloc(sizeof(struct bpf_program)); if(pri->compiled == NULL){ printk("pcap_open : kmalloc failed\n"); return(-ENOMEM); } err = pcap_compile(pri->pcap, (struct bpf_program *) pri->compiled, pri->filter, pri->optimize, netmask); if(err < 0){ printk("pcap_open : pcap_compile failed - '%s'\n", pcap_geterr(pri->pcap)); return(-EIO); } err = pcap_setfilter(pri->pcap, pri->compiled); if(err < 0){ printk("pcap_open : pcap_setfilter failed - '%s'\n", pcap_geterr(pri->pcap)); return(-EIO); } } return(PCAP_FD(pri->pcap)); }