1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 00:47:45 +00:00

LookupServer: Remove some unnecessary "rc" temporaries

This commit is contained in:
Andreas Kling 2021-05-06 13:37:46 +02:00
parent f0629e29c9
commit 6024617df3

View file

@ -23,24 +23,21 @@ MulticastDNS::MulticastDNS(Object* parent)
, m_hostname("courage.local") , m_hostname("courage.local")
{ {
char buffer[HOST_NAME_MAX]; char buffer[HOST_NAME_MAX];
int rc = gethostname(buffer, sizeof(buffer)); if (gethostname(buffer, sizeof(buffer)) < 0) {
if (rc < 0) {
perror("gethostname"); perror("gethostname");
} else { } else {
m_hostname = String::formatted("{}.local", buffer); m_hostname = String::formatted("{}.local", buffer);
} }
u8 zero = 0; u8 zero = 0;
rc = setsockopt(fd(), IPPROTO_IP, IP_MULTICAST_LOOP, &zero, 1); if (setsockopt(fd(), IPPROTO_IP, IP_MULTICAST_LOOP, &zero, 1) < 0)
if (rc < 0)
perror("setsockopt(IP_MULTICAST_LOOP)"); perror("setsockopt(IP_MULTICAST_LOOP)");
ip_mreq mreq = { ip_mreq mreq = {
mdns_addr.sin_addr, mdns_addr.sin_addr,
{ htonl(INADDR_ANY) }, { htonl(INADDR_ANY) },
}; };
rc = setsockopt(fd(), IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)); if (setsockopt(fd(), IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(mreq)) < 0)
if (rc < 0) perror("setsockopt(IP_ADD_MEMBERSHIP)");
perror("setsockopt(IP_ADD_MEMBESHIP)");
bind(IPv4Address(), 5353); bind(IPv4Address(), 5353);
@ -98,8 +95,7 @@ void MulticastDNS::announce()
response.add_answer(answer); response.add_answer(answer);
} }
int rc = emit_packet(response); if (emit_packet(response) < 0)
if (rc < 0)
perror("Failed to emit response packet"); perror("Failed to emit response packet");
} }
@ -147,8 +143,7 @@ Vector<DNSAnswer> MulticastDNS::lookup(const DNSName& name, unsigned short recor
request.set_is_query(); request.set_is_query();
request.add_question({ name, record_type, C_IN }); request.add_question({ name, record_type, C_IN });
int rc = emit_packet(request); if (emit_packet(request) < 0) {
if (rc < 0) {
perror("failed to emit request packet"); perror("failed to emit request packet");
return {}; return {};
} }
@ -159,7 +154,7 @@ Vector<DNSAnswer> MulticastDNS::lookup(const DNSName& name, unsigned short recor
// the main loop while we wait for a response. // the main loop while we wait for a response.
while (true) { while (true) {
pollfd pfd { fd(), POLLIN, 0 }; pollfd pfd { fd(), POLLIN, 0 };
rc = poll(&pfd, 1, 1000); auto rc = poll(&pfd, 1, 1000);
if (rc < 0) { if (rc < 0) {
perror("poll"); perror("poll");
} else if (rc == 0) { } else if (rc == 0) {