mirror of
https://github.com/pi-hole/dnsmasq.git
synced 2025-12-19 10:18:25 +00:00
Make the packet-dump code work with a FIFO.
mkfifo /tmp/dnsmasq.pipe dnsmasq --dumpfile=/tmp/dnsmasq.pipe .... wireshark -i /tmp/dnsmasq.pipe gives real-time display of network traffic in Wireshark.
This commit is contained in:
@@ -781,7 +781,7 @@ The address range can be of the form
|
|||||||
must fall in the same /64 network, or prefix-length must be greater than or equal to 64 except that shorter prefix lengths than 64 are allowed only if non-sequential names are in use.
|
must fall in the same /64 network, or prefix-length must be greater than or equal to 64 except that shorter prefix lengths than 64 are allowed only if non-sequential names are in use.
|
||||||
.TP
|
.TP
|
||||||
.B --dumpfile=<path/to/file>
|
.B --dumpfile=<path/to/file>
|
||||||
Specify the location of a pcap-format file which dnsmasq uses to dump copies of network packets for debugging purposes. If the file exists when dnsmasq starts, it is not deleted; new packets are added to the end.
|
Specify the location of a pcap-format file which dnsmasq uses to dump copies of network packets for debugging purposes. If the file exists when dnsmasq starts, it is not deleted; new packets are added to the end. The file may be a named-pipe which Wireshark is listening to.
|
||||||
.TP
|
.TP
|
||||||
.B --dumpmask=<mask>
|
.B --dumpmask=<mask>
|
||||||
Specify which types of packets should be added to the dumpfile. The argument should be the OR of the bitmasks for each type of packet to be dumped: it can be specified in hex by preceding the number with 0x in the normal way. Each time a packet is written to the dumpfile, dnsmasq logs the packet sequence and the mask
|
Specify which types of packets should be added to the dumpfile. The argument should be the OR of the bitmasks for each type of packet to be dumped: it can be specified in hex by preceding the number with 0x in the normal way. Each time a packet is written to the dumpfile, dnsmasq logs the packet sequence and the mask
|
||||||
|
|||||||
14
src/dump.c
14
src/dump.c
@@ -51,9 +51,6 @@ void dump_init(void)
|
|||||||
|
|
||||||
packet_count = 0;
|
packet_count = 0;
|
||||||
|
|
||||||
if (stat(daemon->dump_file, &buf) == -1)
|
|
||||||
{
|
|
||||||
/* doesn't exist, create and add header */
|
|
||||||
header.magic_number = 0xa1b2c3d4;
|
header.magic_number = 0xa1b2c3d4;
|
||||||
header.version_major = 2;
|
header.version_major = 2;
|
||||||
header.version_minor = 4;
|
header.version_minor = 4;
|
||||||
@@ -62,11 +59,22 @@ void dump_init(void)
|
|||||||
header.snaplen = daemon->edns_pktsz + 200; /* slop for IP/UDP headers */
|
header.snaplen = daemon->edns_pktsz + 200; /* slop for IP/UDP headers */
|
||||||
header.network = 101; /* DLT_RAW http://www.tcpdump.org/linktypes.html */
|
header.network = 101; /* DLT_RAW http://www.tcpdump.org/linktypes.html */
|
||||||
|
|
||||||
|
if (stat(daemon->dump_file, &buf) == -1)
|
||||||
|
{
|
||||||
|
/* doesn't exist, create and add header */
|
||||||
if (errno != ENOENT ||
|
if (errno != ENOENT ||
|
||||||
(daemon->dumpfd = creat(daemon->dump_file, S_IRUSR | S_IWUSR)) == -1 ||
|
(daemon->dumpfd = creat(daemon->dump_file, S_IRUSR | S_IWUSR)) == -1 ||
|
||||||
!read_write(daemon->dumpfd, (void *)&header, sizeof(header), RW_WRITE))
|
!read_write(daemon->dumpfd, (void *)&header, sizeof(header), RW_WRITE))
|
||||||
die(_("cannot create %s: %s"), daemon->dump_file, EC_FILE);
|
die(_("cannot create %s: %s"), daemon->dump_file, EC_FILE);
|
||||||
}
|
}
|
||||||
|
else if (S_ISFIFO(buf.st_mode))
|
||||||
|
{
|
||||||
|
/* File is named pipe (with wireshark on the other end, probably.)
|
||||||
|
Send header. */
|
||||||
|
if ((daemon->dumpfd = open(daemon->dump_file, O_APPEND | O_RDWR)) == -1 ||
|
||||||
|
!read_write(daemon->dumpfd, (void *)&header, sizeof(header), RW_WRITE))
|
||||||
|
die(_("cannot open pipe %s: %s"), daemon->dump_file, EC_FILE);
|
||||||
|
}
|
||||||
else if ((daemon->dumpfd = open(daemon->dump_file, O_APPEND | O_RDWR)) == -1 ||
|
else if ((daemon->dumpfd = open(daemon->dump_file, O_APPEND | O_RDWR)) == -1 ||
|
||||||
!read_write(daemon->dumpfd, (void *)&header, sizeof(header), RW_READ))
|
!read_write(daemon->dumpfd, (void *)&header, sizeof(header), RW_READ))
|
||||||
die(_("cannot access %s: %s"), daemon->dump_file, EC_FILE);
|
die(_("cannot access %s: %s"), daemon->dump_file, EC_FILE);
|
||||||
|
|||||||
Reference in New Issue
Block a user