int dhcpd_sendack(in_addr_t ipaddr) { uint32_t leasetime = CONFIG_NETUTILS_DHCPD_LEASETIME; in_addr_t netaddr; #ifdef HAVE_DSNIP uint32_t dnsaddr; dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP); #endif /* Initialize the ACK response */ dhcpd_initpacket(DHCPACK); memcpy(g_state.ds_outpacket.ciaddr, g_state.ds_inpacket.ciaddr, 4); /* Add the IP address assigned to the client */ netaddr = htonl(ipaddr); memcpy(g_state.ds_outpacket.yiaddr, &netaddr, 4); /* Did the client request a specific lease time? */ (void)dhcpd_verifyreqleasetime(&leasetime); /* Add the lease time to the response */ dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); #ifdef HAVE_NETMASK dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, htonl(CONFIG_NETUTILS_DHCPD_NETMASK)); #endif #ifdef HAVE_ROUTERIP dhcpd_addoption32(DHCP_OPTION_ROUTER, htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP)); #endif #ifdef HAVE_DSNIP dhcp_addoption32p(DHCP_OPTION_DNS_SERVER, (FAR uint8_t*)&dnsaddr); #endif #ifdef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST if (dhcpd_sendpacket(true) < 0) #else if (dhcpd_sendpacket(false) < 0) #endif { return ERROR; } dhcpd_setlease(g_state.ds_inpacket.chaddr, ipaddr, leasetime); return OK; }
static void dhcpd_initpacket(uint8_t mtype) { uint32_t nulladdr = 0; /* Set up the generic parts of the DHCP server message */ memset(&g_state.ds_outpacket, 0, sizeof(struct dhcpmsg_s)); g_state.ds_outpacket.op = DHCP_REPLY; g_state.ds_outpacket.htype = g_state.ds_inpacket.htype; g_state.ds_outpacket.hlen = g_state.ds_inpacket.hlen; memcpy(&g_state.ds_outpacket.xid, &g_state.ds_inpacket.xid, 4); memcpy(g_state.ds_outpacket.chaddr, g_state.ds_inpacket.chaddr, 16); if (memcmp(g_state.ds_outpacket.giaddr, &nulladdr, 4) != 0) { g_state.ds_outpacket.flags = g_state.ds_inpacket.flags; } else { g_state.ds_outpacket.flags = 0; } memset(g_state.ds_outpacket.giaddr, 0, 4); /* Add the generic options */ memcpy(g_state.ds_outpacket.options, g_magiccookie, 4); g_state.ds_optend = &g_state.ds_outpacket.options[4]; *g_state.ds_optend = DHCP_OPTION_END; dhcpd_addoption8(DHCP_OPTION_MSG_TYPE, mtype); dhcpd_addoption32(DHCP_OPTION_SERVER_ID, g_state.ds_serverip); }
int dhcpd_sendack(in_addr_t ipaddr) { uint32_t leasetime = CONFIG_NETUTILS_DHCPD_LEASETIME; in_addr_t netaddr; /* Initialize the ACK response */ dhcpd_initpacket(DHCPACK); memcpy(g_state.ds_outpacket.ciaddr, g_state.ds_inpacket.ciaddr, 4); /* Add the IP address assigned to the client */ netaddr = htonl(ipaddr); memcpy(g_state.ds_outpacket.yiaddr, &netaddr, 4); /* Did the client request a specific lease time? */ (void)dhcpd_verifyreqleasetime(&leasetime); /* Add the lease time to the response */ dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); #ifdef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST if (dhcpd_sendpacket(true) < 0) #else if (dhcpd_sendpacket(false) < 0) #endif { return ERROR; } dhcpd_setlease(g_state.ds_inpacket.chaddr, ipaddr, leasetime); return OK; }
static inline int dhcpd_sendoffer(in_addr_t ipaddr, uint32_t leasetime) { in_addr_t netaddr; /* IP address is in host order */ nvdbg("Sending offer: %08lx\n", (long)ipaddr); /* Initialize the outgoing packet */ dhcpd_initpacket(DHCPOFFER); /* Add the address offered to the client (converting to network order) */ netaddr = htonl(ipaddr); memcpy(g_state.ds_outpacket.yiaddr, &netaddr, 4); /* Add the leasetime to the response options */ dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); /* Send the offer response */ #ifdef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST return dhcpd_sendpacket(true); #else return dhcpd_sendpacket(false); #endif }
static inline int dhcpd_sendoffer(in_addr_t ipaddr, uint32_t leasetime) { in_addr_t netaddr; #ifdef HAVE_DSNIP uint32_t dnsaddr; dnsaddr = htonl(CONFIG_NETUTILS_DHCPD_DNSIP); #endif /* IP address is in host order */ nvdbg("Sending offer: %08lx\n", (long)ipaddr); /* Initialize the outgoing packet */ dhcpd_initpacket(DHCPOFFER); /* Add the address offered to the client (converting to network order) */ netaddr = htonl(ipaddr); memcpy(g_state.ds_outpacket.yiaddr, &netaddr, 4); /* Add the leasetime to the response options */ dhcpd_addoption32(DHCP_OPTION_LEASE_TIME, htonl(leasetime)); #ifdef HAVE_NETMASK dhcpd_addoption32(DHCP_OPTION_SUBNET_MASK, htonl(CONFIG_NETUTILS_DHCPD_NETMASK)); #endif #ifdef HAVE_ROUTERIP dhcpd_addoption32(DHCP_OPTION_ROUTER, htonl(CONFIG_NETUTILS_DHCPD_ROUTERIP)); #endif #ifdef HAVE_DSNIP dhcp_addoption32p(DHCP_OPTION_DNS_SERVER, (FAR uint8_t*)&dnsaddr); #endif /* Send the offer response */ #ifdef CONFIG_NETUTILS_DHCPD_IGNOREBROADCAST return dhcpd_sendpacket(true); #else return dhcpd_sendpacket(false); #endif }