+ /* FIXME: It may be possible to run off the end of a packet here /if/
+ * it's malformed. :( */
+ while (options[i] != DHCP_END) {
+ __u8 tag = options[i++], len;
+ __u32 value;
+
+ if (tag == DHCP_PAD)
+ continue;
+
+ len = options[i++];
+ memcpy(&value, &options[i], len);
+
+#if DEBUG
+{
+ DEBUG_F("tag=%2d, len=%2d, data=", tag, len);
+ int j;
+ for (j=0; j<len; j++)
+ prom_printf("%02x", options[i+j]);
+ prom_printf("\n");
+}
+#endif
+
+ switch (tag) {
+ case DHCP_NETMASK:
+ /* FIXME: do we need to grok the subnet mask? */
+ break;
+ case DHCP_ROUTERS:
+ if ((result->giaddr == NULL || *(result->giaddr) == '\x0')
+ && value != 0) {
+ result->giaddr = ipv4_to_str(value);
+ DEBUG_F("Storing %s as gateway from options\n",
+ result->giaddr);
+ }
+ break;
+ }
+ i += len;
+ }
+}
+
+/*
+ * Check netinfo for ipv4 parameters and add them to the fspec iff the
+ * fspec has no existing value.
+ *
+ * Returns 1 on success, 0 on failure.
+ */
+static int
+extract_netinfo_args(struct boot_fspec_t *result)
+{
+ struct bootp_packet *packet;
+
+ /* Check to see if we can get the [scyg]iaddr fields from netinfo */
+ packet = prom_get_netinfo();
+ if (!packet)
+ return 0;
+
+ DEBUG_F("We have a boot packet\n");
+ DEBUG_F(" siaddr = <%x>\n", packet->siaddr);
+ DEBUG_F(" ciaddr = <%x>\n", packet->ciaddr);
+ DEBUG_F(" yiaddr = <%x>\n", packet->yiaddr);
+ DEBUG_F(" giaddr = <%x>\n", packet->giaddr);
+
+ /* Try to fallback to yiaddr if ciaddr is empty. Broken? */
+ if (packet->ciaddr == 0 && packet->yiaddr != 0)
+ packet->ciaddr = packet->yiaddr;
+
+ if ((result->siaddr == NULL || *(result->siaddr) == '\x0')
+ && packet->siaddr != 0)
+ result->siaddr = ipv4_to_str(packet->siaddr);
+ if ((result->ciaddr == NULL || *(result->ciaddr) == '\x0')
+ && packet->ciaddr != 0)
+ result->ciaddr = ipv4_to_str(packet->ciaddr);
+ if ((result->giaddr == NULL || *(result->giaddr) == '\x0')
+ && packet->giaddr != 0)
+ result->giaddr = ipv4_to_str(packet->giaddr);
+
+ extract_vendor_options(packet, result);
+
+ /* FIXME: Yck! if we /still/ do not have a gateway then "cheat" and use
+ * the server. This will be okay if the client and server are on
+ * the same IP network, if not then lets hope the server does ICMP
+ * redirections */
+ if (result->giaddr == NULL) {
+ result->giaddr = ipv4_to_str(packet->siaddr);
+ DEBUG_F("Forcing giaddr to siaddr <%s>\n", result->giaddr);
+ }
+
+ return 1;
+}