1 /* SPDX-License-Identifier: BSD-3-Clause
2 * Copyright(c) 2010-2014 Intel Corporation.
3 * Copyright (c) 2009, Olivier MATZ <zer0@droids-corp.org>
7 #ifndef _PARSE_IPADDR_H_
8 #define _PARSE_IPADDR_H_
10 #include <cmdline_parse.h>
11 #include <netinet/in.h>
17 #define CMDLINE_IPADDR_V4 0x01
18 #define CMDLINE_IPADDR_V6 0x02
19 #define CMDLINE_IPADDR_NETWORK 0x04
21 struct cmdline_ipaddr {
27 unsigned int prefixlen; /* in case of network only */
29 typedef struct cmdline_ipaddr cmdline_ipaddr_t;
31 struct cmdline_token_ipaddr_data {
35 struct cmdline_token_ipaddr {
36 struct cmdline_token_hdr hdr;
37 struct cmdline_token_ipaddr_data ipaddr_data;
39 typedef struct cmdline_token_ipaddr cmdline_parse_token_ipaddr_t;
41 extern struct cmdline_token_ops cmdline_token_ipaddr_ops;
43 int cmdline_parse_ipaddr(cmdline_parse_token_hdr_t *tk, const char *srcbuf,
44 void *res, unsigned ressize);
45 int cmdline_get_help_ipaddr(cmdline_parse_token_hdr_t *tk, char *dstbuf,
48 #define TOKEN_IPADDR_INITIALIZER(structure, field) \
52 &cmdline_token_ipaddr_ops, /* ops */ \
53 offsetof(structure, field), /* offset */ \
57 CMDLINE_IPADDR_V4 | /* flags */ \
62 #define TOKEN_IPV4_INITIALIZER(structure, field) \
66 &cmdline_token_ipaddr_ops, /* ops */ \
67 offsetof(structure, field), /* offset */ \
71 CMDLINE_IPADDR_V4, /* flags */ \
75 #define TOKEN_IPV6_INITIALIZER(structure, field) \
79 &cmdline_token_ipaddr_ops, /* ops */ \
80 offsetof(structure, field), /* offset */ \
84 CMDLINE_IPADDR_V6, /* flags */ \
88 #define TOKEN_IPNET_INITIALIZER(structure, field) \
92 &cmdline_token_ipaddr_ops, /* ops */ \
93 offsetof(structure, field), /* offset */ \
97 CMDLINE_IPADDR_V4 | /* flags */ \
99 CMDLINE_IPADDR_NETWORK, \
103 #define TOKEN_IPV4NET_INITIALIZER(structure, field) \
107 &cmdline_token_ipaddr_ops, /* ops */ \
108 offsetof(structure, field), /* offset */ \
112 CMDLINE_IPADDR_V4 | /* flags */ \
113 CMDLINE_IPADDR_NETWORK, \
117 #define TOKEN_IPV6NET_INITIALIZER(structure, field) \
121 &cmdline_token_ipaddr_ops, /* ops */ \
122 offsetof(structure, field), /* offset */ \
126 CMDLINE_IPADDR_V4 | /* flags */ \
127 CMDLINE_IPADDR_NETWORK, \
135 #endif /* _PARSE_IPADDR_H_ */