mirror of
https://github.com/RGBCube/serenity
synced 2025-07-25 16:07:47 +00:00
DHCPClient: Log errors and cleanup the code
Prior to this, we ran the DHCP client as a high-priority service, but making the system feel laggy "for some network stuff" is not the greatest of ideas :^)
This commit is contained in:
parent
bf62625001
commit
3ab6c5fd09
2 changed files with 8 additions and 8 deletions
|
@ -21,7 +21,7 @@ KeepAlive=1
|
||||||
User=lookup
|
User=lookup
|
||||||
|
|
||||||
[DHCPClient]
|
[DHCPClient]
|
||||||
Priority=high
|
Priority=low
|
||||||
KeepAlive=1
|
KeepAlive=1
|
||||||
User=root
|
User=root
|
||||||
|
|
||||||
|
|
|
@ -37,12 +37,12 @@ static void send(const InterfaceDescriptor& iface, const DHCPv4Packet& packet, C
|
||||||
{
|
{
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
dbg() << "ERROR: socket";
|
dbg() << "ERROR: socket :: " << strerror(errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface.m_ifname.characters(), IFNAMSIZ) < 0) {
|
if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, iface.m_ifname.characters(), IFNAMSIZ) < 0) {
|
||||||
dbg() << "ERROR from setsockopt(SO_BINDTODEVICE): " << strerror(errno);
|
dbg() << "ERROR: setsockopt(SO_BINDTODEVICE) :: " << strerror(errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4
|
||||||
{
|
{
|
||||||
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
int fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_IP);
|
||||||
if (fd < 0) {
|
if (fd < 0) {
|
||||||
dbg() << "ERROR: socket";
|
dbg() << "ERROR: socket :: " << strerror(errno);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -77,14 +77,14 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4
|
||||||
((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr = ipv4_addr.to_in_addr_t();
|
((sockaddr_in&)ifr.ifr_addr).sin_addr.s_addr = ipv4_addr.to_in_addr_t();
|
||||||
|
|
||||||
if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) {
|
if (ioctl(fd, SIOCSIFADDR, &ifr) < 0) {
|
||||||
dbg() << "ERROR: ioctl(SIOCSIFADDR)";
|
dbg() << "ERROR: ioctl(SIOCSIFADDR) :: " << strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the network mask
|
// set the network mask
|
||||||
((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr = netmask.to_in_addr_t();
|
((sockaddr_in&)ifr.ifr_netmask).sin_addr.s_addr = netmask.to_in_addr_t();
|
||||||
|
|
||||||
if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) {
|
if (ioctl(fd, SIOCSIFNETMASK, &ifr) < 0) {
|
||||||
dbg() << "ERROR: ioctl(SIOCSIFADDR)";
|
dbg() << "ERROR: ioctl(SIOCSIFNETMASK) :: " << strerror(errno);
|
||||||
}
|
}
|
||||||
|
|
||||||
// set the default gateway
|
// set the default gateway
|
||||||
|
@ -97,7 +97,7 @@ static void set_params(const InterfaceDescriptor& iface, const IPv4Address& ipv4
|
||||||
rt.rt_flags = RTF_UP | RTF_GATEWAY;
|
rt.rt_flags = RTF_UP | RTF_GATEWAY;
|
||||||
|
|
||||||
if (ioctl(fd, SIOCADDRT, &rt) < 0) {
|
if (ioctl(fd, SIOCADDRT, &rt) < 0) {
|
||||||
dbg() << "Error: ioctl(SIOCADDRT)";
|
dbg() << "Error: ioctl(SIOCADDRT) :: " << strerror(errno);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -277,7 +277,7 @@ void DHCPv4Client::dhcp_request(DHCPv4Transaction& transaction, const DHCPv4Pack
|
||||||
builder.set_message_type(DHCPMessageType::DHCPRequest);
|
builder.set_message_type(DHCPMessageType::DHCPRequest);
|
||||||
auto& dhcp_packet = builder.build();
|
auto& dhcp_packet = builder.build();
|
||||||
|
|
||||||
// broadcast the discover request
|
// broadcast the "request" request
|
||||||
send(iface, dhcp_packet, this);
|
send(iface, dhcp_packet, this);
|
||||||
transaction.accepted_offer = true;
|
transaction.accepted_offer = true;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue