Skip to content

Commit

Permalink
Merge pull request #49 from Raizo62/MacOS
Browse files Browse the repository at this point in the history
Patch to : Arp table drop the VPCS if there is some rows in arp-table
  • Loading branch information
grossmj authored Sep 8, 2023
2 parents d40d2e5 + 0999ed5 commit c923aa9
Show file tree
Hide file tree
Showing 13 changed files with 111 additions and 227 deletions.
63 changes: 6 additions & 57 deletions src/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -636,56 +636,6 @@ int run_ping(int argc, char **argv)
return 1;
}

int run_dhcp(int argc, char **argv)
{
int dump = 0;
int flag = 0;
int i;

i = 0;
while (++i < argc) {
if (!strcmp(argv[i], "-d")) {
dump = 1;
continue;
}

if (!strcmp(argv[i], "-r")) {
flag = (flag << 4) + 0x5;
continue;
}

if (!strcmp(argv[i], "-x")) {
flag = (flag << 4) + 0xa;
continue;
}
flag = -1;
break;
}
if (flag == -1)
return help_ip(argc, argv);

switch (flag) {
case 0:
run_dhcp_new(0, dump);
break;
case 0x5:
run_dhcp_new(1, dump);
break;
case 0xa:
run_dhcp_release(dump);
break;
case 0x5a:
run_dhcp_new(1, dump);
run_dhcp_release(dump);
break;
case 0xa5:
run_dhcp_release(dump);
run_dhcp_new(1, dump);
break;
}
return 1;
}

