Home | History | Annotate | Download | only in libpcap

Lines Matching refs:handle

85 static int nfqueue_send_verdict(const pcap_t *handle, u_int16_t group_id, u_int32_t id, u_int32_t verdict);
89 netfilter_read_linux(pcap_t *handle, int max_packets, pcap_handler callback, u_char *user)
91 struct pcap_netfilter *handlep = handle->priv;
98 len = recv(handle->fd, handle->buffer, handle->bufsize, 0);
99 if (handle->break_loop) {
100 handle->break_loop = 0;
107 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't receive packet %d:%s", errno, pcap_strerror(errno));
111 buf = (unsigned char *)handle->buffer;
118 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Message truncated: (got: %d) (nlmsg_len: %u)", len, nlh->nlmsg_len);
136 if (handle->linktype != DLT_NFLOG) {
140 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Malformed message: (nlmsg_len: %u)", nlh->nlmsg_len);
186 /* pkth.caplen = min (payload_len, handle->snapshot); */
189 if (handle->fcode.bf_insns == NULL ||
190 bpf_filter(handle->fcode.bf_insns, payload, pkth.len, pkth.caplen))
200 /* if type == NFQUEUE, handle->linktype is always != DLT_NFLOG,
203 nfqueue_send_verdict(handle, ntohs(nfg->res_id), id, NF_ACCEPT);
218 netfilter_set_datalink(pcap_t *handle, int dlt)
220 handle->linktype = dlt;
225 netfilter_stats_linux(pcap_t *handle, struct pcap_stat *stats)
227 struct pcap_netfilter *handlep = handle->priv;
236 netfilter_inject_linux(pcap_t *handle, const void *buf, size_t size)
238 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "inject not supported on netfilter devices");
249 netfilter_send_config_msg(const pcap_t *handle, u_int16_t msg_type, int ack, u_int8_t family, u_int16_t res_id, const struct my_nfattr *mynfa)
285 if (sendto(handle->fd, nlh, nlh->nlmsg_len, 0, (struct sockaddr *) &snl, sizeof(snl)) == -1)
298 len = recvfrom(handle->fd, buf, sizeof(buf), 0, (struct sockaddr *) &snl, &addrlen);
330 nflog_send_config_msg(const pcap_t *handle, u_int8_t family, u_int16_t group_id, const struct my_nfattr *mynfa)
332 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_ULOG << 8) | NFULNL_MSG_CONFIG, 1, family, group_id, mynfa);
336 nflog_send_config_cmd(const pcap_t *handle, u_int16_t group_id, u_int8_t cmd, u_int8_t family)
347 return nflog_send_config_msg(handle, family, group_id, &nfa);
351 nflog_send_config_mode(const pcap_t *handle, u_int16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
363 return nflog_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
367 nfqueue_send_verdict(const pcap_t *handle, u_int16_t group_id, u_int32_t id, u_int32_t verdict)
379 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_VERDICT, 0, AF_UNSPEC, group_id, &nfa);
383 nfqueue_send_config_msg(const pcap_t *handle, u_int8_t family, u_int16_t group_id, const struct my_nfattr *mynfa)
385 return netfilter_send_config_msg(handle, (NFNL_SUBSYS_QUEUE << 8) | NFQNL_MSG_CONFIG, 1, family, group_id, mynfa);
389 nfqueue_send_config_cmd(const pcap_t *handle, u_int16_t group_id, u_int8_t cmd, u_int16_t pf)
401 return nfqueue_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
405 nfqueue_send_config_mode(const pcap_t *handle, u_int16_t group_id, u_int8_t copy_mode, u_int32_t copy_range)
417 return nfqueue_send_config_msg(handle, AF_UNSPEC, group_id, &nfa);
421 netfilter_activate(pcap_t* handle)
423 const char *dev = handle->opt.device;
445 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
447 handle->opt.device);
454 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
470 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE,
472 handle->opt.device);
483 handle->bufsize = 128 + handle->snapshot;
484 handle->offset = 0;
485 handle->read_op = netfilter_read_linux;
486 handle->inject_op = netfilter_inject_linux;
487 handle->setfilter_op = install_bpf_program; /* no kernel filtering */
488 handle->setdirection_op = NULL;
489 handle->set_datalink_op = netfilter_set_datalink;
490 handle->getnonblock_op = pcap_getnonblock_fd;
491 handle->setnonblock_op = pcap_setnonblock_fd;
492 handle->stats_op = netfilter_stats_linux;
495 handle->fd = socket(AF_NETLINK, SOCK_RAW, NETLINK_NETFILTER);
496 if (handle->fd < 0) {
497 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't create raw socket %d:%s", errno, pcap_strerror(errno));
502 handle->linktype = DLT_NFLOG;
503 handle->dlt_list = (u_int *) malloc(sizeof(u_int) * 2);
504 if (handle->dlt_list != NULL) {
505 handle->dlt_list[0] = DLT_NFLOG;
506 handle->dlt_list[1] = DLT_IPV4;
507 handle->dlt_count = 2;
511 handle->linktype = DLT_IPV4;
513 handle->buffer = malloc(handle->bufsize);
514 if (!handle->buffer) {
515 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't allocate dump buffer: %s", pcap_strerror(errno));
520 if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
521 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFULNL_CFG_CMD_PF_UNBIND: %s", pcap_strerror(errno));
525 if (nflog_send_config_cmd(handle, 0, NFULNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
526 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFULNL_CFG_CMD_PF_BIND: %s", pcap_strerror(errno));
532 if (nflog_send_config_cmd(handle, groups[i], NFULNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
533 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't listen on group group index: %s", pcap_strerror(errno));
537 if (nflog_send_config_mode(handle, groups[i], NFULNL_COPY_PACKET, handle->snapshot) < 0) {
538 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFULNL_COPY_PACKET: %s", pcap_strerror(errno));
544 if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_UNBIND, AF_INET) < 0) {
545 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFQNL_CFG_CMD_PF_UNBIND: %s", pcap_strerror(errno));
549 if (nfqueue_send_config_cmd(handle, 0, NFQNL_CFG_CMD_PF_BIND, AF_INET) < 0) {
550 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFQNL_CFG_CMD_PF_BIND: %s", pcap_strerror(errno));
556 if (nfqueue_send_config_cmd(handle, groups[i], NFQNL_CFG_CMD_BIND, AF_UNSPEC) < 0) {
557 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "Can't listen on group group index: %s", pcap_strerror(errno));
561 if (nfqueue_send_config_mode(handle, groups[i], NFQNL_COPY_PACKET, handle->snapshot) < 0) {
562 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "NFQNL_COPY_PACKET: %s", pcap_strerror(errno));
568 if (handle
572 pcap_cleanup_live_common(handle);
576 if (handle->opt.buffer_size != 0) {
580 if (setsockopt(handle->fd, SOL_SOCKET, SO_RCVBUF, &handle->opt.buffer_size, sizeof(handle->opt.buffer_size)) == -1) {
581 pcap_snprintf(handle->errbuf, PCAP_ERRBUF_SIZE, "SO_RCVBUF: %s", pcap_strerror(errno));
586 handle->selectable_fd = handle->fd;
590 pcap_cleanup_live_common(handle);