Network Component  Version 7.10.0
MDK Middleware for IPv4 and IPv6 Networking
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages

Functions of the Ethernet Interface. More...

Typedefs

typedef void(* netARP_cb_t )(netARP_Event event)
 ARP Probe Event callback function. More...
 
typedef void(* netNDP_cb_t )(netNDP_Event event)
 NDP Probe Event callback function. More...
 

Enumerations

enum  netARP_Event {
  netARP_EventSuccess = 0,
  netARP_EventTimeout
}
 ARP Probe Callback Events. More...
 
enum  netNDP_Event {
  netNDP_EventSuccess = 0,
  netNDP_EventTimeout
}
 NDP Probe Callback Events. More...
 

Functions

netStatus netARP_CacheIP (uint32_t if_num, const uint8_t *ip4_addr, netARP_CacheType type)
 Determine whether the ARP table has MAC address resolved for requested IP address. [thread-safe]. More...
 
netStatus netARP_CacheMAC (uint32_t if_num, const uint8_t *mac_addr)
 Determine whether the ARP table has IP address resolved for requested MAC address. [thread-safe]. More...
 
netStatus netARP_GetIP (uint32_t if_num, const uint8_t *mac_addr, uint8_t *ip4_addr)
 Get IP address from the ARP cache. [thread-safe]. More...
 
netStatus netARP_GetMAC (uint32_t if_num, const uint8_t *ip4_addr, uint8_t *mac_addr)
 Get MAC address from the ARP cache. [thread-safe]. More...
 
netStatus netARP_Probe (uint32_t if_num, const uint8_t *ip4_addr, netARP_cb_t cb_func)
 Determine whether the IP address is already in use. [thread-safe]. More...
 
netStatus netNDP_CacheIP (uint32_t if_num, const uint8_t *ip6_addr)
 Determine whether neighbor cache has MAC address resolved for requested IP address. [thread-safe]. More...
 
netStatus netNDP_GetIP (uint32_t if_num, const uint8_t *mac_addr, uint8_t *ip6_addr)
 Get IP address from neighbor discovery cache. [thread-safe]. More...
 
netStatus netNDP_GetMAC (uint32_t if_num, const uint8_t *ip6_addr, uint8_t *mac_addr)
 Get MAC address from neighbor discovery cache. [thread-safe]. More...
 
netStatus netNDP_Probe (uint32_t if_num, const uint8_t *ip6_addr, netNDP_cb_t cb_func)
 Determine whether the IP address is already in use. [thread-safe]. More...
 
netStatus netIGMP_Join (uint32_t if_num, const uint8_t *ip4_addr)
 Join this host to a host group specified with IP address. [thread-safe]. More...
 
netStatus netIGMP_Leave (uint32_t if_num, const uint8_t *ip4_addr)
 Leave a host group specified with IP address. [thread-safe]. More...
 
netStatus netDHCP_Enable (uint32_t if_num)
 Enable Dynamic Host Configuration at runtime. [thread-safe]. More...
 
netStatus netDHCP_Disable (uint32_t if_num)
 Disable Dynamic Host Configuration at runtime. [thread-safe]. More...
 
netStatus netDHCP_SetOption (uint32_t if_num, uint8_t option, const uint8_t *val, uint32_t len)
 Set DHCP Option value at runtime. [thread-safe]. More...
 
netStatus netDHCP6_Enable (uint32_t if_num, netDHCP6_Mode mode)
 Enable Dynamic Host Configuration version 6 at runtime. [thread-safe]. More...
 
netStatus netDHCP6_Disable (uint32_t if_num)
 Disable Dynamic Host Configuration version 6 at runtime. [thread-safe]. More...
 
netStatus netETH_SendRaw (uint32_t if_num, const uint8_t *buf, uint32_t len)
 Send raw Ethernet data. [thread-safe]. More...
 

Description

Functions of the Ethernet Interface.

In the Network Component, the Ethernet interface API is responsible for various Application/Internet/Link layer protocols such as ARP, NDP, IGMP, and DHCP. In the Network Component v7, these protocols are supported for IPv4 and IPv6 connections (where applicable).