static int run_dhcp_new(int renew, int dump)
{
int i;
Expand Down Expand Up @@ -1083,7 +1033,7 @@ int run_ipconfig(int argc, char **argv)

int run_tracert(int argc, char **argv)
{
int i, j;
int i;
u_int gip, gwip;
struct in_addr in;
int count = 128;
Expand Down Expand Up @@ -1130,7 +1080,7 @@ int run_tracert(int argc, char **argv)
printf("Invalid protocol\n");
return 0;
}
j = atoi(argv[i]);
int j = atoi(argv[i]);
if (j == IPPROTO_ICMP) {
pc->mscb.proto = IPPROTO_ICMP;
} else if (j == IPPROTO_UDP) {
Expand All @@ -1155,7 +1105,7 @@ int run_tracert(int argc, char **argv)
return 0;
}
i++;
j = atoi(argv[i]);
int j = atoi(argv[i]);
if (j > 0 && j <= 64)
count = j;
else {
Expand All @@ -1167,7 +1117,7 @@ int run_tracert(int argc, char **argv)
}
if (digitstring(argv[i])) {
if (count == 128) {
j = atoi(argv[i]);
int j = atoi(argv[i]);
if (j > 0 && j <= 64)
count = j;
else {
Expand Down Expand Up @@ -1364,7 +1314,6 @@ int run_set(int argc, char **argv)

if (argc < 2 || (argc == 2 && strlen(argv[1]) == 1 && argv[1][0] == '?')) {
return help_set(argc, argv);
return 0;
}

if (!strncmp("dump", argv[1], strlen(argv[1]))) {
Expand Down Expand Up @@ -1661,7 +1610,7 @@ int show_arp(int argc, char **argv)
pcs *pc;
int i, j;
struct in_addr in;
char buf[18];
char buf[19];
u_char zero[ETH_ALEN] = {0};
int empty = 1;
int si;
Expand Down Expand Up @@ -1872,7 +1821,7 @@ static int show_ip(int argc, char **argv)
printf("DHCP SERVER : %s\n", inet_ntoa(in));
k = time_tick - vpc[id].ip4.dhcp.timetick;
k = vpc[id].ip4.dhcp.lease - k;
printf("DHCP LEASE : %u, %u/%u/%u\n",
printf("DHCP LEASE : %d, %u/%u/%u\n",
k > 0 ? k : 0,
vpc[id].ip4.dhcp.lease,
vpc[id].ip4.dhcp.renew,
Expand Down
15 changes: 7 additions & 8 deletions src/command6.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ int run_ping6(int argc, char **argv)
struct in6_addr ipaddr;
struct packet *m = NULL;
int i;
char *p;
char proto_seq[16];
int count = 5;

Expand Down Expand Up @@ -100,7 +99,7 @@ int run_ping6(int argc, char **argv)
}

/* find destination */
p = (char*)nbDiscovery(pc, &pc->mscb.dip6);
char *p = (char*)nbDiscovery(pc, &pc->mscb.dip6);
if (p == NULL) {
printf("host (%s) not reachable\n", argv[1]);
return 0;
Expand Down Expand Up @@ -206,7 +205,7 @@ int run_ping6(int argc, char **argv)
} else {
i = 1;
while ((i <= count || count == -1) && !ctrl_c) {
struct packet *p;
struct packet *packet;
struct timeval tv;
int usec;
int respok = 0;
Expand All @@ -232,16 +231,16 @@ int run_ping6(int argc, char **argv)
delay_ms(1);
respok = 0;

while ((p = deq(&pc->iq)) != NULL && !respok &&
while ((packet = deq(&pc->iq)) != NULL && !respok &&
!timeout(tv, pc->mscb.waittime) && !ctrl_c) {

pc->mscb.icmptype = pc->mscb.icmpcode = 0;
respok = response6(p, &pc->mscb);
usec = (p->ts.tv_sec - tv.tv_sec) * 1000000 +
p->ts.tv_usec - tv.tv_usec;
respok = response6(packet, &pc->mscb);
usec = (packet->ts.tv_sec - tv.tv_sec) * 1000000 +
packet->ts.tv_usec - tv.tv_usec;
if (usec < 0)
usec = 0;
del_pkt(p);
del_pkt(packet);

if (respok == 0)
continue;
Expand Down
16 changes: 7 additions & 9 deletions src/dhcp.c
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ int dhcp_rebind(pcs *pc)
/* request */
i = 0;
ok = 0;
while (i < 3 && !ok) {
while (!ok) {
m = dhcp4_request(pc);
if (m == NULL) {
sleep(1);
Expand All @@ -739,14 +739,12 @@ int dhcp_rebind(pcs *pc)
free(p);
}
}
if (ok) {
if (pc->ip4.dhcp.renew == 0)
pc->ip4.dhcp.renew = pc->ip4.dhcp.lease / 2;
if (pc->ip4.dhcp.rebind == 0)
pc->ip4.dhcp.rebind = pc->ip4.dhcp.lease * 7 / 8;
return 1;
}
return 0;

if (pc->ip4.dhcp.renew == 0)
pc->ip4.dhcp.renew = pc->ip4.dhcp.lease / 2;
if (pc->ip4.dhcp.rebind == 0)
pc->ip4.dhcp.rebind = pc->ip4.dhcp.lease * 7 / 8;
return 1;
}

int dhcp_enq(pcs *pc, const struct packet *m)
Expand Down
2 changes: 1 addition & 1 deletion src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ int dmp_packet(const struct packet *m, const int flag)

gettimeofday(&tv, 0);
usec = (tv.tv_sec - gtv.tv_sec) * 1000000 + tv.tv_usec - gtv.tv_usec;
printf("\n\033[32m%04d.%d\033[0m", usec / 1000000, usec % 1000000);
printf("\n\033[32m%04u.%u\033[0m", usec / 1000000, usec % 1000000);
if (flag & DMP_MAC) {
printf(" ");
printf("\033[33m");
Expand Down
18 changes: 0 additions & 18 deletions src/getopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -55,24 +55,6 @@ static int opt_offset = 0; /* Index into compounded "-option" */
static int dashdash = 0; /* True if "--" option reached */
static int nonopt = 0; /* How many nonopts we've found */

int arg_to_int(const char* arg, int min, int max, int defalt)
{
int i = defalt;
int rv;

/* no argument means we use the default value */
if (arg) {
/* make sure we got an integer argument */
rv = sscanf(arg, "%d", &i);
if(rv == 1) {
if(i < min || max < i)
i = defalt;
} else
i = defalt;
}
return i;
}

static void increment_index()
{
/* Move onto the next option */
Expand Down
27 changes: 0 additions & 27 deletions src/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,6 @@ int help_clear(int argc, char **argv)
}


int help_echo(int argc, char **argv)
{
return 1;
}

int help_hist(int argc, char **argv)
{
return 1;
}

int help_relay(int argc, char **argv)
{
char *s[2] = {
Expand Down Expand Up @@ -160,11 +150,6 @@ int help_load(int argc, char **argv)
return 1;
}

int help_neighbor(int argc, char **argv)
{
return 1;
}

int help_ping(int argc, char **argv)
{

Expand Down Expand Up @@ -415,11 +400,6 @@ int help_show(int argc, char **argv)
return 0;
}

int help_version(int argc, char **argv)
{
return 1;
}

int help_sleep(int argc, char **argv)
{
esc_prn("\n{Hsleep} [{Useconds}] [{Utext}]\n"
Expand All @@ -439,13 +419,6 @@ int help_help(int argc, char **argv)
return 1;
}

int help_shut(int argc, char **argv)
{
esc_prn("\n{H%s}, shutdown the process (only in daemon mode)\n", argv[0]);

return 1;
}

int run_help(int argc, char **argv)
{
esc_prn("\n"
Expand Down
Loading

0 comments on commit c923aa9

Please sign in to comment.