netutils/dhcpc: fix nxstyle warning

Signed-off-by: chao.an <anchao@xiaomi.com>
This commit is contained in:
chao.an 2020-04-03 14:45:11 +08:00 committed by patacongo
parent 70bb13ce3b
commit c6b678fa60

View File

@ -64,7 +64,6 @@
/* Configuration */
/* DHCP Definitions */
#define STATE_INITIAL 0
@ -143,8 +142,15 @@ struct dhcpc_state_s
* Private Data
****************************************************************************/
static const uint8_t xid[4] = {0xad, 0xde, 0x12, 0x23};
static const uint8_t magic_cookie[4] = {99, 130, 83, 99};
static const uint8_t xid[4] =
{
0xad, 0xde, 0x12, 0x23
};
static const uint8_t magic_cookie[4] =
{
99, 130, 83, 99
};
/****************************************************************************
* Private Functions
@ -226,7 +232,8 @@ static int dhcpc_sendmsg(FAR struct dhcpc_state_s *pdhcpc,
pdhcpc->packet.hlen = pdhcpc->ds_maclen;
memcpy(pdhcpc->packet.xid, xid, 4);
memcpy(pdhcpc->packet.chaddr, pdhcpc->ds_macaddr, pdhcpc->ds_maclen);
memset(&pdhcpc->packet.chaddr[pdhcpc->ds_maclen], 0, 16 - pdhcpc->ds_maclen);
memset(&pdhcpc->packet.chaddr[pdhcpc->ds_maclen],
0, 16 - pdhcpc->ds_maclen);
memcpy(pdhcpc->packet.options, magic_cookie, sizeof(magic_cookie));
/* Add the common header options */
@ -305,30 +312,35 @@ static uint8_t dhcpc_parseoptions(FAR struct dhcpc_state *presult,
switch (*optptr)
{
case DHCP_OPTION_SUBNET_MASK:
/* Get subnet mask in network order */
memcpy(&presult->netmask.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_ROUTER:
/* Get the default router address in network order */
memcpy(&presult->default_router.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_DNS_SERVER:
/* Get the DNS server address in network order */
memcpy(&presult->dnsaddr.s_addr, optptr + 2, 4);
break;
case DHCP_OPTION_MSG_TYPE:
/* Get message type */
type = *(optptr + 2);
break;
case DHCP_OPTION_SERVER_ID:
/* Get server address in network order */
memcpy(&presult->serverid.s_addr, optptr + 2, 4);
@ -364,7 +376,8 @@ static uint8_t dhcpc_parsemsg(FAR struct dhcpc_state_s *pdhcpc, int buflen,
{
if (pdhcpc->packet.op == DHCP_REPLY &&
memcmp(pdhcpc->packet.xid, xid, sizeof(xid)) == 0 &&
memcmp(pdhcpc->packet.chaddr, pdhcpc->ds_macaddr, pdhcpc->ds_maclen) == 0)
memcmp(pdhcpc->packet.chaddr,
pdhcpc->ds_macaddr, pdhcpc->ds_maclen) == 0)
{
memcpy(&presult->ipaddr.s_addr, pdhcpc->packet.yiaddr, 4);
return dhcpc_parseoptions(presult, &pdhcpc->packet.options[4], buflen);
@ -390,8 +403,9 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
int ret;
ninfo("MAC: %02x:%02x:%02x:%02x:%02x:%02x\n",
((uint8_t*)macaddr)[0], ((uint8_t*)macaddr)[1], ((uint8_t*)macaddr)[2],
((uint8_t*)macaddr)[3], ((uint8_t*)macaddr)[4], ((uint8_t*)macaddr)[5]);
((uint8_t *)macaddr)[0], ((uint8_t *)macaddr)[1],
((uint8_t *)macaddr)[2], ((uint8_t *)macaddr)[3],
((uint8_t *)macaddr)[4], ((uint8_t *)macaddr)[5]);
/* Allocate an internal DHCP structure */
@ -463,7 +477,6 @@ FAR void *dhcpc_open(FAR const char *interface, FAR const void *macaddr,
return NULL;
}
#endif
}
return (FAR void *)pdhcpc;
@ -557,8 +570,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
pdhcpc->ipaddr.s_addr = presult->ipaddr.s_addr;
pdhcpc->serverid.s_addr = presult->serverid.s_addr;
/* Temporarily use the address offered by the server and break
* out of the loop.
/* Temporarily use the address offered by the server
* and break out of the loop.
*/
netlib_set_ipv4addr(pdhcpc->interface,
@ -567,9 +580,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
}
}
/* An error has occurred. If this was a timeout error (meaning that
* nothing was received on this socket for a long period of time).
* Then loop and send the DISCOVER command again.
/* An error has occurred. If this was a timeout error (meaning
* that nothing was received on this socket for a long period
* of time). Then loop and send the DISCOVER command again.
*/
else if (errno != EAGAIN)
@ -579,7 +592,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
return ERROR;
}
}
while (state == STATE_INITIAL && retries < CONFIG_NETUTILS_DHCPC_RETRIES);
while (state == STATE_INITIAL &&
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
/* If no DHCPOFFER recveived here, error out */
@ -617,8 +631,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
msgtype = dhcpc_parsemsg(pdhcpc, result, presult);
/* The ACK response means that the server has accepted our request
* and we have the lease.
/* The ACK response means that the server has accepted
* our request and we have the lease.
*/
if (msgtype == DHCPACK)
@ -638,9 +652,9 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
break;
}
/* If we get any OFFERs from other servers, then decline them now
* and continue waiting for the ACK from the server that we
* requested from.
/* If we get any OFFERs from other servers, then decline
* them now and continue waiting for the ACK from the server
* that we requested from.
*/
else if (msgtype == DHCPOFFER)
@ -659,8 +673,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
/* An error has occurred. If this was a timeout error (meaning
* that nothing was received on this socket for a long period of
* time). Then break out and send the DISCOVER command again (at most
* 3 times).
* time). Then break out and send the DISCOVER command again
* (at most 3 times).
*/
else if (errno != EAGAIN)
@ -671,7 +685,8 @@ int dhcpc_request(FAR void *handle, FAR struct dhcpc_state *presult)
return ERROR;
}
}
while (state == STATE_HAVE_OFFER && retries < CONFIG_NETUTILS_DHCPC_RETRIES);
while (state == STATE_HAVE_OFFER &&
retries < CONFIG_NETUTILS_DHCPC_RETRIES);
}
while (state != STATE_HAVE_LEASE);