---
title: "Dhcp"
url: "https://maker.wiznet.io/forum/10054"
markdown_url: "https://maker.wiznet.io/forum/10054/md"
type: "Forum topic"
category: "Ethernet Chips"
author: "MrBool"
created: "2014-03-17T09:57:31+09:00"
last_activity: "2017-05-04T08:32:01+09:00"
language: "en"
views: 857
replies: 1
source: "WIZnet Makers forum (https://maker.wiznet.io/forum/)"
---

# Dhcp

## Question

Asked by MrBool on 2014-03-17 in Ethernet Chips.

I use W5500 with STM32F051R8T6, my IDE is Keil. I ported some part of code to this chip and communication by SPI works well. I also have succes with STM32F103X CooCox CoIDE Project Loopback Test - works perfect.
I have problem with DHCP client. When I run this project I have go HardFault. Here is my console output:

## [code]=== W5500 NET CONF : DHCP === MAC: 00:08:DC:00:AB:CD SIP: 192.168.1.123 GAR: 192.168.1.1 SUB: 255.255.255.0 DNS: 0.0.0.0

> Send DHCP_DISCOVER
> DHCP message : 192.168.1.1(67) 345 received.
> Receive DHCP_OFFER
> Send DHCP_REQUEST
> DHCP message : 192.168.1.1(67) 345 received.
> Receive DHCP_ACK
> HardFault[/code]

during debug I have found that hardfault is occur in this line:

```
if(*((uint32_t*)addr) == 0) return SOCKERR_IPINVALID;
```

in function

```
int32_t sendto(uint8_t sn, uint8_t * buf, uint16_t len, uint8_t * addr, uint16_t port)
```

What could be the problem?

## Replies

### Reply 1 by MrBool, 2014-03-18

Hi,

I checked and addr = 0x2000016B - address of variable DHCP_allocated_ip.

You are right. This addr is not divied by 4.

I change code to:

```
if ((addr[0] | addr[1] | addr[2] | addr[3]) == 0) return SOCKERR_IPINVALID;
```

and now everything is OK.

---

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