To get or set Ethernet options, use the generic netIF_GetOption and netIF_SetOption. The available options are as follows:

Option Description
netIF_OptionMAC_Address Ethernet MAC Address
netIF_OptionVLAN_Identifier Ethernet VLAN Identifier
netIF_OptionIP4_MTU IPv4 Maximum Transmission Unit
netIF_OptionIP4_Address IPv4 Address
netIF_OptionIP4_SubnetMask IPv4 Subnet mask
netIF_OptionIP4_DefaultGateway IPv4 Default Gateway
netIF_OptionIP4_PrimaryDNS IPv4 Primary DNS
netIF_OptionIP4_SecondaryDNS IPv4 Secondary DNS
netIF_OptionIP6_MTU IPv6 Maximum Transmission Unit
netIF_OptionIP6_LinkLocalAddress IPv6 Link-local Address
netIF_OptionIP6_StaticAddress IPv6 Static Address
netIF_OptionIP6_DynamicAddress IPv6 Dynamic Address
netIF_OptionIP6_SubnetPrefixLengthIPv6 Subnet Prefix-length
netIF_OptionIP6_DefaultGateway IPv6 Default Gateway
netIF_OptionIP6_PrimaryDNS IPv6 Primary DNS
netIF_OptionIP6_SecondaryDNS IPv6 Secondary DNS

The callback function netETH_Notify informs the user application about state changes on the Ethernet link.

Address Resolution Protocol (ARP, IPv4 only)

The Address Resolution Protocol (ARP) is used to resolve network layer (IP) addresses to link layer (MAC) addresses. It is being used in IPv4 networks only. In IPv6 networks, Neighbor Discovery Protocol (NDP) is used instead.

The Network Component provides five functions for ARP. Two functions are working on the ARP table, two functions actually resolve the IP or MAC address and one function that checks whether the IP address is already in use. netARP_CacheIP determines whether the ARP table has a MAC address resolved for a certain IP address. netARP_CacheMAC determines whether the ARP table has an IP address resolved for a certain MAC address. To retrieve the MAC address for an IP address from the ARP table, use netARP_GetMAC, while netARP_GetIP provides the IP address for a given MAC address. To verify that the IP address is not used in local area network, use netARP_Probe.

Neighbor Discovery Protocol (NDP, IPv6 only)

The Neighbor Discovery Protocol (NDP) operates on the link layer and is responsible for

It is available for IPv6 only.

The function netNDP_CacheIP checks if the NDP table has a MAC address resolved for a certain IPv6 address. To retrieve this MAC address, use netNDP_GetMAC. To retrieve an IPv6 address for any given MAC address, use netNDP_GetIP. To verify that the IPv6 address is not used in local area network, use netNDP_Probe.

Internet Group Management Protocol (IGMP, IPv4 only)

The Internet Group Management Protocol (IGMP) is used to do IP Multicasting. This means that an IP datagram is sent to a "host group". A multicast datagram is delivered to all the members of its destination host group. IGMPv1 and IGMPv2 protocol specification are supported in the Network Component. It is available for IPv4 only.

To add a host to a certain host group, use netIGMP_Join. To leave a host group, netIGMP_Leave is used.

Dynamic Host Configuration Protocol (DHCP, IPv4 only)

The Dynamic Host Configuration Protocol (DHCP) is used for dynamically distributing network configuration parameters, such as IP addresses for interfaces and services. Using DHCP, network nodes request IP addresses and networking parameters automatically from a DHCP server, eliminating the need to configure these settings manually (refer to IP Address Assignment for more information). Although DHCP is specified for IPv4 and IPv6 networks, the Network Component is only supporting IPv4 networks at the moment.

Like all services, the DHCP is normally started automatically if NET_START_SERVICE is set to 1 in the Net_Config.c configuration file. If it is disabled, DHCP needs to be started manually in the user application using netDHCP_Enable. At runtime, it is always possible to stop DHCP using the function netDHCP_Disable. In this case, the Network Core will revert the IP address of the node to the static IP address specified in the Net_Config_ETH_n.h file.

