aboutsummaryrefslogtreecommitdiff
path: root/libbb/atlas_probe.c
blob: a3264fbda2ab2377d7e5c5ddd072bc09c1d66a77 (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
/*
 * 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)
{
        int probe_id;
        size_t len;
        char *check;
        const char *key;
        FILE *fp;
        char buf[80];

        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;
}