#include "stdhead.h"
#include "clilib.h"
#include "parse.h"
void write_to_log (char * str, int time_flag)
{
extern int event_log_fd;
time_t curr_time;
int time_length;
char *str_curr_time;
if (time_flag)
{
curr_time = time (&curr_time);
str_curr_time = ctime (&curr_time);
write (event_log_fd, str_curr_time, strlen(str_curr_time));
write (event_log_fd, "\t", 1);
}
if ((write (event_log_fd, str, strlen (str))) == -1)
printf ("Failed to log event.\n");
if (time_flag)
write (event_log_fd, "\n", 1);
}
// Build message linked-list from character buffer
void build_linked_list (char *m, int len, struct DHCP_MESSAGE *dhcp_message)
{
int index = 0, i;
struct OPTIONS *opt;
dhcp_message -> u_msg_type.buffer[0] = m[index++];
for (i = 2; i >= 0; i--)
dhcp_message -> u_trans_id.buffer[i] = m[index++];
dhcp_message -> u_trans_id.buffer[3] = 0;
opt = (struct OPTIONS *) malloc (sizeof (struct OPTIONS));
read_option (m, index, len, opt);
dhcp_message -> opt = opt;
}
void print_linked_list_contents (struct DHCP_MESSAGE *dhcp_message)
{
struct OPTIONS *q;
struct DUID *d;
struct DUID1 *d1;
struct DUID2 *d2;
struct DUID3 *d3;
struct IA *ia;
struct IA_ADDRESS *ia_addr;
struct PREFERENCE *preference;
struct STATUS_CODE *sc_ptr;
int i;
char name[64];
printf ("Message type = %d\n", dhcp_message -> u_msg_type.msg_type);
printf ("Transaction ID = %d\n\n", dhcp_message -> u_trans_id.trans_id);
q = dhcp_message -> opt;
if (!q)
{
printf ("No options defined!\n");
return;
}
do
{
switch (q -> u_opt_code.opt_code)
{
case OPTION_CLIENTID :
case OPTION_SERVERID :
//printf ("Option type = %d\n", q -> u_opt_code.opt_code);
//printf ("DUID length = %d\n", q -> u_opt_len.opt_len);
d = q -> opt_data;
//printf ("DUID type = %d\n", d -> u_duid_type.duid_type);
if (d -> u_duid_type.duid_type == 1)
{
d1 = d -> duid_type;
//printf ("Time = %d\n", d1 -> u_time.time);
//printf ("Hardware type = %d\nHardware address = ", d1 -> u_haddr_type.haddr_type);
for (i = 0; i < 6; i++)
{
printf ("%x", d1 -> link_layer_address[i]);
if (i != 5)
printf (":");
}
//printf ("\n\n");
}
else if (d -> u_duid_type.duid_type == 2)
{
d2 = d -> duid_type;
//printf ("Identifier length = %d\nIdentifier = ", d2 -> u_identifier_length.identifier_length);
//for (i = 0; i < d2 -> u_identifier_length.identifier_length; i++)
// printf ("%d", d2 -> identifier[i]);
// printf ("\nDomain name = ");
//for (i = 0; i < d2 -> domain_name_len; i++)
// printf ("%c", d2 -> domain_name[i]);
}
else if (d -> u_duid_type.duid_type == 3)
{
d3 = d -> duid_type;
// printf ("Hardware type = %d\nHardware address = ", d3 -> u_haddr_type.haddr_type);
for (i = 0; i < 6; i++)
{
printf ("%x", d3 -> link_layer_address[i]);
if (i != 5)
printf (":");
}
printf ("\n\n");
}
q = d -> opt;
break;
case OPTION_IA :
// printf ("Option type = IA option\n");
// printf ("option length = %d\n", q -> u_opt_len.opt_len);
ia = q -> opt_data;
// printf ("IAID = %x\n", ia -> u_iaid.iaid);
// printf ("T1 = %d\n", ia -> u_t1.t1);
// printf ("T2 = %d\n", ia -> u_t2.t2);
// printf ("Status code for IA = %d\n\n", ia -> status);
q = ia -> opt;
break;
case OPTION_IAADDR :
// printf ("Option type = IA address option\n");
// printf ("option length = %d\n", q -> u_opt_len.opt_len);
ia_addr = q -> opt_data;
// printf ("Temporary address bit = %d\n", ia_addr -> t_bit);
// printf ("Address status = %d\n", ia_addr -> addr_status);
// printf ("Prefix length of the address = %d\n", ia_addr -> prefix_length);
printf ("IPv6 Address = %s\n", inet_ntop (AF_INET6, ia_addr -> addr, name, 64));
printf ("Preferred lifetime = %d\n" , ia_addr -> u_pref_lifetime.pref_lifetime);
printf ("Valid lifetime = %d\n", ia_addr -> u_valid_lifetime.valid_lifetime);
q = ia_addr -> opt;
break;
case OPTION_PREFERENCE :
// printf ("Option type = Preference Option\n");
// printf ("Option length = %d\n", q -> u_opt_len.opt_len);
preference = q -> opt_data;
// printf ("Preference value = %d\n\n", preference -> preference_value);
q = preference -> opt;
break;
case OPTION_STATUS_CODE :
// printf ("Option type = Status code\n");
// printf("Option length = %d\n",q->u_opt_len.opt_len);
sc_ptr = q->opt_data;
// printf( "Status code = %d\nStatus message =",sc_ptr->u_status_code.status_code);
//for(i=0; i < q->u_opt_len.opt_len -2; i++)
// printf("%c", sc_ptr->message[i]);
// printf("\n\n");
q=sc_ptr->opt;
break;
default :
printf ("Invalid option type\n\n");
q = 0;
return;
}
}
while (q);
}
// This function returns the generated random number in between -0.1 and +0.1
float generate_rand ()
{
time_t t1;
// call srand with the current time as the seed
srand (time (&t1));
// Return a random vakue between -0.1 and +0.1
return ((float)((rand()%200)-100)/1000.0);
}
// This function returns a random number in between the defined constants.
int calculate_initial_delay ()
{
time_t t1;
int random;
// call srand with the current time as the seed
srand (time (&t1));
// Calculate and return a random number between MAX_SOL_DELAY and MIN_SOL_DELAY
random = rand () % (MAX_SOL_DELAY);
if (random < (MIN_SOL_DELAY))
random += (MIN_SOL_DELAY);
return random;
}
/* This function calculates the timeout upon the expiry of which the
retransmission is to be done. */
float calculate_retransmission_timeout (float RTprev, float mrt)
{
float rt = ((2.0 * RTprev) + (generate_rand () * RTprev));
if (mrt != 0)
while (rt > mrt)
rt = mrt + generate_rand () * mrt;
return rt;
}
/* This function checks whether that particular option exists in the linked
list. It returns 1on success and 0 on failure. */
int check_for_option (int option, struct DHCP_MESSAGE *dhcp_msg_ptr)
{
struct OPTIONS * opt;
struct DUID *duid_ptr;
struct IA *ia_ptr;
struct IA_ADDRESS * iaaddr_ptr;
struct STATUS_CODE * status_ptr;
struct PREFERENCE * preference;
// Move to the first option node
opt= dhcp_msg_ptr->opt;
// Until there are no moer options in the message
while ( opt !=0)
{
// If the required option is found then return 1
if (opt->u_opt_code.opt_code == option)
return 1;
// Depending on the option code
switch(opt->u_opt_code.opt_code)
{
case OPTION_CLIENTID :
case OPTION_SERVERID :
// Move to the next node
duid_ptr = (struct DUID *) opt -> opt_data;
opt = duid_ptr->opt;
break;
case OPTION_IA :
// Move to the next node
ia_ptr= (struct IA *) opt -> opt_data;
opt= ia_ptr->opt;
break;
case OPTION_IAADDR :
// Move to the next node
iaaddr_ptr=(struct IA_ADDRESS *) opt -> opt_data;
opt=iaaddr_ptr->opt;
break;
case OPTION_STATUS_CODE :
// Move to the next node
status_ptr=(struct STATUS_CODE *) opt -> opt_data;
opt=status_ptr->opt;
break;
case OPTION_PREFERENCE :
// Move to the next node
preference = (struct PREFERENCE *) opt -> opt_data;
opt = preference -> opt;
break;
default :
opt = 0;
break;
}
}
return 0;
}
int check_for_status (struct DHCP_MESSAGE *dhcp_msg_ptr)
{
struct OPTIONS *options_ptr;
struct DUID *duid_ptr;
struct IA *ia_ptr;
struct IA_ADDRESS * iaaddr_ptr;
struct STATUS_CODE * status_ptr;
struct PREFERENCE * preference_ptr;
// Move to the first option node
options_ptr= dhcp_msg_ptr->opt;
// Until there are no moer options in the message
while (options_ptr !=0)
{
// Depending on the option code
switch(options_ptr -> u_opt_code.opt_cod
没有合适的资源?快使用搜索试试~ 我知道了~
dhcpv6-linux-1.0.zip_DHCPV6 linux_DHCPv6_IPV6 DHCP_dhcpv6 client
共56个文件
h:31个
c:16个
conf:4个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 186 浏览量
2022-09-24
00:20:18
上传
评论
收藏 53KB ZIP 举报
温馨提示
关于Linux下DHCP支持IPv6的版本实现,可以参考一下。
资源推荐
资源详情
资源评论
收起资源包目录
dhcpv6-linux-1.0.zip (56个子文件)
client
solicit.c 6KB
rebind.c 1KB
request.c 2KB
stdhead.h 202B
message_type.h 257B
states.h 144B
rebind.h 77B
macros.h 337B
solicit.conf 279B
renew.c 1KB
struct.h 3KB
release.h 78B
solicit.conf.syntax 551B
options_type.h 153B
renew.h 76B
client.c 18KB
request.h 145B
decline.c 1KB
release.c 1KB
head.h 365B
constants.h 327B
solicit.h 284B
clilib.h 2KB
status_codes.h 332B
parse.c 8KB
Makefile 1KB
parse.h 256B
decline.h 78B
clilib.c 55KB
timer_val.h 1KB
dhcpv6_client.c 2KB
server
reply.c 6KB
server.c 12KB
leases6.conf 65B
stdhead.h 159B
message_type.h 257B
lib.h 1KB
dhcpd6.conf.syntax 952B
macros.h 337B
struct.h 4KB
dhcpd6.conf 333B
leases.h 1KB
options_type.h 153B
reply.h 444B
head.h 271B
constants.h 476B
leases.c 24KB
advertise.h 420B
status_codes.h 334B
parse.c 14KB
partial_leases6.conf 0B
Makefile 763B
parse.h 348B
advertise.c 5KB
lib.c 36KB
www.pudn.com.txt 218B
共 56 条
- 1
资源评论
- coolmlhe2024-03-19资源内容详细全面,与描述一致,对我很有用,有一定的使用价值。
JonSco
- 粉丝: 66
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功