The callback function netDHCP_Notify notifies the user application of DHCP events or extended DHCP options. This function is optional and not required for a default DHCP client configuration. However, if your application requires the ability to react on changes of the IP address, you need to implement this function in the user code.

Typedef Documentation

void(* netARP_cb_t)(netARP_Event event)

ARP Probe Event callback function.

Parameters
[in]event- Probe event as defined in netARP_Event.
Returns
none.

Is the type definition for the Probe callback function. Users must provide the function. The callback function uses the event argument to signal one of the following Probe events:

Event Description
netARP_EventSuccessRemote host responded to ARP probe.
netARP_EventTimeoutProbe session has timed out, remote host did not respond.

Parameter for:

void(* netNDP_cb_t)(netNDP_Event event)

NDP Probe Event callback function.

Parameters
[in]event- Probe event as defined in netNDP_Event.
Returns
none.

Is the type definition for the Probe callback function. Users must provide the function. The callback function uses the event argument to signal one of the following Probe events:

Event Description
netNDP_EventSuccessRemote host responded to NDP probe.
netNDP_EventTimeoutProbe session has timed out, remote host did not respond.

Parameter for:

Enumeration Type Documentation

ARP Probe Callback Events.

Parameter for:

Enumerator
netARP_EventSuccess 

Probed Host responded.

netARP_EventTimeout 

Timeout, no response to ARP probe.

NDP Probe Callback Events.

Parameter for:

Enumerator
netNDP_EventSuccess 

Probed Host responded.

netNDP_EventTimeout 

Timeout, no response to NDP probe.

Function Documentation

netStatus netARP_CacheIP ( uint32_t  if_num,
const uint8_t *  ip4_addr,
netARP_CacheType  type 
)

Determine whether the ARP table has MAC address resolved for requested IP address. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip4_addrrequested IPv4 address.
[in]typeaddress cache type.
Returns
status code that indicates the execution status of the function.

The function netARP_CacheIP determines whether the ARP table has a MAC (Ethernet) address entry for the requested IP address. If an entry does not exist, the function forces the Network Core to resolve and cache the MAC address into the internal ARP table buffer. To resolve the MAC address, the Network Core sends an ARP request to the network.

The argument if_num is the Ethernet interface number for which to check the ARP table.

The argument ip4_addr points to a buffer containing the four octets of the dotted decimal IPv4 address to be resolved.

The argument type specifies whether the IP address is fixed or temporary. This consequently determines whether or not the Network Core automatically refreshes the IP address entry in the ARP cache.

Type Description
netARP_CacheTemporaryIP The IP address is temporary, and thus Network removes the IP address entry from the ARP cache after a timeout.
netARP_CacheFixedIP The IP address is fixed, and thus Network's ARP module automatically refreshes the IP address entry after the timeout.

Possible netStatus return values:

  • netOK: MAC address resolved successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netBusy: MAC address resolving in progress.
  • netError: Gateway IP address is undefined.
Note
  • This function can only be used with IPv4. For IPv6 similar functionality is provided by netNDP_CacheIP.
  • Only the Ethernet interface uses the netARP_CacheIP function. There is no ARP protocol for the PPP or SLIP interface.
  • The netARP_CacheIP function is primarily useful before sending the first UDP packet. The function is not necessary before sending TCP packets because the TCP module can retransmit the packet if the remote machine did not receive the packet.

Code Example

uint8_t mac_addr [NET_ADDR_ETH_LEN];
uint8_t ip4_addr [NET_ADDR_IP4_LEN];
..
netIP_aton ("192.168.0.100", NET_ADDR_IP4, ip4_addr);
while (netARP_GetMAC (0, ip4_addr, mac_addr) != netOK) {
// Requested IP address not yet cached
osDelay (1000);
}
netStatus netARP_CacheMAC ( uint32_t  if_num,
const uint8_t *  mac_addr 
)

Determine whether the ARP table has IP address resolved for requested MAC address. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]mac_addrrequested MAC address.
Returns
status code that indicates the execution status of the function.

The function netARP_CacheMAC determines whether the ARP table has an IP address entry for the requested MAC (Ethernet) address mac_addr. If an entry does not exist, the function forces the Network Core to resolve and cache the IP address into the internal ARP table buffer. To resolve the IP address, the Network Core sends an inverse ARP request to the network.

