File: node_emu.c

package info (click to toggle)
ttt 1.7-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 568 kB
  • ctags: 544
  • sloc: ansic: 4,767; sh: 2,804; tcl: 159; makefile: 136
file content (69 lines) | stat: -rw-r--r-- 1,253 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
/* $Id: node_emu.c,v 0.1 1996/06/30 12:52:56 kjc Exp $ */
/* node_emu.c -- dummy routines of node.c used by viewers */
#include <stdio.h>
#include "ttt.h"
#include "ttt_node.h"

static int nhosts, nprotos, rhosts, rprotos;
static struct t_node node_tab[2][30];

void node_bumptime(void)
{
    nprotos = nhosts = 0;
}

void node_record(long type, long *id, int size)
{
    struct t_node *np;

    if (type < TTTTYPE_HOST) {
	if (nprotos >= 30)
	    return;
	np = &node_tab[0][nprotos++];
    }
    else {
	if (nhosts >= 30)
	    return;
	np = &node_tab[1][nhosts++];
    }

    np->t_type = type;
    np->t_size = size;
    np->t_id[0] = id[0];
#ifdef IPV6
    np->t_id[1] = id[1];
    np->t_id[2] = id[2];
    np->t_id[3] = id[3];
#endif
}

struct t_node *node_getbiggest(long type)
{
    if (type < TTTTYPE_HOST) {
	if (nprotos == 0)
	    return NULL;
	rprotos = 1;
	return &node_tab[0][0];
    }
    else {
	if (nhosts == 0)
	    return NULL;
	rhosts = 1;
	return &node_tab[1][0];
    }
}

struct t_node *node_getnext(struct t_node *np)
{
    if (np->t_type < TTTTYPE_HOST) {
	if (rprotos >= nprotos)
	    return NULL;
	return &node_tab[0][rprotos++];
    }
    else {
	if (rhosts >= nhosts)
	    return NULL;
	return &node_tab[1][rhosts++];
    }
}