Print out the lease time, just to show how easy it is.

pull/1/head
Michael Brown 2006-07-20 03:02:34 +00:00
parent 16d04386b6
commit 7ca8bcd98c
2 changed files with 18 additions and 8 deletions

View File

@ -74,6 +74,9 @@
/** Requested IP address */ /** Requested IP address */
#define DHCP_REQUESTED_ADDRESS 50 #define DHCP_REQUESTED_ADDRESS 50
/** Lease time */
#define DHCP_LEASE_TIME 51
/** Option overloading /** Option overloading
* *
* The value of this option is the bitwise-OR of zero or more * The value of this option is the bitwise-OR of zero or more

View File

@ -22,10 +22,20 @@ int test_dhcp ( struct net_device *netdev ) {
if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 ) if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 )
goto out_no_options; goto out_no_options;
/* Register options received via DHCP */
register_dhcp_options ( dhcp.options );
/* Retrieve IP address configuration */ /* Retrieve IP address configuration */
find_dhcp_ipv4_option ( dhcp.options, DHCP_EB_YIADDR, &address ); find_global_dhcp_ipv4_option ( DHCP_EB_YIADDR, &address );
find_dhcp_ipv4_option ( dhcp.options, DHCP_SUBNET_MASK, &netmask ); find_global_dhcp_ipv4_option ( DHCP_SUBNET_MASK, &netmask );
find_dhcp_ipv4_option ( dhcp.options, DHCP_ROUTERS, &gateway ); find_global_dhcp_ipv4_option ( DHCP_ROUTERS, &gateway );
printf ( "IP %s", inet_ntoa ( address ) );
printf ( " netmask %s", inet_ntoa ( netmask ) );
printf ( " gateway %s\n", inet_ntoa ( gateway ) );
printf ( "Lease time is %ld seconds\n",
find_global_dhcp_num_option ( DHCP_LEASE_TIME ) );
/* Remove old IP address configuration */ /* Remove old IP address configuration */
del_ipv4_address ( netdev ); del_ipv4_address ( netdev );
@ -35,11 +45,8 @@ int test_dhcp ( struct net_device *netdev ) {
gateway ) ) != 0 ) gateway ) ) != 0 )
goto out_no_del_ipv4; goto out_no_del_ipv4;
printf ( "IP %s", inet_ntoa ( address ) ); /* Unregister and free DHCP options */
printf ( " netmask %s", inet_ntoa ( netmask ) ); unregister_dhcp_options ( dhcp.options );
printf ( " gateway %s\n", inet_ntoa ( gateway ) );
/* Free DHCP options */
free_dhcp_options ( dhcp.options ); free_dhcp_options ( dhcp.options );
out_no_options: out_no_options:
/* Take down IP interface */ /* Take down IP interface */