7 int test_dhcp ( struct net_device *netdev ) {
8 struct dhcp_session dhcp;
9 struct in_addr address = { htonl ( 0 ) };
10 struct in_addr netmask = { htonl ( 0 ) };
11 struct in_addr gateway = { INADDR_NONE };
14 /* Bring IP interface up with address 0.0.0.0 */
15 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
19 /* Issue DHCP request */
20 memset ( &dhcp, 0, sizeof ( dhcp ) );
22 if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 )
25 /* Register options received via DHCP */
26 register_dhcp_options ( dhcp.options );
28 /* Retrieve IP address configuration */
29 find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
30 find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
31 find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
33 printf ( "IP %s", inet_ntoa ( address ) );
34 printf ( " netmask %s", inet_ntoa ( netmask ) );
35 printf ( " gateway %s\n", inet_ntoa ( gateway ) );
37 printf ( "Lease time is %ld seconds\n",
38 find_global_dhcp_num_option ( DHCP_LEASE_TIME ) );
40 /* Remove old IP address configuration */
41 del_ipv4_address ( netdev );
43 /* Set up new IP address configuration */
44 if ( ( rc = add_ipv4_address ( netdev, address, netmask,
48 /* Unregister and free DHCP options */
49 unregister_dhcp_options ( dhcp.options );
50 free_dhcp_options ( dhcp.options );
52 /* Take down IP interface */
53 del_ipv4_address ( netdev );