The argument if_num is the Ethernet interface number for which to check the ARP table.

The argument mac_addr points to a buffer containing the six octets of the MAC address to be resolved.

Possible netStatus return values:

  • netOK: IP address resolved successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netBusy: IP address resolving in progress.
  • netError: Local IP address is undefined.
Note
  • This function can only be used with IPv4. There is no similar functionality for IPv6.
  • Only the Ethernet interface uses the netARP_CacheMAC function. There is no ARP protocol for the PPP or SLIP interface.

Code Example

uint8_t mac_addr [NET_ADDR_ETH_LEN];
uint8_t ip4_addr [NET_ADDR_IP4_LEN];
..
netMAC_aton ("1E-30-6C-A2-45-5E", mac_addr);
if (netARP_GetIP (0, mac_addr, ip4_addr) != netOK) {
// Requested MAC address not yet cached
netARP_CacheMAC (0, mac_addr);
}
netStatus netARP_GetIP ( uint32_t  if_num,
const uint8_t *  mac_addr,
uint8_t *  ip4_addr 
)

Get IP address from the ARP cache. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]mac_addrrequested MAC address.
[out]ip4_addrresolved IPv4 address.
Returns
status code that indicates the execution status of the function.

The function netARP_GetIP determines the resolved IP address for a specific MAC address.

The argument if_num is the Ethernet interface number for which to check the ARP table.

The argument mac_addr points to a buffer containing the six octets of the MAC address to be resolved.

The argument ip4_addr points to a buffer that stores the resolved IPv4 address.

Possible netStatus return values:

  • netOK: IP address copied to a buffer.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Requested MAC address not found in ARP table.
Note
This function can only be used with IPv4. For IPv6 similar functionality is provided by netNDP_GetIP.

Refer to

Code Example (see netARP_CacheMAC)

netStatus netARP_GetMAC ( uint32_t  if_num,
const uint8_t *  ip4_addr,
uint8_t *  mac_addr 
)

Get MAC address from the ARP cache. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip4_addrrequested IPv4 address.
[out]mac_addrresolved MAC address.
Returns
status code that indicates the execution status of the function.

The function netARP_GetMAC determines the resolved MAC address for a specific IP address.

The argument if_num is the Ethernet interface number for which to check the ARP table.

The argument ip4_addr points to a buffer containing four octets of the dotted decimal IPv4 address to be resolved.

The argument mac_addr points to a buffer that stores the resolved six octets of the MAC address.

Possible netStatus return values:

  • netOK: MAC address copied to a buffer.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Requested IP address not found in ARP table.

Refer to

Note
This function can only be used with IPv4. For IPv6 similar functionality is provided by netNDP_GetMAC.

Code Example

uint8_t ip4_addr [NET_ADDR_IP4_LEN] = { 192, 168, 0, 100 };
uint8_t mac_addr [NET_ADDR_ETH_LEN];
char addr_ascii[18];
..
if (netARP_GetMAC (0, ip4_addr, mac_addr) == netOK) {
netIP_ntoa (NET_ADDR_IP4, ip4_addr, addr_ascii, sizeof (addr_ascii));
printf ("Requested IP address: %s\n", addr_ascii);
netMAC_ntoa (mac_addr, addr_ascii, sizeof (addr_ascii));
printf ("Cached MAC address: %s\n", addr_ascii);
}
netStatus netARP_Probe ( uint32_t  if_num,
const uint8_t *  ip4_addr,
netARP_cb_t  cb_func 
)

Determine whether the IP address is already in use. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip4_addrrequested IPv4 address.
[in]cb_funccallback function to call, when probe session ends.
Returns
status code that indicates the execution status of the function.

The function netARP_Probe determines whether the requested IPv4 address is already used in local area network. You can use this function to check for IPv4 address collisions.

The argument if_num is the Ethernet interface number for which to check the IPv4 address.

The argument ip4_addr points to a buffer containing four octets of the dotted decimal IPv4 address to be checked.

