summaryrefslogtreecommitdiff
path: root/package/ramips/applications/hwnat/src/mtr_api.c
blob: 2512478b1c178cccb246bb9794cde1a8b9438cc0 (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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <getopt.h>
#include "mtr_ioctl.h"

int SetMtrEntry(struct mtr_args *opt, unsigned int cmd)
{
    int fd;

    fd = open("/dev/"MTR_DEVNAME, O_RDONLY);
    if (fd < 0)
    {
        printf("Open %s pseudo device failed\n","/dev/"MTR_DEVNAME);
        return MTR_FAIL;
    }

    if(ioctl(fd, cmd, opt)<0)
    {
        printf("MTR_API: ioctl error\n");
        close(fd);
        return MTR_FAIL;
    }

    close(fd);
    return MTR_SUCCESS;
}

int MtrGetAllEntries(struct mtr_list_args *opt)
{
    int fd=0;

    fd = open("/dev/"MTR_DEVNAME, O_RDONLY);
    if (fd < 0)
    {
        printf("Open %s pseudo device failed\n","/dev/"MTR_DEVNAME);
        return MTR_FAIL;
    }

    if(ioctl(fd, MTR_GET_ALL_ENTRIES, opt)<0)
    {
        printf("MTR_API: ioctl error\n");
        close(fd);
        return MTR_FAIL;
    }

    close(fd);

    return MTR_SUCCESS;

}