Lines Matching +full:device +full:- +full:handle
2 * Copyright 2006-2010, Haiku, Inc. All Rights Reserved.
6 * Axel Dörfler, axeld@pinc-software.de
12 #include "pcap-int.h"
34 // integer value didn't change). Even though IFT_TUN is a no-op in versions
56 pcap_read_haiku(pcap_t* handle, int maxPackets _U_, pcap_handler callback, in pcap_read_haiku() argument
61 u_char* buffer = (u_char*)handle->buffer; in pcap_read_haiku()
64 if (handle->break_loop) { in pcap_read_haiku()
65 handle->break_loop = 0; in pcap_read_haiku()
68 bytesReceived = recvfrom(handle->fd, buffer, handle->bufsize, MSG_TRUNC, in pcap_read_haiku()
82 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in pcap_read_haiku()
87 struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv; in pcap_read_haiku()
88 // BPF is 32-bit, which is more than sufficient for any realistic in pcap_read_haiku()
101 handlep->stat.ps_recv++; in pcap_read_haiku()
109 wireLength <= handle->bufsize ? wireLength : handle->bufsize; in pcap_read_haiku()
112 if (handle->fcode.bf_insns) { in pcap_read_haiku()
114 // length, not the snapshot length of the pcap_t handle. in pcap_read_haiku()
115 if (pcapint_filter(handle->fcode.bf_insns, buffer, wireLength, in pcap_read_haiku()
122 header.caplen = captureLength <= (bpf_u_int32)handle->snapshot ? in pcap_read_haiku()
124 (bpf_u_int32)handle->snapshot; in pcap_read_haiku()
133 handlep->stat.ps_drop++; in pcap_read_haiku()
165 get_promisc(pcap_t *handle) in get_promisc() argument
167 struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv; in get_promisc()
169 if (ioctl_ifreq(handlep->aux_socket, SIOCGIFFLAGS, "SIOCGIFFLAGS", in get_promisc()
170 &handlep->ifreq, handle->errbuf) < 0) in get_promisc()
172 return (handlep->ifreq.ifr_flags & IFF_PROMISC) != 0; in get_promisc()
177 set_promisc(pcap_t *handle, const int enable) in set_promisc() argument
179 struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv; in set_promisc()
181 handlep->ifreq.ifr_flags |= IFF_PROMISC; in set_promisc()
183 handlep->ifreq.ifr_flags &= ~IFF_PROMISC; in set_promisc()
185 return ioctl_ifreq(handlep->aux_socket, SIOCSIFFLAGS, "SIOCSIFFLAGS", in set_promisc()
186 &handlep->ifreq, handle->errbuf); in set_promisc()
191 pcap_cleanup_haiku(pcap_t *handle) in pcap_cleanup_haiku() argument
193 struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv; in pcap_cleanup_haiku()
194 if (handlep->aux_socket >= 0) { in pcap_cleanup_haiku()
200 if (handle->opt.promisc && ! handlep->orig_promisc && in pcap_cleanup_haiku()
201 get_promisc(handle)) in pcap_cleanup_haiku()
202 (void)set_promisc(handle, 0); in pcap_cleanup_haiku()
203 close(handlep->aux_socket); in pcap_cleanup_haiku()
204 handlep->aux_socket = -1; in pcap_cleanup_haiku()
206 pcapint_cleanup_live_common(handle); in pcap_cleanup_haiku()
211 pcap_inject_haiku(pcap_t *handle, const void *buffer _U_, int size _U_) in pcap_inject_haiku() argument
214 // https://dev.haiku-os.org/ticket/18810 in pcap_inject_haiku()
215 strlcpy(handle->errbuf, "Sending packets isn't supported yet", in pcap_inject_haiku()
222 pcap_stats_haiku(pcap_t *handle, struct pcap_stat *stats) in pcap_stats_haiku() argument
224 struct pcap_haiku* handlep = (struct pcap_haiku*)handle->priv; in pcap_stats_haiku()
225 *stats = handlep->stat; in pcap_stats_haiku()
228 if (ioctl_ifreq(handlep->aux_socket, SIOCGIFSTATS, "SIOCGIFSTATS", in pcap_stats_haiku()
229 &handlep->ifreq, handle->errbuf) < 0) in pcap_stats_haiku()
231 // The result is subject to wrapping around the 32-bit integer space, in pcap_stats_haiku()
233 // into a 32-bit member of pcap_stats. in pcap_stats_haiku()
234 stats->ps_ifdrop = handlep->ifreq.ifr_stats.receive.dropped - stats->ps_ifdrop; in pcap_stats_haiku()
240 pcap_activate_haiku(pcap_t *handle) in pcap_activate_haiku() argument
242 struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv; in pcap_activate_haiku()
246 if ((handlep->aux_socket = dgram_socket(AF_INET, handle->errbuf)) < 0) in pcap_activate_haiku()
252 if (ioctl_ifreq(handlep->aux_socket, SIOCGIFSTATS, "SIOCGIFSTATS", in pcap_activate_haiku()
253 &handlep->ifreq, handle->errbuf) < 0) { in pcap_activate_haiku()
254 // Detect a non-existent network interface at least at the in pcap_activate_haiku()
260 handlep->stat.ps_ifdrop = handlep->ifreq.ifr_stats.receive.dropped; in pcap_activate_haiku()
263 if ((handle->fd = dgram_socket(AF_LINK, handle->errbuf)) < 0) in pcap_activate_haiku()
271 if (ioctl_ifreq(handle->fd, SIOCGIFADDR, "SIOCGIFADDR", in pcap_activate_haiku()
272 &handlep->ifreq, handle->errbuf) < 0) in pcap_activate_haiku()
274 struct sockaddr_dl *sdl = (struct sockaddr_dl *)&handlep->ifreq.ifr_addr; in pcap_activate_haiku()
275 if (sdl->sdl_family != AF_LINK) { in pcap_activate_haiku()
276 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in pcap_activate_haiku()
278 sdl->sdl_family, handle->opt.device); in pcap_activate_haiku()
281 switch (sdl->sdl_type) { in pcap_activate_haiku()
285 handle->linktype = DLT_EN10MB; in pcap_activate_haiku()
293 // header until hrev57585: https://dev.haiku-os.org/ticket/18801 in pcap_activate_haiku()
294 handle->linktype = DLT_RAW; in pcap_activate_haiku()
297 snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, in pcap_activate_haiku()
299 sdl->sdl_type, handle->opt.device); in pcap_activate_haiku()
304 if (ioctl_ifreq(handle->fd, SIOCSPACKETCAP, "SIOCSPACKETCAP", in pcap_activate_haiku()
305 &handlep->ifreq, handle->errbuf) < 0) in pcap_activate_haiku()
308 handle->selectable_fd = handle->fd; in pcap_activate_haiku()
309 handle->read_op = pcap_read_haiku; in pcap_activate_haiku()
310 handle->setfilter_op = pcapint_install_bpf_program; /* no kernel filtering */ in pcap_activate_haiku()
311 handle->inject_op = pcap_inject_haiku; in pcap_activate_haiku()
312 handle->stats_op = pcap_stats_haiku; in pcap_activate_haiku()
313 handle->cleanup_op = pcap_cleanup_haiku; in pcap_activate_haiku()
316 handle->getnonblock_op = pcapint_getnonblock_fd; in pcap_activate_haiku()
317 handle->setnonblock_op = pcapint_setnonblock_fd; in pcap_activate_haiku()
327 if (handle->snapshot <= 0 || handle->snapshot > MAXIMUM_SNAPLEN) in pcap_activate_haiku()
328 handle->snapshot = MAXIMUM_SNAPLEN; in pcap_activate_haiku()
347 // if not all practical use cases, then pcap_read_haiku() can handle in pcap_activate_haiku()
349 handle->bufsize = 65536; in pcap_activate_haiku()
351 // allocate buffer for monitoring the device in pcap_activate_haiku()
352 handle->buffer = (u_char*)malloc(handle->bufsize); in pcap_activate_haiku()
353 if (handle->buffer == NULL) { in pcap_activate_haiku()
354 pcapint_fmt_errmsg_for_errno(handle->errbuf, PCAP_ERRBUF_SIZE, in pcap_activate_haiku()
359 if (handle->opt.promisc) { in pcap_activate_haiku()
362 if ((handlep->orig_promisc = get_promisc(handle)) < 0) in pcap_activate_haiku()
364 if (! handlep->orig_promisc && set_promisc(handle, 1) < 0) in pcap_activate_haiku()
369 pcap_cleanup_haiku(handle); in pcap_activate_haiku()
375 validate_ifname(const char *device, char *errbuf) in validate_ifname() argument
377 if (strlen(device) >= IF_NAMESIZE) { in validate_ifname()
379 "Interface name \"%s\" is too long.", device); in validate_ifname()
386 // #pragma mark - pcap API
401 // remove unsuitable well-known 64-bit versions (with or without in can_be_bound()
421 pcapint_create_interface(const char *device, char *errorBuffer) in pcapint_create_interface() argument
423 if (validate_ifname(device, errorBuffer) < 0) in pcapint_create_interface()
425 if (! can_be_bound(device)) { in pcapint_create_interface()
427 "Interface \"%s\" does not support capturing traffic.", device); in pcapint_create_interface()
431 pcap_t* handle = PCAP_CREATE_COMMON(errorBuffer, struct pcap_haiku); in pcapint_create_interface() local
432 if (handle == NULL) in pcapint_create_interface()
434 handle->activate_op = pcap_activate_haiku; in pcapint_create_interface()
436 struct pcap_haiku *handlep = (struct pcap_haiku *)handle->priv; in pcapint_create_interface()
437 handlep->aux_socket = -1; in pcapint_create_interface()
438 strcpy(handlep->ifreq.ifr_name, device); in pcapint_create_interface()
440 return handle; in pcapint_create_interface()