]>
Commit | Line | Data |
---|---|---|
f043759d RA |
1 | /* |
2 | * misc.c Miscellaneous TIPC helper functions. | |
3 | * | |
4 | * This program is free software; you can redistribute it and/or | |
5 | * modify it under the terms of the GNU General Public License | |
6 | * as published by the Free Software Foundation; either version | |
7 | * 2 of the License, or (at your option) any later version. | |
8 | * | |
9 | * Authors: Richard Alpe <richard.alpe@ericsson.com> | |
10 | */ | |
11 | ||
12 | #include <stdio.h> | |
13 | #include <stdint.h> | |
14 | #include <linux/tipc.h> | |
15 | ||
16 | #include "misc.h" | |
17 | ||
18 | #define IN_RANGE(val, low, high) ((val) <= (high) && (val) >= (low)) | |
19 | ||
20 | uint32_t str2addr(char *str) | |
21 | { | |
22 | unsigned int z, c, n; | |
23 | char dummy; | |
24 | ||
25 | if (sscanf(str, "%u.%u.%u%c", &z, &c, &n, &dummy) != 3) { | |
26 | fprintf(stderr, "invalid network address, syntax: Z.C.N\n"); | |
27 | return 0; | |
28 | } | |
29 | ||
30 | if (IN_RANGE(z, 0, 255) && IN_RANGE(c, 0, 4095) && IN_RANGE(n, 0, 4095)) | |
31 | return tipc_addr(z, c, n); | |
32 | ||
33 | fprintf(stderr, "invalid network address \"%s\"\n", str); | |
34 | return 0; | |
35 | } |