def send_dhcp_request_packet(
request: DHCPDiscoverPacket, ifname: str) -> None:
"""Sends out the specified DHCP discover packet to the given interface.
Optionally takes a `retry_call` to cancel if a fatal error occurs before
the first packet can be sent, such as inability to get a source IP
address.
"""
with udp_socket() as sock:
sock.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1)
mac = get_interface_mac(sock, ifname)
request.set_mac(mac)
bind_address = get_interface_ip(sock, ifname)
sock.bind((bind_address, BOOTP_CLIENT_PORT))
sock.sendto(request.packet, ('<broadcast>', BOOTP_SERVER_PORT))
# Packets will be sent at the following intervals (in seconds).
# The length of `DHCP_REQUEST_TIMING` indicates the number of packets
# that will be sent. The values should get progressively larger, to mimic
# the exponential back-off retry behavior of a real DHCP client.
评论列表
文章目录