~ubuntu-branches/ubuntu/feisty/wpasupplicant/feisty

« back to all changes in this revision

Viewing changes to l2_packet_pcap.c

  • Committer: Bazaar Package Importer
  • Author(s): Reinhard Tartler
  • Date: 2007-04-01 10:53:37 UTC
  • Revision ID: james.westby@ubuntu.com-20070401105337-3dd89n3g8ecdhjsl
Tags: 0.5.7-0ubuntu2
Apply patch from upstream after private email discussion:
http://w1.fi/gitweb/gitweb.cgi?p=hostap.git;a=commitdiff;h=33673d3f43da6f5ec0f0aa5a8245a1617b6eb2fd#patch1
Fixes LP: #98895, #98925

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
 
49
49
int l2_packet_get_own_addr(struct l2_packet_data *l2, u8 *addr)
50
50
{
51
 
        os_memcpy(addr, l2->own_addr, ETH_ALEN);
 
51
        memcpy(addr, l2->own_addr, ETH_ALEN);
52
52
        return 0;
53
53
}
54
54
 
73
73
                l2->eth = NULL;
74
74
                return -1;
75
75
        }
76
 
        os_memcpy(l2->own_addr, own_addr.data, ETH_ALEN);
 
76
        memcpy(l2->own_addr, own_addr.data, ETH_ALEN);
77
77
 
78
78
        return 0;
79
79
}
97
97
#endif /* CONFIG_WINPCAP */
98
98
        } else {
99
99
                size_t mlen = sizeof(*eth) + len;
100
 
                eth = os_malloc(mlen);
 
100
                eth = malloc(mlen);
101
101
                if (eth == NULL)
102
102
                        return -1;
103
103
 
104
 
                os_memcpy(eth->h_dest, dst_addr, ETH_ALEN);
105
 
                os_memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
 
104
                memcpy(eth->h_dest, dst_addr, ETH_ALEN);
 
105
                memcpy(eth->h_source, l2->own_addr, ETH_ALEN);
106
106
                eth->h_proto = htons(proto);
107
 
                os_memcpy(eth + 1, buf, len);
 
107
                memcpy(eth + 1, buf, len);
108
108
 
109
109
#ifdef CONFIG_WINPCAP
110
110
                ret = pcap_sendpacket(l2->pcap, (u8 *) eth, mlen);
112
112
                ret = eth_send(l2->eth, (u8 *) eth, mlen);
113
113
#endif /* CONFIG_WINPCAP */
114
114
 
115
 
                os_free(eth);
 
115
                free(eth);
116
116
        }
117
117
 
118
118
        return ret;
208
208
 
209
209
#ifdef CONFIG_WINPCAP
210
210
        char ifname[128];
211
 
        os_snprintf(ifname, sizeof(ifname), "\\Device\\NPF_%s", l2->ifname);
 
211
        snprintf(ifname, sizeof(ifname), "\\Device\\NPF_%s", l2->ifname);
212
212
        pcap_lookupnet(ifname, &pcap_netp, &pcap_maskp, pcap_err);
213
213
        l2->pcap = pcap_open_live(ifname, 2500, 0, 10, pcap_err);
214
214
        if (l2->pcap == NULL) {
234
234
                return -1;
235
235
        }
236
236
#endif /* CONFIG_WINPCAP */
237
 
        os_snprintf(pcap_filter, sizeof(pcap_filter),
238
 
                    "not ether src " MACSTR " and "
239
 
                    "( ether dst " MACSTR " or ether dst " MACSTR " ) and "
240
 
                    "ether proto 0x%x",
241
 
                    MAC2STR(l2->own_addr), /* do not receive own packets */
242
 
                    MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
243
 
                    protocol);
 
237
        snprintf(pcap_filter, sizeof(pcap_filter),
 
238
                 "not ether src " MACSTR " and "
 
239
                 "( ether dst " MACSTR " or ether dst " MACSTR " ) and "
 
240
                 "ether proto 0x%x",
 
241
                 MAC2STR(l2->own_addr), /* do not receive own packets */
 
242
                 MAC2STR(l2->own_addr), MAC2STR(pae_group_addr),
 
243
                 protocol);
244
244
        if (pcap_compile(l2->pcap, &pcap_fp, pcap_filter, 1, pcap_netp) < 0) {
245
245
                fprintf(stderr, "pcap_compile: %s\n", pcap_geterr(l2->pcap));
246
246
                return -1;
289
289
{
290
290
        struct l2_packet_data *l2;
291
291
 
292
 
        l2 = os_zalloc(sizeof(struct l2_packet_data));
 
292
        l2 = wpa_zalloc(sizeof(struct l2_packet_data));
293
293
        if (l2 == NULL)
294
294
                return NULL;
295
 
        os_strncpy(l2->ifname, ifname, sizeof(l2->ifname));
 
295
        strncpy(l2->ifname, ifname, sizeof(l2->ifname));
296
296
        l2->rx_callback = rx_callback;
297
297
        l2->rx_callback_ctx = rx_callback_ctx;
298
298
        l2->l2_hdr = l2_hdr;
299
299
 
300
300
#ifdef CONFIG_WINPCAP
301
301
        if (own_addr)
302
 
                os_memcpy(l2->own_addr, own_addr, ETH_ALEN);
 
302
                memcpy(l2->own_addr, own_addr, ETH_ALEN);
303
303
#else /* CONFIG_WINPCAP */
304
304
        if (l2_packet_init_libdnet(l2))
305
305
                return NULL;
309
309
#ifndef CONFIG_WINPCAP
310
310
                eth_close(l2->eth);
311
311
#endif /* CONFIG_WINPCAP */
312
 
                os_free(l2);
 
312
                free(l2);
313
313
                return NULL;
314
314
        }
315
315
 
331
331
#endif /* CONFIG_WINPCAP */
332
332
        if (l2->pcap)
333
333
                pcap_close(l2->pcap);
334
 
        os_free(l2);
 
334
        free(l2);
335
335
}
336
336
 
337
337
 
349
349
        }
350
350
 
351
351
        for (dev = devs; dev && !found; dev = dev->next) {
352
 
                if (os_strcmp(dev->name, l2->ifname) != 0)
 
352
                if (strcmp(dev->name, l2->ifname) != 0)
353
353
                        continue;
354
354
 
355
355
                addr = dev->addresses;
356
356
                while (addr) {
357
357
                        saddr = (struct sockaddr_in *) addr->addr;
358
358
                        if (saddr && saddr->sin_family == AF_INET) {
359
 
                                os_snprintf(buf, len, "%s",
360
 
                                            inet_ntoa(saddr->sin_addr));
 
359
                                snprintf(buf, len, "%s",
 
360
                                         inet_ntoa(saddr->sin_addr));
361
361
                                found = 1;
362
362
                                break;
363
363
                        }