/* WARNING: Type propagation algorithm not settling */
void udhcpd_main(int param_1,int param_2)
{
undefined4 uVar1;
int *piVar2;
int iVar3;
__fd_mask *p_Var4;
int iVar5;
undefined1 *puVar6;
undefined4 *puVar7;
int *piVar8;
ssize_t sVar9;
time_t tVar10;
undefined4 *puVar11;
uint uVar12;
uint uVar13;
int local_318;
int local_314;
int local_310;
timeval local_30c;
char acStack_304 [32];
uint local_2e4 [32];
uint auStack_264 [3];
int local_258;
byte local_248;
byte local_247;
byte local_246;
byte local_245;
byte local_244;
byte local_243;
timeval *local_40;
char *local_3c;
__fd_mask *local_38;
byte *local_34;
int *local_30;
int *local_2c;
static_leases = malloc(0xb80) //possible issue identified - semgrep
memset(static_leases,0,0xb80) //possible issue identified - semgrep
memset(&server_config,0,100) //possible issue identified - semgrep
if (param_1 < 2) {
read_config("/etc/udhcpd.conf");
}
else {
read_config(*(undefined4 *)(param_2 + 4));
}
uVar1 = pidfile_acquire(DAT_0041bc84);
pidfile_write_release(uVar1);
piVar2 = (int *)find_option(DAT_0041bc4c,0x33);
if (piVar2 == (int *)0x0) {
DAT_0041bc60 = 0xd2f00;
}
else {
uVar12 = *(uint *)(*piVar2 + 2);
DAT_0041bc60 = uVar12 << 0x18 | uVar12 >> 0x18 | uVar12 >> 8 & 0xff00 | (uVar12 & 0xff00) << 8;
}
piVar2 = (int *)find_option(DAT_0041bc4c,1);
if (piVar2 == (int *)0x0) {
DAT_0041bc9c = 0xff;
}
else {
uVar12 = *(uint *)(*piVar2 + 2);
DAT_0041bc9c = ~(uVar12 << 0x18 | uVar12 >> 0x18 | uVar12 >> 8 & 0xff00 | (uVar12 & 0xff00) << 8
);
}
leases = malloc(DAT_0041bc64 * 0x5c) //possible issue identified - semgrep
memset(leases,0,DAT_0041bc64 * 0x5c);
read_leases(DAT_0041bc80);
write_leases();
iVar3 = read_interface(DAT_0041bc50,&DAT_0041bc54,&server_config,&DAT_0041bc58);
if (iVar3 < 0) {
FUN_004018b0(1);
}
socketpair(1,2,0,(int *)&DAT_0041bbd0);
signal(0x10,(__sighandler_t)&UNK_004018f8) //possible issue identified - semgrep
signal(0xf,(__sighandler_t)&UNK_004018f8) //possible issue identified - semgrep
uVar12 = 0xffffffff;
iVar3 = get_uptime();
iVar3 = iVar3 + DAT_0041bc6c;
local_38 = (__fd_mask *)local_2e4;
local_40 = &local_30c;
local_2c = &local_310;
local_34 = &local_248;
local_3c = acStack_304;
local_30 = &local_314;
switchD_00401f4c_caseD_0:
joined_r0x00401db4:
do {
p_Var4 = local_38;
if ((int)uVar12 < 0) goto LAB_00401f9c;
LAB_00401dc4:
do {
*p_Var4 = 0;
p_Var4 = p_Var4 + 1;
} while (auStack_264 != (uint *)p_Var4);
local_2e4[uVar12 >> 5] = local_2e4[uVar12 >> 5] | 1 << (uVar12 & 0x1f);
local_2e4[DAT_0041bbd0 >> 5] = local_2e4[DAT_0041bbd0 >> 5] | 1 << (DAT_0041bbd0 & 0x1f);
if (DAT_0041bc6c != 0) {
local_30c.tv_sec = get_uptime();
local_30c.tv_sec = iVar3 - local_30c.tv_sec;
local_30c.tv_usec = 0;
if (DAT_0041bc6c == 0) goto LAB_00401e20;
if (0 < local_30c.tv_sec) {
uVar13 = uVar12;
if ((int)uVar12 < (int)DAT_0041bbd0) {
uVar13 = DAT_0041bbd0;
}
iVar5 = select(uVar13 + 1,(fd_set *)local_38,(fd_set *)0x0,(fd_set *)0x0,local_40);
goto joined_r0x00401e50;
}
LAB_00402248:
write_leases();
iVar3 = get_uptime();
iVar3 = iVar3 + DAT_0041bc6c;
goto joined_r0x00401db4;
}
LAB_00401e20:
uVar13 = DAT_0041bbd0;
if ((int)DAT_0041bbd0 < (int)uVar12) {
uVar13 = uVar12;
}
iVar5 = select(uVar13 + 1,(fd_set *)local_38,(fd_set *)0x0,(fd_set *)0x0,(timeval *)0x0);
joined_r0x00401e50:
if (iVar5 == 0) goto LAB_00402248;
if ((iVar5 < 0) && (piVar2 = __errno_location(), *piVar2 != 4)) goto joined_r0x00401db4;
if ((local_2e4[DAT_0041bbd0 >> 5] >> (DAT_0041bbd0 & 0x1f) & 1) != 0) {
sVar9 = read(DAT_0041bbd0,local_2c,4) //possible issue identified - semgrep
if (sVar9 < 0) goto switchD_00401f4c_caseD_0;
if (local_310 == 0xf) {
FUN_004018b0(0);
}
else if (local_310 == 0x10) {
write_leases();
tVar10 = time((time_t *)0x0);
iVar3 = tVar10 + DAT_0041bc6c;
goto joined_r0x00401db4;
}
}
iVar5 = get_packet(auStack_264,uVar12);
if (iVar5 < 0) {
if ((iVar5 != -1) || (piVar2 = __errno_location(), *piVar2 == 4))
goto switchD_00401f4c_caseD_0;
close(uVar12);
LAB_00401f9c:
uVar12 = listen_socket(0,0x43,DAT_0041bc50);
p_Var4 = local_38;
if ((int)uVar12 < 0) {
FUN_004018b0(0);
p_Var4 = local_38;
}
goto LAB_00401dc4;
}
puVar6 = (undefined1 *)get_option(auStack_264,0x35);
if (puVar6 == (undefined1 *)0x0) goto switchD_00401f4c_caseD_0;
puVar7 = (undefined4 *)find_static_lease_by_chaddr(local_34);
puVar11 = puVar7;
if (puVar7 == (undefined4 *)0x0) {
puVar11 = (undefined4 *)find_lease_by_chaddr(local_34);
}
sprintf(local_3c,"%02x:%02x:%02x:%02x:%02x:%02x",(uint)local_248,(uint)local_247,(uint)local_246
,(uint)local_245,(uint)local_244,(uint)local_243) //possible issue identified - semgrep
switch(*puVar6) {
default:
goto switchD_00401f4c_caseD_0;
case 1:
syslog(0xe5,"DHCP: Server receive DISCOVER from %s.",local_3c);
sendOffer(auStack_264);
break;
case 3:
piVar2 = (int *)get_option(auStack_264,0x32);
piVar8 = (int *)get_option(auStack_264,0x36);
syslog(0xe5,"DHCP: Server receive REQUEST from %s.",local_3c);
if (piVar2 != (int *)0x0) {
*local_30 = *piVar2;
}
if (piVar8 != (int *)0x0) {
local_318 = *piVar8;
}
if (puVar11 == (undefined4 *)0x0) {
if (piVar8 != (int *)0x0) goto switchD_00401f4c_caseD_0;
if (piVar2 == (int *)0x0) {
if ((local_258 != 0) && (iVar5 = FUN_0040193c(), iVar5 != 0)) {
sendACK(auStack_264,local_258);
break;
}
}
else {
puVar11 = (undefined4 *)find_lease_by_yiaddr(local_314);
if (puVar11 == (undefined4 *)0x0) {
iVar5 = FUN_0040193c(local_314);
if ((iVar5 == 0) || (iVar5 = check_ip(local_314), iVar5 != 0)) goto LAB_004023a8;
sendACK(auStack_264,local_314);
break;
}
iVar5 = lease_expired(puVar11);
if (iVar5 != 0) {
puVar11[3] = 0;
*puVar11 = 0;
puVar11[1] = 0;
puVar11[2] = 0;
break;
}
}
}
else {
if (piVar8 != (int *)0x0) {
if (((server_config != local_318) || (piVar2 == (int *)0x0)) || (puVar11[4] != local_314))
goto switchD_00401f4c_caseD_0;
LAB_004021a8:
sendACK(auStack_264);
break;
}
if (piVar2 == (int *)0x0) {
if (puVar11[4] == local_258) goto LAB_004021a8;
}
else if (puVar11[4] == local_314) goto LAB_004021a8;
}
LAB_004023a8:
sendNAK(auStack_264);
break;
case 4:
if ((puVar11 == (undefined4 *)0x0) || (puVar11 == puVar7)) goto switchD_00401f4c_caseD_0;
*puVar11 = 0;
puVar11[1] = 0;
puVar11[2] = 0;
puVar11[3] = 0;
iVar5 = get_uptime();
puVar11[5] = iVar5 + DAT_0041bc70;
break;
case 7:
if ((puVar11 == (undefined4 *)0x0) || (puVar11 == puVar7)) {
if (puVar7 == (undefined4 *)0x0) goto switchD_00401f4c_caseD_0;
puVar7[6] = 0;
write_leases();
}
else {
uVar1 = get_uptime();
puVar11[5] = uVar1;
write_leases();
syslog(0xe5,"DHCP: Server receive RELEASE from %s.",local_3c);
}
break;
case 8:
send_inform(auStack_264);
}
} while( true );
}