Skip to content

Commit

Permalink
dhcpclient: Start on boot
Browse files Browse the repository at this point in the history
  • Loading branch information
byteduck committed Mar 21, 2024
1 parent 36fce17 commit 2a31c8f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
4 changes: 4 additions & 0 deletions base/etc/init/services/dhcpclient.service
@@ -0,0 +1,4 @@
[service]
name=DHCP Client
exec=dhcpclient
after=boot
9 changes: 9 additions & 0 deletions services/dhcpclient/Client.cpp
Expand Up @@ -59,6 +59,9 @@ Client::Client(int socket, std::vector<Interface> interfaces):
}

void Client::loop() {
if (m_interfaces.empty())
return;

for (auto& interface : m_interfaces)
discover(interface);

Expand Down Expand Up @@ -90,6 +93,7 @@ void Client::loop() {
switch (type.value()) {
case Ack:
res = do_ack(buf);
return; // TODO: For now, we don't renew leases or anything so might as well exit
break;

case Offer:
Expand Down Expand Up @@ -186,6 +190,11 @@ Duck::Result Client::setup_interface(const Client::Interface& interface, const I
ifreq req;
strncpy(req.ifr_name, interface.name.c_str(), IFNAMSIZ);

if (gateway.has_value())
Duck::Log::infof("Setting up {} as {} with subnet {} and gateway {}", interface.name, addr, subnet, gateway.value());
else
Duck::Log::infof("Setting up {} as {} with subnet {}", interface.name, addr, subnet);

// Set IP
*((sockaddr_in*) &req.ifr_addr) = addr.as_sockaddr(0);
if (ioctl(sockid, SIOCSIFADDR, &req) < 0) {
Expand Down

0 comments on commit 2a31c8f

Please sign in to comment.