MCPcopy Index your code
hub / github.com/secdev/scapy / make_reply

Method make_reply

scapy/layers/dns.py:1694–1912  ·  view source on GitHub ↗
(self, req)

Source from the content-addressed store, hash-verified

1692 )
1693
1694 def make_reply(self, req):
1695 # Build reply from the request
1696 resp = req.copy()
1697 if Ether in req:
1698 if self.mDNS:
1699 resp[Ether].src, resp[Ether].dst = None, None
1700 elif self.llmnr:
1701 resp[Ether].src, resp[Ether].dst = None, req[Ether].src
1702 else:
1703 resp[Ether].src, resp[Ether].dst = (
1704 None if req[Ether].dst == "ff:ff:ff:ff:ff:ff" else req[Ether].dst,
1705 req[Ether].src,
1706 )
1707 from scapy.layers.inet6 import IPv6
1708 if IPv6 in req:
1709 resp[IPv6].underlayer.remove_payload()
1710 if self.mDNS:
1711 # "All Multicast DNS responses (including responses sent via unicast)
1712 # SHOULD be sent with IP TTL set to 255."
1713 resp /= IPv6(dst="ff02::fb", src=self.src_ip6,
1714 fl=req[IPv6].fl, hlim=255)
1715 elif self.llmnr:
1716 resp /= IPv6(dst=req[IPv6].src, src=self.src_ip6,
1717 fl=req[IPv6].fl, hlim=req[IPv6].hlim)
1718 else:
1719 resp /= IPv6(dst=req[IPv6].src, src=self.src_ip6 or req[IPv6].dst,
1720 fl=req[IPv6].fl, hlim=req[IPv6].hlim)
1721 elif IP in req:
1722 resp[IP].underlayer.remove_payload()
1723 if self.mDNS:
1724 # "All Multicast DNS responses (including responses sent via unicast)
1725 # SHOULD be sent with IP TTL set to 255."
1726 resp /= IP(dst="224.0.0.251", src=self.src_ip,
1727 id=req[IP].id, ttl=255)
1728 elif self.llmnr:
1729 resp /= IP(dst=req[IP].src, src=self.src_ip,
1730 id=req[IP].id, ttl=req[IP].ttl)
1731 else:
1732 resp /= IP(dst=req[IP].src, src=self.src_ip or req[IP].dst,
1733 id=req[IP].id, ttl=req[IP].ttl)
1734 else:
1735 warning("No IP or IPv6 layer in %s", req.command())
1736 return
1737 try:
1738 resp /= UDP(sport=req[UDP].dport, dport=req[UDP].sport)
1739 except IndexError:
1740 warning("No UDP layer in %s", req.command(), exc_info=True)
1741 return
1742 try:
1743 req = req[self.cls]
1744 except IndexError:
1745 warning(
1746 "No %s layer in %s",
1747 self.cls.__name__,
1748 req.command(),
1749 exc_info=True,
1750 )
1751 return

Callers

nothing calls this directly

Calls 15

IPv6Class · 0.90
IPClass · 0.90
warningFunction · 0.90
UDPClass · 0.90
resolve_ifaceFunction · 0.90
get_if_addr6Function · 0.90
get_if_addrFunction · 0.90
DNSQRClass · 0.85
DNSRRClass · 0.85
DNSRRSRVClass · 0.85
dns_resolveFunction · 0.85
DNSRRNSECClass · 0.85

Tested by

no test coverage detected