The argument cb_func points to an event callback function called by the Network Core when the probe session ends. Refer to netARP_cb_t.

Possible netStatus return values:

  • netOK: Probe process started successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netBusy: Probe process is busy.

Refer to

Note
This function can only be used with IPv4. For IPv6 similar functionality is provided by netNDP_Probe.

Code Example

uint8_t ip4_addr[NET_ADDR_IP4_LEN] = { 192, 168, 0, 100 };
static void probe_callback (netARP_Event event) {
switch (event) {
printf ("Response received, IP address is in use.\n");
break;
printf ("Probe timeout, no response.\n");
break;
}
}
..
if (netARP_Probe (0, ip4_addr, probe_callback) == netOK) {
printf("Probe started.\n");
}
else {
printf("Probe not ready or bad parameters.\n");
}
netStatus netDHCP6_Disable ( uint32_t  if_num)

Disable Dynamic Host Configuration version 6 at runtime. [thread-safe].

Parameters
[in]if_numinterface_number.
Returns
status code that indicates the execution status of the function.

The function netDHCP6_Disable permanently disables the DHCPv6 service at runtime. To enable the DHCPv6 client again, you must call netDHCP6_Enable.

The argument if_num specifies the Ethernet interface for which DHCPv6 is to be disabled.

Possible netStatus return values:

  • netOK: DHCPv6 client disabled successfully.
  • netInvalidParameter: Invalid interface number provided.
Note
  • You can use the function only when the Dynamic Host Configuration for IPv6 is enabled in the Net_Config_ETH_n.c configuration file.
  • The DHCPv6 service works for IPv6 only.

Code Example

if (use_dhcp6 == false)
// Use a pre-defined static IP address
}
else {
// Use DHCPv6 assigned IP address, stateful mode
}
netStatus netDHCP6_Enable ( uint32_t  if_num,
netDHCP6_Mode  mode 
)

Enable Dynamic Host Configuration version 6 at runtime. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]modeDHCPv6 operation mode.
Returns
status code that indicates the execution status of the function.

The function netDHCP6_Enable enables the DHCPv6 service at runtime.

The argument if_num specifies the Ethernet interface for which DHCPv6 is to be enabled.

The argument mode specifies whether DHCPv6 client runs in stateful mode with IPv6 address assignment, or in stateless mode with no IPv6 address assignment. In stateless mode, DHCPv6 client obtains only additional information, such as DNS name servers.

Possible netStatus return values:

  • netOK: DHCPv6 client enabled successfully.
  • netInvalidParameter: Invalid interface number provided.
  • netError: DHCPv6 client internal error.
Note
  • If you set the NET_START_SERVICE to 1 in Net_Config.c, all selected services will be started automatically. Thus, you only need to call this function, if you have either stopped the DHCPv6 service previously using netDHCP6_Disable or have set NET_START_SERVICE to 0.
  • The DHCPv6 service works for IPv6 only.

Code Example (see netDHCP6_Disable)

netStatus netDHCP_Disable ( uint32_t  if_num)

Disable Dynamic Host Configuration at runtime. [thread-safe].

Parameters
[in]if_numinterface_number.
Returns
status code that indicates the execution status of the function.

The function netDHCP_Disable permanently disables the DHCP service at runtime. To enable the DHCP client again, you must call netDHCP_Enable.

The argument if_num specifies the Ethernet interface for which DHCP is to be disabled.

Possible netStatus return values:

  • netOK: DHCP client disabled successfully.
  • netInvalidParameter: Invalid interface number provided.
Note
  • You can use the function only when the Dynamic Host Configuration for IPv4 is enabled in the Net_Config_ETH_n.c configuration file.
  • The DHCP service works for IPv4 only.

Code Example

if (use_dhcp == false)
// Use a pre-defined static IP address
}
else {
// Use DHCP assigned IP address
}
netStatus netDHCP_Enable ( uint32_t  if_num)

Enable Dynamic Host Configuration at runtime. [thread-safe].

Parameters
[in]if_numinterface_number.
Returns
status code that indicates the execution status of the function.

The function netDHCP_Enable enables the DHCP service at runtime.

The argument if_num specifies the Ethernet interface for which DHCP is to be enabled.

