# MAC and IP addresses

**URL:** <https://forums.freertos.org/t/mac-and-ip-addresses/12042>\
**Category:** Libraries\
**Created:** [March 19, 2021, 11:09am UTC](https://forums.freertos.org/t/mac-and-ip-addresses/12042 "2021-03-19T11:09:29Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![eduardo-semcon](https://avatars.discourse-cdn.com/v4/letter/e/85e7bf/32.png) [@eduardo-semcon](https://forums.freertos.org/u/eduardo-semcon)\
**Post date:** [March 19, 2021, 11:09am UTC](https://forums.freertos.org/t/mac-and-ip-addresses/12042/1 "2021-03-19T11:09:29Z")

</div>

I’m trying to find out to set the MAC address and IP address.

In NetworkInterface.c function BaseType\_t xNetworkInterfaceInitialise( void )  
the MAC address is obtained by calling:

```
        xETH.Init.MACAddr = ( uint8_t * ) FreeRTOS_GetMACAddress();

```

There is a function in FreeRTOS\_IP.c

```auto
const uint8_t * FreeRTOS_GetMACAddress( void )
{
    return ipLOCAL_MAC_ADDRESS;
}

```

That makes use of a define in FreeRTOS\_IP\_Private.h

```
#define ipLOCAL_MAC_ADDRESS ( xDefaultPartUDPPacketHeader.ucBytes )

```

In turn the xDefaultPartUDPPacketHeader is defined in FreeRTOS\_UDP\_IP.c

```auto
UDPPacketHeader_t xDefaultPartUDPPacketHeader =
{
    /* .ucBytes : */
    {
       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* Ethernet source MAC address. */
       0x08, 0x00, /* Ethernet frame type. */
        ipIP_VERSION_AND_HEADER_LENGTH_BYTE, /* ucVersionHeaderLength. */
        0x00, /* ucDifferentiatedServicesCode. */
        0x00, 0x00, /* usLength. */
        0x00, 0x00, /* usIdentification. */
        0x00, 0x00, /* usFragmentOffset. */
        ipconfigUDP_TIME_TO_LIVE, /* ucTimeToLive */
        ipPROTOCOL_UDP, /* ucProtocol. */
        0x00, 0x00, /* usHeaderChecksum. */
      0x00, 0x00, 0x00, 0x00 /* Source IP address. */
   }
};

```

Should I just replace  
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /\* Ethernet source MAC address. \*/

by the MAC address.  
Somehow this does not seem right.  
The STM32F767 seems to have a UID register that provides a Unique ID number.  
Could I use this? How?

And in respect with the IP address. If I’m not using DHCP how can I define an IP address?

I see

```auto
    #define ipLOCAL_IP_ADDRESS_POINTER ( ( uint32_t * ) &( xDefaultPartUDPPacketHeader.ulWords[20U / sizeof( uint32_t )] ) )

```

in FreeRTOS\_IP\_Private.h which suggests the same way…

thanks

---

<div class="post-metadata">

**Author:** ![hs2](https://avatars.discourse-cdn.com/v4/letter/h/a4c791/32.png) [@hs2](https://forums.freertos.org/u/hs2)\
**Post date:** [March 19, 2021, 11:52am UTC](https://forums.freertos.org/t/mac-and-ip-addresses/12042/2 "2021-03-19T11:52:17Z")

</div>

You have to use `FreeRTOS_IPInit()` to initialize the stack.  
I recommend to have a look at [FreeRTOS+TCP Networking Tutorial](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Networking_Tutorial.html) and there you find e.g. [TCP Networking Tutorial - Initialising the TCP/IP Stack](https://www.freertos.org/FreeRTOS-Plus/FreeRTOS_Plus_TCP/TCP_Networking_Tutorial_Initialising_TCP.html) including examples.

---

<div class="post-metadata">

**Author:** ![htibosch](https://d3iykfbgfh8zhg.cloudfront.net/user_avatar/forums.freertos.org/htibosch/32/62_2.png) [@htibosch](https://forums.freertos.org/u/htibosch)\
**Post date:** [March 19, 2021, 5:43pm UTC](https://forums.freertos.org/t/mac-and-ip-addresses/12042/3 "2021-03-19T17:43:42Z")

</div>

> The STM32F767 seems to have a UID register that provides a Unique ID number.  
> Could I use this? How?

All FreeRTOS+TCP demos are using any MAC-address, and their purpose is just for testing.  
Hartmut is right that `FreeRTOS_IPInit()`must be called to initialise the ( default ) IP- and MAC-address.  
In real life, a device gets a [MAC-address chip](https://www.maximintegrated.com/en/design/technical-documents/app-notes/1/186.html) with a single purpose: to give your application a world-wide unique MAC-address. These chips normally have a 1-wire access.  
As long as you are experimenting, or as long as you work on you private LAN, you are free to create your own MAC-addresses and the ST UID register can help you with that.

There are a [few rules](https://en.wikipedia.org/wiki/MAC_address) about the MAC-address though: some bits have a special meaning.
