---
title: "DHCP not working"
url: "https://maker.wiznet.io/forum/13250"
markdown_url: "https://maker.wiznet.io/forum/13250/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "Century"
created: "2019-03-25T13:30:20+09:00"
last_activity: "2022-09-25T22:26:52+09:00"
language: "en"
views: 1381
replies: 3
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# DHCP not working

## Question

Asked by Century on 2019-03-25 in Ethernet Chips.

Hi all,

I am using ioLibrary_Driver-master for DHCP, I am not getting any response from the DHCP.

/* PARSE REPLY pDHCPMSG */
int8_t parseDHCPMSG(void)
{
uint8_t svr_addr[6];
uint16_t svr_port;
uint16_t len;

```
uint8_t * p;
uint8_t * e;
uint8_t type = 0;
uint8_t opt_len;
```

if((len = getSn_RX_RSR(DHCP_SOCKET)) > 0)
{
len = recvfrom(DHCP_SOCKET, (uint8_t *)pDHCPMSG, len, svr_addr, &svr_port);
#ifdef *DHCP_DEBUG*
printf(“DHCP message : %d.%d.%d.%d(%d) %d received. \r\n”,svr_addr[0],svr_addr[1],svr_addr[2], svr_addr[3],svr_port, len);
#endif
}
else
return 0;
if (svr_port == DHCP_SERVER_PORT)
{
// compare mac address
if ( (pDHCPMSG->chaddr[0] != DHCP_CHADDR[0]) || (pDHCPMSG->chaddr[1] != DHCP_CHADDR[1]) ||
(pDHCPMSG->chaddr[2] != DHCP_CHADDR[2]) || (pDHCPMSG->chaddr[3] != DHCP_CHADDR[3]) ||
(pDHCPMSG->chaddr[4] != DHCP_CHADDR[4]) || (pDHCPMSG->chaddr[5] != DHCP_CHADDR[5]) )
return 0;
p = (uint8_t *)(&pDHCPMSG->op);
p = p + 240; // 240 = sizeof(RIP_MSG) + MAGIC_COOKIE size in RIP_MSG.opt - sizeof(RIP_MSG.opt)
e = p + (len - 240);

```
	while ( p < e ) {

		switch ( *p ) {

		case endOption :
		   p = e;   // for break while(p < e)
			break;
        case padOption :
			p++;
			break;
		case dhcpMessageType :
			p++;
			p++;
			type = *p++;
			break;
		case subnetMask :
			p++;
			p++;
			DHCP_allocated_sn[0] = *p++;
			DHCP_allocated_sn[1] = *p++;
			DHCP_allocated_sn[2] = *p++;
			DHCP_allocated_sn[3] = *p++;
			break;
		case routersOnSubnet :
			p++;
			opt_len = *p++;       
			DHCP_allocated_gw[0] = *p++;
			DHCP_allocated_gw[1] = *p++;
			DHCP_allocated_gw[2] = *p++;
			DHCP_allocated_gw[3] = *p++;
			p = p + (opt_len - 4);
			break;
		case dns :
			p++;                  
			opt_len = *p++;       
			DHCP_allocated_dns[0] = *p++;
			DHCP_allocated_dns[1] = *p++;
			DHCP_allocated_dns[2] = *p++;
			DHCP_allocated_dns[3] = *p++;
			p = p + (opt_len - 4);
			break;
		case dhcpIPaddrLeaseTime :
			p++;
			opt_len = *p++;
			dhcp_lease_time  = *p++;
			dhcp_lease_time  = (dhcp_lease_time << 8) + *p++;
			dhcp_lease_time  = (dhcp_lease_time << 8) + *p++;
			dhcp_lease_time  = (dhcp_lease_time << 8) + *p++;
        #ifdef _DHCP_DEBUG_  
           dhcp_lease_time = 10;
			#endif
			break;
		case dhcpServerIdentifier :
			p++;
			opt_len = *p++;
			DHCP_SIP[0] = *p++;
			DHCP_SIP[1] = *p++;
			DHCP_SIP[2] = *p++;
			DHCP_SIP[3] = *p++;
			break;
		default :
			p++;
			opt_len = *p++;
			p += opt_len;
			break;
		} // switch
	} // while
} // if
return	type;
```

}

for the above function I am always getting 0 response.

Please help me out, what could be the mistake and any error on DHCP init.

Thanks.

## Replies

### Reply 1 by taylor, 2019-03-26

Hello,

How did you initialize DHCP()?

Here is ‘W5500 Application code examples’, please refer this example.

<https://wizwiki.net/wiki/doku.php?id=products:w5500:driver>

[w5500_example_dhcp_stm32f103x_coide_20131226](https://wizwiki.net/wiki/lib/exe/fetch.php?media=products:w5500:w5500_example_dhcp_stm32f103x_coide_20131226.zip)

[Wireshark](https://www.wireshark.org/) is a network packet analyzer.

First of all, check dhcp request packet please.

Here is a sample of DHCP traffic.

<https://wiki.wireshark.org/SampleCaptures?action=AttachFile&do=get&target=dhcp.pcap>

thanks
best regards
taylor

### Reply 2 by Century, 2019-03-26 (in reply to reply 1)

Thank You, Will look into it.

### Reply 3 by mzedan, 2022-09-25 (in reply to reply 1)

Greetings,
It seems that this link <https://wizwiki.net/wiki/doku.php?id=products:w5500:driver> is no longer exists. Is there is an alternative link I can go to?

Regards

---

Source: https://maker.wiznet.io/forum/13250
