xj | b04a402 | 2021-11-25 15:01:52 +0800 | [diff] [blame] | 1 | #include <stdlib.h> |
| 2 | #include <stdio.h> |
| 3 | #include <string.h> |
| 4 | #include <sys/ioctl.h> |
| 5 | #include <fcntl.h> |
| 6 | #include <getopt.h> |
| 7 | #include "mtr_ioctl.h" |
| 8 | |
| 9 | int SetMtrEntry(struct mtr_args *opt, unsigned int cmd) |
| 10 | { |
| 11 | int fd; |
| 12 | |
| 13 | fd = open("/dev/"MTR_DEVNAME, O_RDONLY); |
| 14 | if (fd < 0) |
| 15 | { |
| 16 | printf("Open %s pseudo device failed\n","/dev/"MTR_DEVNAME); |
| 17 | return MTR_FAIL; |
| 18 | } |
| 19 | |
| 20 | if(ioctl(fd, cmd, opt)<0) { |
| 21 | printf("MTR_API: ioctl error\n"); |
| 22 | close(fd); |
| 23 | return MTR_FAIL; |
| 24 | } |
| 25 | |
| 26 | close(fd); |
| 27 | return MTR_SUCCESS; |
| 28 | } |
| 29 | |
| 30 | int MtrGetAllEntries(struct mtr_list_args *opt) |
| 31 | { |
| 32 | int fd=0; |
| 33 | |
| 34 | fd = open("/dev/"MTR_DEVNAME, O_RDONLY); |
| 35 | if (fd < 0) |
| 36 | { |
| 37 | printf("Open %s pseudo device failed\n","/dev/"MTR_DEVNAME); |
| 38 | return MTR_FAIL; |
| 39 | } |
| 40 | |
| 41 | if(ioctl(fd, MTR_GET_ALL_ENTRIES, opt)<0) { |
| 42 | printf("MTR_API: ioctl error\n"); |
| 43 | close(fd); |
| 44 | return MTR_FAIL; |
| 45 | } |
| 46 | |
| 47 | close(fd); |
| 48 | |
| 49 | return MTR_SUCCESS; |
| 50 | |
| 51 | } |
| 52 | |