chiark / gitweb /
sd-dhcp: rely on FIONREAD working
authorTom Gundersen <teg@jklm.no>
Wed, 21 May 2014 14:31:28 +0000 (16:31 +0200)
committerTom Gundersen <teg@jklm.no>
Wed, 21 May 2014 14:31:28 +0000 (16:31 +0200)
This fallback will anyway never get tested, so rip it out.

src/libsystemd-network/dhcp-protocol.h
src/libsystemd-network/sd-dhcp-client.c

index 260508fbbd2e402f6015a8f6c01f6584050acba2..4d87891ff1d84a69b2471a44333b8e858cae669f 100644 (file)
@@ -60,7 +60,7 @@ typedef struct DHCPPacket DHCPPacket;
 #define DHCP_IP_SIZE            (int32_t)(sizeof(struct iphdr))
 #define DHCP_IP_UDP_SIZE        (int32_t)(sizeof(struct udphdr) + DHCP_IP_SIZE)
 #define DHCP_MESSAGE_SIZE       (int32_t)(sizeof(DHCPMessage))
-#define DHCP_MIN_OPTIONS_SIZE   308
+#define DHCP_MIN_OPTIONS_SIZE   308 /* spec says 312, but that includes the magic cookie */
 #define DHCP_MAGIC_COOKIE       (uint32_t)(0x63825363)
 
 enum {
index ac97e007726b8cff69d1a0eb6241f570b83ae873..ba44069f662a4303b260b47c70ec339538fb07a0 100644 (file)
@@ -1186,8 +1186,12 @@ static int client_receive_message_udp(sd_event_source *s, int fd,
         assert(client);
 
         r = ioctl(fd, FIONREAD, &buflen);
-        if (r < 0 || buflen <= 0)
-                buflen = sizeof(DHCPMessage) + DHCP_MIN_OPTIONS_SIZE;
+        if (r < 0)
+                return r;
+
+        if (buflen < 0)
+                /* this can't be right */
+                return -EIO;
 
         message = malloc0(buflen);
         if (!message)
@@ -1224,8 +1228,12 @@ static int client_receive_message_raw(sd_event_source *s, int fd,
         assert(client);
 
         r = ioctl(fd, FIONREAD, &buflen);
-        if (r < 0 || buflen <= 0)
-                buflen = sizeof(DHCPPacket) + DHCP_MIN_OPTIONS_SIZE;
+        if (r < 0)
+                return r;
+
+        if (buflen < 0)
+                /* this can't be right */
+                return -EIO;
 
         packet = malloc0(buflen);
         if (!packet)