IP Address

Microchip TCP/IP Stack

Microchip TCP/IP Stack Help
IP Address

The IP address is used to address nodes on an Internet Protocol network. You will need to configure your application with an IP address, or enable a method to obtain one. You may also want to define a few other parameters that describe how your device will try to fit into its network, by default. 

The macros that you will need to define include:

Macro 
Property 
Sample Value 
MY_DEFAULT_IP_ADDR_BYTE1 
Default IP address byte 1 
192ul 
MY_DEFAULT_IP_ADDR_BYTE2 
Default IP address byte 2 
168ul 
MY_DEFAULT_IP_ADDR_BYTE3 
Default IP address byte 3 
1ul 
MY_DEFAULT_IP_ADDR_BYTE4 
Default IP address byte 4 
100ul 
MY_DEFAULT_MASK_BYTE1 
Default subnet mask byte 1 
255ul 
MY_DEFAULT_MASK_BYTE2 
Default subnet mask byte 2 
255ul 
MY_DEFAULT_MASK_BYTE3 
Default subnet mask byte 3 
255ul 
MY_DEFAULT_MASK_BYTE4 
Default subnet mask byte 4 
0ul 
MY_DEFAULT_GATE_BYTE1 
Default gateway byte 1 
192ul 
MY_DEFAULT_GATE_BYTE1 
Default gateway byte 2 
168ul 
MY_DEFAULT_GATE_BYTE1 
Default gateway byte 3 
1ul 
MY_DEFAULT_GATE_BYTE1 
Default gateway byte 4 
1ul 

The subnet address is a bit mask that defines the scope of the network. If your IP address is 192.168.5.100, and you specify a subnet mask of 255.255.255.0, the stack will assume that addresses in the range 192.168.5.x are on the same subnet that you are, and that packets sent to any of those addresses won't have to be routed anywhere else. 

The default gateway is the IP address of the node on the network that your application will send packets to if it doesn't know how to route them to the address it wants to send them to. If your application is on the 192.268.5.x subnet, if it wants to send a packet to 198.175.253.160 and it doesn't know exactly how to get there, it will send it to the default gateway. 

Note that if you write your own code instead of starting with a demo application, you will need to populate your AppConfig structure with these values. Also note that these are only default values. Other protocols (or your application itself) may modify any of the APP_CONFIG fields that represent these parameters. 

There are three methods that you can use to set or obtain an IP address: static, DHCP, or AutoIP. 

Static IP Addressing 

Using a static address will allow you to specify a set IP address. This can either be done at compile time, by setting the default IP address to the value you'd like to use and using the demo code (which populated your AppConfig structure automatically), or during run-time, by programming your application to set the IP address in your AppConfig structure based on some input. If you'd like to include the code for DCHP and AutoIP address acquisition if your project but still use static addressing, you can call the DHCP and AutoIP functions that disable those modules to prevent them from overwriting your IP address. Use of static addresses will usually only work if the server is configured to support that address. 

DHCP 

The DHCP client module will allow your application to dynamically obtain an IP address from a DHCP server on the same network. Doing this will reset the IP address, subnet mask, gateway address, and some other configuration parameters in your AppConfig structure. To use DHCP, include the files DHCP.c, DHCPs.c, and DHCP.h in your project, and add or uncomment the definition "#define STACK_USE_DHCP_CLIENT" to TCPIPConfig.h. The TCP/IP stack also includes a simple DHCP server that can supply an IP address to one DHCP client. To enable this functionality, add the macro "#define STACK_USE_DHCP_SERVER" to TCPIPConfig.h

AutoIP 

The AutoIP module will allow your application to choose an IP address and claim it for itself. These addresses are link-local, meaning they cannot be routed, and will only work on your local link. This functionality is based on the specification for allocating dynamic link-local addresses, but is modified to take the form used by Microsoft's APIPA link-local address allocation scheme. To enable this feature, include the files AutoIP.c and AutoIP.h and add the macro "#define STACK_USE_AUTO_IP" to TCPIPConfig.h

IP Address Module Interaction 

It is possible to configure a default static address and enable DHCP and AutoIP at the same time. If you don't disable one or the other, the AutoIP module will immediately choose an address in the specified address range and begin attempting to claim it. DHCP will also begin sending messages to attempt to lease a DHCP IP address from a DHCP server. In most cases the DHCP module will complete all of its transactions before AutoIP finishes claiming its address. In this case, the DHCP address will be copied to the AppConfig structure and the AutoIP module will stop trying to claim its address. Since a routable DHCP address is always preferred to a link-local AutoIP address, the stack will also immediately start using a DHCP address if it becomes available, even if an AutoIP address was already in use (i.e. if you enable DHCP after AutoIP has already claimed an address). This may cause existing open sockets to lose communication; they should be re-opened with the new address. In this situation, you can also use a static address if you disable DHCP and AutoIP and set the static address in the AppConfig structure. 

If AutoIP is used in conjunction with the DHCP Server module, the AutoIP module will generate an address in the 169.254.x.x subnet and then serve another address in the same subnet to the DHCP client connected to the board.

Microchip TCP/IP Stack 5.42.08 - June 15, 2013
Copyright © 2012 Microchip Technology, Inc.  All rights reserved.