aboutsummaryrefslogtreecommitdiff
path: root/libbb/atlas_probe.c
blob: 8a5c8f0e131f16468c2f3950e6a63bc7b3f99bd1 (plain)
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
/*
 * Copyright (c) 2013 RIPE NCC <atlas@ripe.net>
 * Licensed under GPLv2 or later, see file LICENSE in this tarball for details.
 */

#include "libbb.h"
int get_probe_id(void)
{
        static int probe_id= -1;

        size_t len;
        char *check;
        const char *key;
        FILE *fp;
        char buf[80];

	if (probe_id > 0)
		return probe_id;	/* Assume probe ID never changes */

        fp= fopen("/home/atlas/status/reg_init_reply.txt", "r");
        if (!fp)
                return -1;

        probe_id= -1;
        while (fgets(buf, sizeof(buf), fp) != NULL)
        {
                if (strchr(buf, '\n') == NULL)
                        continue;
                key= "PROBE_ID ";
                len= strlen(key);

                if (strncmp(buf, key, len) != 0 || strlen(buf) <= len)
                        continue;
                probe_id= strtol(buf+len, &check, 10);
                break;
        }
        fclose(fp);
        return probe_id;
}