Skip to content

Commit

Permalink
Fixing the AVL bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
mramadas committed Nov 4, 2004
1 parent a9ef558 commit 4a843dd
Show file tree
Hide file tree
Showing 5 changed files with 128 additions and 171 deletions.
8 changes: 4 additions & 4 deletions avl.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,14 +234,14 @@ SnapInsert(
return BALANCE;
}

else if (AVL_CheckHash(&new_node->addr_pair, &((*root)->addr_pair), &dir) == LOW) {
else if (AVL_WhichDir(&new_node->addr_pair, &((*root)->addr_pair)) == LT) {
if ((tmp = SnapInsert(&(*root)->left, new_node)) == BALANCE) {
return SnapLeftGrown(root);
}
return tmp;
}

else if (AVL_CheckHash(&new_node->addr_pair, &((*root)->addr_pair), &dir) == HIGH) {
else if (AVL_WhichDir(&new_node->addr_pair, &((*root)->addr_pair)) == RT) {
if ((tmp = SnapInsert(&(*root)->right, new_node)) == BALANCE) {
return SnapRightGrown(root);
}
Expand Down Expand Up @@ -473,15 +473,15 @@ SnapRemove(
return 0;
}

if (AVL_CheckHash(&addr, &((*root)->addr_pair), &dir) == LOW) {
if (AVL_WhichDir(&addr, &((*root)->addr_pair)) == LT) {
if ((tmp = SnapRemove(&(*root)->left, addr)) == BALANCE) {
return SnapLeftShrunk(root);
}

return tmp;
}

if (AVL_CheckHash(&addr, &((*root)->addr_pair), &dir) == HIGH) {
if (AVL_WhichDir(&addr, &((*root)->addr_pair)) == RT) {
if ((tmp = SnapRemove(&(*root)->right, addr)) == BALANCE) {
return SnapRightShrunk(root);
}
Expand Down
6 changes: 3 additions & 3 deletions flex_bison/filt_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ static const short yycheck[] = { 4,
20, 21, 17, 18, 19, 20, 21, 19, 20, 21
};
/* -*-C-*- Note some compilers choke on comments on `#line' lines. */
#line 3 "/usr/local/share/bison.simple"
#line 3 "/usr/share/bison.simple"
/* This file comes from bison-1.28. */

/* Skeleton output parser for bison,
Expand Down Expand Up @@ -474,7 +474,7 @@ __yy_memcpy (char *to, char *from, unsigned int count)
#endif
#endif

#line 217 "/usr/local/share/bison.simple"
#line 217 "/usr/share/bison.simple"

/* The user can define YYPARSE_PARAM as the name of an argument to be passed
into yyparse. The argument should have type void *.
Expand Down Expand Up @@ -912,7 +912,7 @@ case 27:
break;}
}
/* the action file gets copied in in place of this dollarsign */
#line 543 "/usr/local/share/bison.simple"
#line 543 "/usr/share/bison.simple"

yyvsp -= yylen;
yyssp -= yylen;
Expand Down
36 changes: 18 additions & 18 deletions ipv6.c
Original file line number Diff line number Diff line change
Expand Up @@ -422,44 +422,44 @@ void IP_COPYADDR (ipaddr *toaddr, ipaddr fromaddr)
/*
* ipsameaddr: test for equality of two IPv4 or IPv6 addresses
*/
int IP_SAMEADDR (ipaddr addr1, ipaddr addr2)
int IP_SAMEADDR (ipaddr *addr1, ipaddr *addr2)
{
int ret = 0;
if (ADDR_ISV6(&addr1)) {
if (ADDR_ISV6(&addr2))
ret = (memcmp(addr1.un.ip6.s6_addr,
addr2.un.ip6.s6_addr,16) == 0);
if (ADDR_ISV6(addr1)) {
if (ADDR_ISV6(addr2))
ret = (memcmp(addr1->un.ip6.s6_addr,
addr2->un.ip6.s6_addr,16) == 0);
} else {
if (ADDR_ISV4(&addr2))
ret = (addr1.un.ip4.s_addr == addr2.un.ip4.s_addr);
if (ADDR_ISV4(addr2))
ret = (addr1->un.ip4.s_addr == addr2->un.ip4.s_addr);
}
if (debug > 3)
printf("SameAddr(%s(%d),%s(%d)) returns %d\n",
HostName(addr1), ADDR_VERSION(&addr1),
HostName(addr2), ADDR_VERSION(&addr2),
HostName(*addr1), ADDR_VERSION(addr1),
HostName(*addr2), ADDR_VERSION(addr2),
ret);
return ret;
}

/*
* iplowaddr: test if one IPv4 or IPv6 address is lower than the second one
*/
int IP_LOWADDR (ipaddr addr1, ipaddr addr2)
int IP_LOWADDR (ipaddr *addr1, ipaddr *addr2)
{
int ret = 0;
if (ADDR_ISV6(&addr1)) {
if (ADDR_ISV6(&addr2))
ret = (memcmp(addr1.un.ip6.s6_addr,
addr2.un.ip6.s6_addr,16) < 0);
if (ADDR_ISV6(addr1)) {
if (ADDR_ISV6(addr2))
ret = (memcmp(addr1->un.ip6.s6_addr,
addr2->un.ip6.s6_addr,16) < 0);
} else {
if (ADDR_ISV4(&addr2))
ret = (addr1.un.ip4.s_addr < addr2.un.ip4.s_addr);
if (ADDR_ISV4(addr2))
ret = (addr1->un.ip4.s_addr < addr2->un.ip4.s_addr);
}

if (debug > 3)
printf("LowAddr(%s(%d),%s(%d)) returns %d\n",
HostName(addr1), ADDR_VERSION(&addr1),
HostName(addr2), ADDR_VERSION(&addr2),
HostName(*addr1), ADDR_VERSION(addr1),
HostName(*addr2), ADDR_VERSION(addr2),
ret);
return ret;
}
Expand Down
16 changes: 9 additions & 7 deletions tcptrace.h
Original file line number Diff line number Diff line change
Expand Up @@ -875,8 +875,8 @@ int CompIsCompressed(void);
Bool FileIsStdin(char *filename);
struct tcb *ptp2ptcb(tcp_pair *ptp, struct ip *pip, struct tcphdr *ptcp);
void IP_COPYADDR (ipaddr *toaddr, ipaddr fromaddr);
int IP_SAMEADDR (ipaddr addr1, ipaddr addr2);
int IP_LOWADDR (ipaddr addr1, ipaddr addr2);
int IP_SAMEADDR (ipaddr *addr1, ipaddr *addr2);
int IP_LOWADDR (ipaddr *addr1, ipaddr *addr2);
void PcapSavePacket(char *filename, struct ip *pip, void *plast);
void StringToArgv(char *buf, int *pargc, char ***pargv);
void CopyAddr(tcp_pair_addrblock *, struct ip *pip,portnum,portnum);
Expand Down Expand Up @@ -909,9 +909,7 @@ void freequad(quadrant **);
/* AVL tree support routines */
enum AVLRES SnapInsert(ptp_snap **n, ptp_snap *new_node);
enum AVLRES SnapRemove(ptp_snap **n, tcp_pair_addrblock address);
int AVL_CheckHash(tcp_pair_addrblock *ptpa1,
tcp_pair_addrblock *ptpa2, int *pdir);
int AVL_CheckDir(tcp_pair_addrblock *ptpa1, tcp_pair_addrblock *ptpa2);
int AVL_WhichDir(tcp_pair_addrblock *ptpa1, tcp_pair_addrblock *ptpa2);

/* high-level line drawing */
PLINE new_line(PLOTTER pl, char *label, char *color);
Expand Down Expand Up @@ -956,8 +954,12 @@ of bits as specified in RFC 2481 and draft-ietf-tsvwg-ecn-04.txt */
#define B2A -1

/* If the AVL node is to left or right in the AVL tree */
#define LOW 2
#define HIGH 3
/* Words "LEFT" and "RIGHT" have already been taken in an enum
* above. Let us call them LT, RT just not to make it ambiguous for ourselves
* or the compiler or both :-)
*/
#define LT -2
#define RT 2

/*macros for maintaining the seqspace used for rexmit*/
#define QUADSIZE (0x40000000)
Expand Down
Loading

0 comments on commit 4a843dd

Please sign in to comment.