dhcp.c: Make init_packet() not return a struct.
Just work via a pointer to not rely on the compiler being intelligent and inlining.
This commit is contained in:
		
							
								
								
									
										41
									
								
								src/dhcp.c
									
									
									
									
									
								
							
							
						
						
									
										41
									
								
								src/dhcp.c
									
									
									
									
									
								
							| @@ -418,26 +418,23 @@ void handle_packet(struct client_state_t cs[static 1]) | |||||||
| } | } | ||||||
|  |  | ||||||
| // Initialize a DHCP client packet that will be sent to a server | // Initialize a DHCP client packet that will be sent to a server | ||||||
| static struct dhcpmsg init_packet(char type, uint32_t xid) | static void init_packet(struct dhcpmsg packet[static 1], char type) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = { |     packet->op = 1; // BOOTREQUEST (client) | ||||||
|         .op = 1, // BOOTREQUEST (client) |     packet->htype = 1; // ETH_10MB | ||||||
|         .htype = 1, // ETH_10MB |     packet->hlen = 6; // ETH_10MB_LEN | ||||||
|         .hlen = 6, // ETH_10MB_LEN |     packet->cookie = htonl(DHCP_MAGIC); | ||||||
|         .cookie = htonl(DHCP_MAGIC), |     packet->options[0] = DCODE_END; | ||||||
|         .options[0] = DCODE_END, |     add_option_msgtype(packet, type); | ||||||
|         .xid = xid, |     memcpy(packet->chaddr, client_config.arp, 6); | ||||||
|     }; |     add_option_clientid(packet, client_config.clientid, | ||||||
|     add_option_msgtype(&packet, type); |  | ||||||
|     memcpy(packet.chaddr, client_config.arp, 6); |  | ||||||
|     add_option_clientid(&packet, client_config.clientid, |  | ||||||
|                         client_config.clientid_len); |                         client_config.clientid_len); | ||||||
|     return packet; |  | ||||||
| } | } | ||||||
|  |  | ||||||
| ssize_t send_discover(struct client_state_t cs[static 1]) | ssize_t send_discover(struct client_state_t cs[static 1]) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = init_packet(DHCPDISCOVER, cs->xid); |     struct dhcpmsg packet = {.xid = cs->xid}; | ||||||
|  |     init_packet(&packet, DHCPDISCOVER); | ||||||
|     if (cs->clientAddr) |     if (cs->clientAddr) | ||||||
|         add_option_reqip(&packet, cs->clientAddr); |         add_option_reqip(&packet, cs->clientAddr); | ||||||
|     add_option_maxsize(&packet); |     add_option_maxsize(&packet); | ||||||
| @@ -451,7 +448,8 @@ ssize_t send_discover(struct client_state_t cs[static 1]) | |||||||
| ssize_t send_selecting(struct client_state_t cs[static 1]) | ssize_t send_selecting(struct client_state_t cs[static 1]) | ||||||
| { | { | ||||||
|     char clibuf[INET_ADDRSTRLEN]; |     char clibuf[INET_ADDRSTRLEN]; | ||||||
|     struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid); |     struct dhcpmsg packet = {.xid = cs->xid}; | ||||||
|  |     init_packet(&packet, DHCPREQUEST); | ||||||
|     add_option_reqip(&packet, cs->clientAddr); |     add_option_reqip(&packet, cs->clientAddr); | ||||||
|     add_option_serverid(&packet, cs->serverAddr); |     add_option_serverid(&packet, cs->serverAddr); | ||||||
|     add_option_maxsize(&packet); |     add_option_maxsize(&packet); | ||||||
| @@ -467,7 +465,8 @@ ssize_t send_selecting(struct client_state_t cs[static 1]) | |||||||
|  |  | ||||||
| ssize_t send_renew(struct client_state_t cs[static 1]) | ssize_t send_renew(struct client_state_t cs[static 1]) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid); |     struct dhcpmsg packet = {.xid = cs->xid}; | ||||||
|  |     init_packet(&packet, DHCPREQUEST); | ||||||
|     packet.ciaddr = cs->clientAddr; |     packet.ciaddr = cs->clientAddr; | ||||||
|     add_option_maxsize(&packet); |     add_option_maxsize(&packet); | ||||||
|     add_option_request_list(&packet); |     add_option_request_list(&packet); | ||||||
| @@ -479,7 +478,8 @@ ssize_t send_renew(struct client_state_t cs[static 1]) | |||||||
|  |  | ||||||
| ssize_t send_rebind(struct client_state_t cs[static 1]) | ssize_t send_rebind(struct client_state_t cs[static 1]) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = init_packet(DHCPREQUEST, cs->xid); |     struct dhcpmsg packet = {.xid = cs->xid}; | ||||||
|  |     init_packet(&packet, DHCPREQUEST); | ||||||
|     packet.ciaddr = cs->clientAddr; |     packet.ciaddr = cs->clientAddr; | ||||||
|     add_option_reqip(&packet, cs->clientAddr); |     add_option_reqip(&packet, cs->clientAddr); | ||||||
|     add_option_maxsize(&packet); |     add_option_maxsize(&packet); | ||||||
| @@ -492,7 +492,8 @@ ssize_t send_rebind(struct client_state_t cs[static 1]) | |||||||
|  |  | ||||||
| ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server) | ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = init_packet(DHCPDECLINE, cs->xid); |     struct dhcpmsg packet = {.xid = cs->xid}; | ||||||
|  |     init_packet(&packet, DHCPDECLINE); | ||||||
|     add_option_reqip(&packet, cs->clientAddr); |     add_option_reqip(&packet, cs->clientAddr); | ||||||
|     add_option_serverid(&packet, server); |     add_option_serverid(&packet, server); | ||||||
|     log_line("%s: Sending a decline message...", client_config.interface); |     log_line("%s: Sending a decline message...", client_config.interface); | ||||||
| @@ -501,8 +502,8 @@ ssize_t send_decline(struct client_state_t cs[static 1], uint32_t server) | |||||||
|  |  | ||||||
| ssize_t send_release(struct client_state_t cs[static 1]) | ssize_t send_release(struct client_state_t cs[static 1]) | ||||||
| { | { | ||||||
|     struct dhcpmsg packet = init_packet(DHCPRELEASE, |     struct dhcpmsg packet = {.xid = nk_random_u32(&cs->rnd32_state)}; | ||||||
|                                         nk_random_u32(&cs->rnd32_state)); |     init_packet(&packet, DHCPRELEASE); | ||||||
|     packet.ciaddr = cs->clientAddr; |     packet.ciaddr = cs->clientAddr; | ||||||
|     add_option_reqip(&packet, cs->clientAddr); |     add_option_reqip(&packet, cs->clientAddr); | ||||||
|     add_option_serverid(&packet, cs->serverAddr); |     add_option_serverid(&packet, cs->serverAddr); | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user