# Network
[Core]

The Network subsystem manages the Ethernet controller. More...

## Functions
int | Network_SetActive (int state)
| Sets whether the Network subsystem is active.
int | Network_GetActive (void)
| Returns the active state of the Network subsystem.
int | Network_SetAddress (int a0, int a1, int a2, int a3)
| Set the IP address of the Make Controller.
int | Network_SetMask (int a0, int a1, int a2, int a3)
| Set the network mask of the Make Controller on your local network.
int | Network_SetGateway (int a0, int a1, int a2, int a3)
| Set the gateway address for the local network the Make Controller is on.
int | Network_GetAddress (int *a0, int *a1, int *a2, int *a3)
| Read the board's current IP address.
int | Network_GetMask (int *a0, int *a1, int *a2, int *a3)
| Read the board's current network mask.
int | Network_GetGateway (int *a0, int *a1, int *a2, int *a3)
| Read the board's current gateway address.
void | Network_SetDhcpEnabled (int enabled)
| Set whether DHCP is enabled.
int | Network_GetDhcpEnabled ()
| Read whether DHCP is currently enabled.
int | Network_DnsGetHostByName (const char *name)
| Resolve the IP address for a given host name.

## Detailed Description

The Network subsystem manages the Ethernet controller.

Like any other network enabled device, the Make Controller has an IP address, net mask and gateway.

- The default IP address is 192.168.0.200
- The default mask is 255.255.255.0
- The default gateway 192.168.0.1

You can set any of these values manually, or use DHCP to get them automatically.

## MAC

The Make Controller's MAC address defaults to AC.DE.48.55.x.y where x & y are calculated from the unit's serial number, handled by the System subsystem.

## Web Server

The Make Controller Kit can also act as a web server. The demo web server running on the Make Controller displays some stats about the board's current state through a web interface. It is intended mainly as a starting point for more useful web applications. See the source in webserver.c.

## Function Documentation

int Network_DnsGetHostByName | ( | const char * | name | ) |

Resolve the IP address for a given host name.

Up to 4 DNS entries are cached, so if you make successive calls to this function, you won't incur a whole lookup roundtrip - you'll just get the cached value. The cached values are maintained internally, so if one of them becomes invalid, a new lookup will be fired off the next time it's asked for.

Parameters:

  | name | A string specifying the name of the host to look up.

Returns:
  An integer representation of the IP address of the host. This can be passed to the Sockets functions to read and write. Returns -1 on error.

Example

      // try to open a socket connection to makingthings.com
      int addr = Network_DnsGetHostByName("makingthings.com");
      struct netconn* socket = Socket(addr, 80); // open up a new connection to that address

Definition at line 956 of file network.c.

int Network_GetActive | ( | void |  | ) |

Returns the active state of the Network subsystem.

Returns:
  State - 1 (active) or 0 (inactive).

Definition at line 646 of file network.c.

int Network_GetAddress | ( | int * | a0,
|  | int * | a1,
|  | int * | a2,
|  | int * | a3 |
| ) |  |  |

Read the board's current IP address.

Pass in pointers to integers where the address should be stored.

Parameters:

  | a0 | A pointer to an integer where the first of 4 numbers of the address is to be stored.
  | a1 | A pointer to an integer where the second of 4 numbers of the address is to be stored.
  | a2 | A pointer to an integer where the third of 4 numbers of the address is to be stored.
  | a3 | A pointer to an integer where the fourth of 4 numbers of the address is to be stored.

Returns:
  0 on success.

Example

        int a0, a1, a2, a3;
        Network_GetAddress( &a0, &a1, &a2, &a3 );
        // now our variables are filled with the current address values

Definition at line 782 of file network.c.

int Network_GetDhcpEnabled | ( | void |  | ) |

Read whether DHCP is currently enabled.

This value is stored presistently, so it will be the same across system reboots.

Returns:
  An integer specifying whether DHCP is enabled - 1 (enabled) or 0 (disabled).

Definition at line 932 of file network.c.

int Network_GetGateway | ( | int * | a0,
|  | int * | a1,
|  | int * | a2,
|  | int * | a3 |
| ) |  |  |

Read the board's current gateway address.

Pass in pointers to integers where the gateway address should be stored.

Parameters:

  | a0 | A pointer to an integer where the first of 4 numbers of the gateway address is to be stored.
  | a1 | A pointer to an integer where the second of 4 numbers of the gateway address is to be stored.
  | a2 | A pointer to an integer where the third of 4 numbers of the gateway address is to be stored.
  | a3 | A pointer to an integer where the fourth of 4 numbers of the gateway address is to be stored.

Returns:
  0 on success.

Example

        int a0, a1, a2, a3;
        Network_GetGateway( &a0, &a1, &a2, &a3 );
        // now our variables are filled with the current gateway values

Definition at line 865 of file network.c.