Possible netStatus return values:

  • netOK: DHCP client enabled successfully.
  • netInvalidParameter: Invalid interface number provided.
  • netError: DHCP client internal error.
Note
  • If you set the NET_START_SERVICE to 1 in Net_Config.c, all selected services will be started automatically. Thus, you only need to call this function, if you have either stopped the DHCP service previously using netDHCP_Disable or have set NET_START_SERVICE to 0.
  • The DHCP service works for IPv4 only.

Code Example (see netDHCP_Disable)

netStatus netDHCP_SetOption ( uint32_t  if_num,
uint8_t  option,
const uint8_t *  val,
uint32_t  len 
)

Set DHCP Option value at runtime. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]optionDHCP option code.
[in]valpointer to option value.
[in]lenlength of option value in bytes.
Returns
status code that indicates the execution status of the function.

The function netDHCP_SetOption changes DHCP client options at runtime. To change a DHCP option, DHCP client must be disabled with a call to netDHCP_Disable, and enabled again after the call to netDHCP_SetOption with netDHCP_Enable.

The argument if_num specifies the Ethernet interface for which DHCP option is to be set.

The argument option specifies a DHCP option to be set. The following options are supported:

Option Description Minimum length
NET_DHCP_OPTION_CLIENT_ID Client-identifier option 2 bytes

The argument val is a pointer to user provided DHCP option value. If argument val is NULL, default DHCP option value is used instead of the user provided. Default DHCP Client-identifier option is Ethernet MAC address.

The argument len contains the length of the option value in bytes.

Possible netStatus return values:

  • netOK: Option successfully set.
  • netInvalidParameter: Invalid parameter provided.
  • netWrongState: DHCP client is running.
Note
  • You can use the function only when the Dynamic Host Configuration for IPv4 is enabled in the Net_Config_ETH_n.c configuration file.
  • The DHCP service works for IPv4 only.

Code Example

// Type = 255, IAID = 01020304, DUID = 13169
uint8_t user_cid[] = { 0xFF, 1, 2, 3, 4, 0x33, 0x71 };
netStatus netETH_SendRaw ( uint32_t  if_num,
const uint8_t *  buf,
uint32_t  len 
)

Send raw Ethernet data. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]bufbuffer containing the data.
[in]lenlength of data in bytes.
Returns
status code that indicates the execution status of the function.

The function netETH_SendRaw sends the raw Ethernet data to a remote machine. The data must contain Ethernet header and payload data. This allows the users to implement additional Ethernet protocols, which are not supported by the network library.

The argument if_num specifies the Ethernet interface which is used for sending.

The argument buf points to a buffer containing Ethernet raw data.

The argument len specifies the number of data bytes to send.

Possible netStatus return values:

  • netOK: Data sent successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netWrongState: Ethernet link is down.
  • netDriverError: Ethernet driver internal error.
  • netBusy: Ethernet transmitter is busy.

Code Example

void netETH_ReceiveRaw (uint32_t if_num, const uint8_t *buf, uint32_t len) {
uint8_t echo_buf[60];
// Echo small packets
if (len <= 60) {
memcpy (&echo_buf[0], &buf[6], 6); // Destination MAC address
memcpy (&echo_buf[6], &buf[0], 6); // Source MAC address
memcpy (&echo_buf[12], &buf[12], len-12); // EtherType + data
netETH_SendRaw (if_num, echo_buf, len);
}
}
netStatus netIGMP_Join ( uint32_t  if_num,
const uint8_t *  ip4_addr 
)

Join this host to a host group specified with IP address. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip4_addrgroup IPv4 address.
Returns
status code that indicates the execution status of the function.

The function netIGMP_Join requests that a host should become a member of the host group identified by ip4_addr.

The argument if_num is the interface number of the host.

The argument ip4_addr points to the address of the group. Before any datagrams destined to a particular group can be received, an upper-layer protocol must ask the IP module to join that group.

Possible netStatus return values:

  • netOK: Joining the group successful.
  • netInvalidParameter: Invalid parameter provided.
  • netError: No free entries in IGMP table.
