Created
January 3, 2025 06:12
-
-
Save G36maid/c9eeddad2c9a8bd37285ad10ccd478c6 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
#include <stdlib.h> | |
#include <stdint.h> | |
#include "dhcp.h" | |
int main() { | |
// int32_t dhcpParse(uint8_t *pData, uint32_t size); | |
uint8_t dhcp_data[] = { | |
0, 0, // 0: padding | |
1, 4, 255, 255, 255, 0, // 1: subnet mask (255.255.255.0) | |
3, 4, 192, 168, 1, 1, // 3: router (192.168.1.1) | |
4, 4, 192, 168, 1, 2, // 4: time server (192.168.1.2) | |
5, 4, 192, 168, 1, 3, // 5: name server (192.168.1.3) | |
6, 8, 8, 8, 8, 8, 8, 4, 4, 4, // 6: domain name server (8.8.8.8, 8.8.4.4) | |
7, 4, 192, 168, 1, 4, // 7: log server (192.168.1.4) | |
8, 4, 192, 168, 1, 5, // 8: cookie server (192.168.1.5) | |
9, 4, 192, 168, 1, 6, // 9: LPR server (192.168.1.6) | |
10, 4, 192, 168, 1, 7, // 10: impress server (192.168.1.7) | |
11, 4, 192, 168, 1, 8, // 11: resource location server (192.168.1.8) | |
12, 12, 'G', '3', '6', 'A', 'r', 'c', 'h', 'l', 'i', 'n', 'u', 'x', // 12: host name ("MyHost123") | |
19, 1, 1, // 19: IP forward enable (1: enable) | |
20, 1, 0, // 20: source routing disable (0: disable) | |
2, 4, 0x00, 0x00, 0x70, 0x80,// 2: time offset UTC: +8 hours 28800 seconds | |
21, 16 , | |
192, 168, 10, 0, // 21: policy filter (invalid) | |
255, 255, 255, 0, | |
10, 0, 0, 0, | |
255, 0, 0, 0, | |
255 // 255: end | |
}; | |
dhcpParse(dhcp_data, sizeof(dhcp_data)); | |
while (1){ | |
int result = dhcpParse(NULL, 0); | |
if (result == 1) { | |
continue; | |
} else if (result == 0) { | |
printf("%d : End of TLV.\n", result); | |
int end_result = dhcpParse(NULL, 0); | |
printf("%d : no TLVs left. \n", end_result); | |
break; | |
} else if (result == -1) { | |
printf("%d : Invalid input or no TLVs left.\n", result); | |
} | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment