busybox-1.32.0/networking/udhcp/d6_dhcpc.c
static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid)
{
	uint8_t *ptr;
	struct d6_option *clientid;
	unsigned secs;

	memset(packet, 0, sizeof(*packet));

	packet->d6_xid32 = xid;
	packet->d6_msg_type = type;

	/* ELAPSED_TIME option is required to be present by the RFC,
	 * and some servers do check for its presense. [which?]
	 */
	ptr = packet->d6_options; /* NB: it is 32-bit aligned */
	*((uint32_t*)ptr) = htonl((D6_OPT_ELAPSED_TIME << 16) + 2);
	ptr += 4;
	client_data.last_secs = monotonic_sec();
	if (client_data.first_secs == 0)
		client_data.first_secs = client_data.last_secs;
	secs = client_data.last_secs - client_data.first_secs;
	*((uint16_t*)ptr) = (secs < 0xffff) ? htons(secs) : 0xffff;
	ptr += 2;

	/* add CLIENTID option */
	clientid = (void*)client_data.clientid;
	return mempcpy(ptr, clientid, clientid->len + 2+2);
}
/* Initialize the packet with the proper defaults */
Initialize the packet with the proper defaults
Initialize the packet with the proper defaults
static uint8_t *init_d6_packet(struct d6_packet *packet, char type, uint32_t xid)
{
	uint8_t *ptr;
	struct d6_option *clientid;
	unsigned secs;
	memset(packet, 0, sizeof(*packet));
	packet->d6_xid32 = xid;
	packet->d6_msg_type = type;
	ptr = packet->d6_options; 
	*((uint32_t*)ptr) = htonl((D6_OPT_ELAPSED_TIME << 16) + 2);
	ptr += 4;
	client_data.last_secs = monotonic_sec();
	if (client_data.first_secs == 0)
		client_data.first_secs = client_data.last_secs;
	secs = client_data.last_secs - client_data.first_secs;
	*((uint16_t*)ptr) = (secs < 0xffff) ? htons(secs) : 0xffff;
	ptr += 2;
	clientid = (void*)client_data.clientid;
	return mempcpy(ptr, clientid, clientid->len + 2+2);
}
static uint8_t * init_d6_packet ( struct d6_packet * packet , char type , uint32_t xid ) { uint8_t * ptr ; struct d6_option * clientid ; unsigned secs ; memset ( packet , 0 , sizeof ( * packet ) ) ; packet -> d6_xid32 = xid ; packet -> d6_msg_type = type ; ptr = packet -> d6_options ; * ( ( uint32_t * ) ptr ) = htonl ( ( D6_OPT_ELAPSED_TIME << 16 ) + 2 ) ; ptr += 4 ; client_data . last_secs = monotonic_sec ( ) ; if ( client_data . first_secs == 0 ) client_data . first_secs = client_data . last_secs ; secs = client_data . last_secs - client_data . first_secs ; * ( ( uint16_t * ) ptr ) = ( secs < 0xffff ) ? htons ( secs ) : 0xffff ; ptr += 2 ; clientid = ( void * ) client_data . clientid ; return mempcpy ( ptr , clientid , clientid -> len + 2 + 2 ) ; }
Initialize the packet with the proper defaults
Initialize the packet with the proper defaults
/* ELAPSED_TIME option is required to be present by the RFC,
	 * and some servers do check for its presense. [which?]
	 */ /* NB: it is 32-bit aligned */ /* add CLIENTID option */