Note
This function can only be used with IPv4. Currently, no similar functionality is provided for IPv6.

Code Example

void Server_Thread (void *arg) {
SOCKADDR_IN recaddr;
int sock, sd, res, addrlen;
int type = (int)arg;
char dbuf[10];
const uint8_t ip4_addr[NET_ADDR_IP4_LEN] = { 238, 0, 100, 1 };
char ip_ascii[16];
if (netIGMP_Join (0, ip4_addr) == netOK) {
netIP_ntoa (NET_ADDR_IP4, ip4_addr, ip_ascii, sizeof(ip_ascii));
printf ("This Host is a member of group: %s\n", ip_ascii);
}
else {
printf ("Failed to join a host group.\n");
}
while (1) {
// Setup network parameters
memset (&addr, 0, sizeof(addr));
// Accept only IPv4 connections
addr.sin_port = htons(SOCK_PORT);
// Create socket
sock = socket (addr.sin_family, type, 0);
// Bind address and port to socket
uint8_t mcast_ip1[NET_ADDR_IP4_LEN] = {239, 128, 0, 1};
addr.sin_addr.s_b1 = mcast_ip1[0];
addr.sin_addr.s_b2 = mcast_ip1[1];
addr.sin_addr.s_b3 = mcast_ip1[2];
addr.sin_addr.s_b4 = mcast_ip1[3];
bind (sock, (SOCKADDR *)&addr, sizeof(addr));
listen (sock, 1);
sd = accept (sock, NULL, NULL);
closesocket (sock);
sock = sd;
while (1) {
res = recv (sock, dbuf, sizeof (dbuf), 0);
if (res <= 0) {
break;
}
if (dbuf[0] == BLINKLED) {
LED_SetOut (dbuf[1]);
}
}
closesocket (sock);
}
}
netStatus netIGMP_Leave ( uint32_t  if_num,
const uint8_t *  ip4_addr 
)

Leave a host group specified with IP address. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip4_addrgroup IPv4 address.
Returns
status code that indicates the execution status of the function.

The function netIGMP_Leave requests a host to give up its membership in a host group.

The argument if_num is the host interface number.

The argument ip4_addr points to the host group. After the upper-layer has requested to leave the host group, datagrams destined to a particular group can not be received, but are silently discarded by the IP-layer.

Possible netStatus return values:

  • netOK: Leaving the group successful.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Not member of requested host group.
Note
This function can only be used with IPv4. Currently, no similar functionality is provided for IPv6.

Code Example

const uint8_t ip4_addr[NET_ADDR_IP4_LEN] = { 238, 0, 100, 1 };
char ip_ascii[16];
..
if (netIGMP_Leave (0, ip4_addr) == netOK) {
netIP_ntoa (NET_ADDR_IP4, ip4_addr, ip_ascii, sizeof(ip_ascii));
printf ("This Host has left the group: %s\n", ip_ascii);
}
else {
printf ("Failed to leave a group, this host is not a member.\n");
}
netStatus netNDP_CacheIP ( uint32_t  if_num,
const uint8_t *  ip6_addr 
)

Determine whether neighbor cache has MAC address resolved for requested IP address. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip6_addrrequested IPv6 address.
Returns
status code that indicates the execution status of the function.

The function netNDP_CacheIP determines whether the NDP table has already an entry for the requested IPv6 address ip6_addr. If an entry does not exist, the function forces the Network Core to resolve and cache the IP address into the internal NDP table buffer.

The argument if_num is the Ethernet interface number for which to cache the NDP table.

The argument ip6_addr points to a buffer containing the IPv6 address.

Possible netStatus return values:

  • netOK: MAC address resolved successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Gateway IPv6 address is undefined.

Code Example

uint8_t mac_addr [NET_ADDR_ETH_LEN];
uint8_t ip6_addr [NET_ADDR_IP6_LEN];
..
netIP_aton ("fe80::1c30:6cff:fea2:455e", NET_ADDR_IP6, ip6_addr);
if (netNDP_GetMAC (0, ip6_addr, mac_addr) != netOK) {
// Requested IP address not yet cached
netNDP_CacheIP (0, ip6_addr);
}
netStatus netNDP_GetIP ( uint32_t  if_num,
const uint8_t *  mac_addr,
uint8_t *  ip6_addr 
)