int Network_GetMask | ( | int * | a0,
|  | int * | a1,
|  | int * | a2,
|  | int * | a3 |
| ) |  |  |

Read the board's current network mask.

Pass in pointers to integers where the mask should be stored.

Parameters:

  | a0 | A pointer to an integer where the first of 4 numbers of the mask is to be stored.
  | a1 | A pointer to an integer where the second of 4 numbers of the mask is to be stored.
  | a2 | A pointer to an integer where the third of 4 numbers of the mask is to be stored.
  | a3 | A pointer to an integer where the fourth of 4 numbers of the mask is to be stored.

Returns:
  0 on success.

Example

        int a0, a1, a2, a3;
        Network_GetMask( &a0, &a1, &a2, &a3 );
        // now our variables are filled with the current mask values

Definition at line 824 of file network.c.

int Network_SetActive | ( | int | state | ) |

Sets whether the Network subsystem is active.

This fires up the networking system on the Make Controller, and will not return until a network is found, ie. a network cable is plugged in.

Parameters:

  | state | An integer specifying the active state - 1 (active) or 0 (inactive).

Returns:
  0 on success.

Definition at line 601 of file network.c.

int Network_SetAddress | ( | int | a0,
|  | int | a1,
|  | int | a2,
|  | int | a3 |
| ) |  |  |

Set the IP address of the Make Controller.

The IP address of the Make Controller, in dotted decimal form (xxx.xxx.xxx.xxx), can be set by passing in each of the numbers as a separate parameter. The default IP address of each Make Controller as it ships from the factory is 192.168.0.200.

This value is stored in EEPROM, so it persists even after the board is powered down.

Parameters:

  | a0 | An integer corresponding to the first of 4 numbers in the address.
  | a1 | An integer corresponding to the second of 4 numbers in the address.
  | a2 | An integer corresponding to the third of 4 numbers in the address.
  | a3 | An integer corresponding to the fourth of 4 numbers in the address.

Returns:
  0 on success.

Example

        // set the address to 192.168.0.23
        Network_SetAddress( 192, 168, 0, 23 );

Definition at line 677 of file network.c.

void Network_SetDhcpEnabled | ( | int | enabled | ) |

Set whether DHCP is enabled.

The Make Controller can use DHCP (Dynamic Host Configuration Protocol) to automatically retrieve an IP address from a router. If you're using your Make Controller on a network with a router, it is generally preferred (and more convenient) to use DHCP. Otherwise, turn DHCP off and set the IP address, mask, and gateway manually.

Wikipedia has a good article about DHCP at http://en.wikipedia.org/wiki/Dynamic_Host_Configuration_Protocol

This value is stored persistently, so it will remain constant across system reboots.

Parameters:

  | enabled | An integer specifying whether to enable DHCP - 1 (enable) or 0 (disable).

Definition at line 901 of file network.c.

int Network_SetGateway | ( | int | a0,
|  | int | a1,
|  | int | a2,
|  | int | a3 |
| ) |  |  |

Set the gateway address for the local network the Make Controller is on.

The gateway address is commonly 192.168.0.1 for many home networks. Set the gateway address in dotted decimal form (xxx.xxx.xxx.xxx), passing in each number as a separate parameter.

This value is stored in EEPROM, so it persists even after the board is powered down.

Parameters:

  | a0 | An integer corresponding to the first of 4 numbers in the gateway address.
  | a1 | An integer corresponding to the second of 4 numbers in the gateway address.
  | a2 | An integer corresponding to the third of 4 numbers in the gateway address.
  | a3 | An integer corresponding to the fourth of 4 numbers in the gateway address.

Returns:
  0 on success.

Example

        // set the gateway to 192.168.5.1
        if( 0 != Network_SetGateway( 192, 168, 5, 1 ) )
          // then there was a problem.

Definition at line 751 of file network.c.

int Network_SetMask | ( | int | a0,
|  | int | a1,
|  | int | a2,
|  | int | a3 |
| ) |  |  |

Set the network mask of the Make Controller on your local network.

When on a subnet or local network, the network mask must be set in order for the gateway to route information to the board's IP address properly. The mask is commonly 255.255.255.0 for many home networks. Set the mask in dotted decimal form (xxx.xxx.xxx.xxx), passing in each number as a separate parameter.

This value is stored in EEPROM, so it persists even after the board is powered down.

Parameters:

  | a0 | An integer corresponding to the first of 4 numbers in the mask.
  | a1 | An integer corresponding to the second of 4 numbers in the mask.
  | a2 | An integer corresponding to the third of 4 numbers in the mask.
  | a3 | An integer corresponding to the fourth of 4 numbers in the mask.

Returns:
  0 on success.

Example

        // set the mask to 255.255.255.254
        if( 0 != Network_SetMask( 255, 255, 255, 254 ) )
          // then there was a problem.

Definition at line 715 of file network.c.