Browse Source

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

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
7ca8bcd98c
2 changed files with 18 additions and 8 deletions
  1. 3
    0
      src/include/gpxe/dhcp.h
  2. 15
    8
      src/tests/dhcptest.c

+ 3
- 0
src/include/gpxe/dhcp.h View File

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

+ 15
- 8
src/tests/dhcptest.c View File

@@ -22,10 +22,20 @@ int test_dhcp ( struct net_device *netdev ) {
22 22
 	if ( ( rc = async_wait ( start_dhcp ( &dhcp ) ) ) != 0 )
23 23
 		goto out_no_options;
24 24
 
25
+	/* Register options received via DHCP */
26
+	register_dhcp_options ( dhcp.options );
27
+
25 28
 	/* Retrieve IP address configuration */
26
-	find_dhcp_ipv4_option ( dhcp.options, DHCP_EB_YIADDR, &address );
27
-	find_dhcp_ipv4_option ( dhcp.options, DHCP_SUBNET_MASK, &netmask );
28
-	find_dhcp_ipv4_option ( dhcp.options, DHCP_ROUTERS, &gateway );
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 );
32
+
33
+	printf ( "IP %s", inet_ntoa ( address ) );
34
+	printf ( " netmask %s", inet_ntoa ( netmask ) );
35
+	printf ( " gateway %s\n", inet_ntoa ( gateway ) );
36
+
37
+	printf ( "Lease time is %ld seconds\n",
38
+		 find_global_dhcp_num_option ( DHCP_LEASE_TIME ) );
29 39
 
30 40
 	/* Remove old IP address configuration */
31 41
 	del_ipv4_address ( netdev );
@@ -35,11 +45,8 @@ int test_dhcp ( struct net_device *netdev ) {
35 45
 				       gateway ) ) != 0 )
36 46
 		goto out_no_del_ipv4;
37 47
 
38
-	printf ( "IP %s", inet_ntoa ( address ) );
39
-	printf ( " netmask %s", inet_ntoa ( netmask ) );
40
-	printf ( " gateway %s\n", inet_ntoa ( gateway ) );
41
-
42
-	/* Free DHCP options */
48
+	/* Unregister and free DHCP options */
49
+	unregister_dhcp_options ( dhcp.options );
43 50
 	free_dhcp_options ( dhcp.options );
44 51
  out_no_options:
45 52
 	/* Take down IP interface */

Loading…
Cancel
Save