Get IP address from neighbor discovery cache. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]mac_addrrequested MAC address.
[out]ip6_addrresolved IPv6 address.
Returns
status code that indicates the execution status of the function.

The function netNDP_GetIP determines the resolved IPv6 address for a specific MAC address.

The argument if_num is the Ethernet interface number to be used.

The argument mac_addr points to a buffer containing the MAC address.

The argument ip6_addr points to a buffer that stores the resolved IPv6 address.

Possible netStatus return values:

  • netOK: IPv6 address copied to a buffer.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Requested MAC address not found in NDP table.

Code Example

uint8_t mac_addr [NET_ADDR_ETH_LEN];
uint8_t ip6_addr [NET_ADDR_IP6_LEN];
..
netMAC_aton ("1E-30-6C-A2-45-5E", mac_addr);
if (netNDP_GetIP (0, mac_addr, ip6_addr) == netOK) {
// MAC address found in ND cache
}
netStatus netNDP_GetMAC ( uint32_t  if_num,
const uint8_t *  ip6_addr,
uint8_t *  mac_addr 
)

Get MAC address from neighbor discovery cache. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip6_addrrequested IPv6 address.
[out]mac_addrresolved MAC address.
Returns
status code that indicates the execution status of the function.

The function netNDP_GetMAC determines the resolved MAC address for a specific IPv6 address.

The argument if_num is the Ethernet interface number to be used.

The argument ip6_addr points to a buffer containing the IPv6 address.

The argument mac_addr points to a buffer that stores the resolved six octets of the MAC address.

Possible netStatus return values:

  • netOK: MAC address copied to a buffer.
  • netInvalidParameter: Invalid parameter provided.
  • netError: Requested IPv6 address not found in NDP table.

Code Example

uint8_t ip6_addr [NET_ADDR_IP6_LEN];
uint8_t mac_addr [NET_ADDR_ETH_LEN];
char addr_ascii[40];
..
netIP_aton ("fe80::1c30:6cff:fea2:455e", NET_ADDR_IP6, ip6_addr);
if (netNDP_GetMAC (0, ip6_addr, mac_addr) == netOK) {
printf ("Requested IP address: %s\n", addr_ascii);
netMAC_ntoa (mac_addr, addr_ascii, sizeof (addr_ascii));
printf ("Resolved MAC address: %s\n", addr_ascii);
}
netStatus netNDP_Probe ( uint32_t  if_num,
const uint8_t *  ip6_addr,
netNDP_cb_t  cb_func 
)

Determine whether the IP address is already in use. [thread-safe].

Parameters
[in]if_numinterface_number.
[in]ip6_addrrequested IPv6 address.
[in]cb_funccallback function to call, when probe session ends.
Returns
status code that indicates the execution status of the function.

The function netNDP_Probe determines whether the requested IPv6 address is already used in local area network. You can use this function to check for IPv6 address collisions.

The argument if_num is the Ethernet interface number for which to check the IPv6 address.

The argument ip6_addr points to a buffer containing the IPv6 address to be checked.

The argument cb_func points to an event callback function called by the Network Core when the probe session ends. Refer to netNDP_cb_t.

Possible netStatus return values:

  • netOK: Probe process started successfully.
  • netInvalidParameter: Invalid parameter provided.
  • netBusy: Probe process is busy.

Refer to

Note
This function can only be used with IPv6. For IPv4 similar functionality is provided by netARP_Probe.

Code Example

uint8_t ip6_addr[NET_ADDR_IP6_LEN];
static void probe_callback (netNDP_Event event) {
switch (event) {
printf ("Response received, IP address is in use.\n");
break;
printf ("Probe timeout, no response.\n");
break;
}
}
..
netIP_aton ("fe80::1c30:6cff:fea2:455e", NET_ADDR_IP6, ip6_addr);
if (netNDP_Probe (0, ip6_addr, probe_callback) == netOK) {
printf("Probe started.\n");
}
else {
printf("Probe not ready or bad parameters.\n");
}