summaryrefslogtreecommitdiff
path: root/src/resolve/resolved-dns-packet.c
diff options
context:
space:
mode:
authorDaniel Mack <daniel@zonque.org>2015-07-11 16:21:26 -0400
committerDaniel Mack <daniel@zonque.org>2015-08-25 14:25:56 +0200
commit106784ebb7b303ae471851100a773ad2aebf5b80 (patch)
treee486bff2f465631ecd21bbc491dc79b1072b8dc5 /src/resolve/resolved-dns-packet.c
parent8326c7f789bad623a5705b04b78d104d993a90ee (diff)
resolved: use switch-case statements for protocol details
With more protocols to come, switch repetitive if-else blocks with a switch-case statements.
Diffstat (limited to 'src/resolve/resolved-dns-packet.c')
-rw-r--r--src/resolve/resolved-dns-packet.c43
1 files changed, 22 insertions, 21 deletions
diff --git a/src/resolve/resolved-dns-packet.c b/src/resolve/resolved-dns-packet.c
index bebd1ee4a6..784d949cce 100644
--- a/src/resolve/resolved-dns-packet.c
+++ b/src/resolve/resolved-dns-packet.c
@@ -64,7 +64,7 @@ int dns_packet_new(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
int dns_packet_new_query(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
DnsPacket *p;
DnsPacketHeader *h;
- int r;
+ int r, rd;
assert(ret);
@@ -74,26 +74,27 @@ int dns_packet_new_query(DnsPacket **ret, DnsProtocol protocol, size_t mtu) {
h = DNS_PACKET_HEADER(p);
- if (protocol == DNS_PROTOCOL_LLMNR)
- h->flags = htobe16(DNS_PACKET_MAKE_FLAGS(0 /* qr */,
- 0 /* opcode */,
- 0 /* c */,
- 0 /* tc */,
- 0 /* t */,
- 0 /* ra */,
- 0 /* ad */,
- 0 /* cd */,
- 0 /* rcode */));
- else
- h->flags = htobe16(DNS_PACKET_MAKE_FLAGS(0 /* qr */,
- 0 /* opcode */,
- 0 /* aa */,
- 0 /* tc */,
- 1 /* rd (ask for recursion) */,
- 0 /* ra */,
- 0 /* ad */,
- 0 /* cd */,
- 0 /* rcode */));
+ switch (protocol) {
+ case DNS_PROTOCOL_LLMNR:
+ /* no recursion for link-local resolving protocols */
+ rd = 0;
+ break;
+
+ default:
+ /* ask for recursion */
+ rd = 1;
+ break;
+ }
+
+ h->flags = htobe16(DNS_PACKET_MAKE_FLAGS(0 /* qr */,
+ 0 /* opcode */,
+ 0 /* aa */,
+ 0 /* tc */,
+ rd /* rd */,
+ 0 /* ra */,
+ 0 /* ad */,
+ 0 /* cd */,
+ 0 /* rcode */));
*ret = p;
return 0;