Control Area Network - Ethernet - Gateway - Control (Utility)
More...
|
int | main (int argc, char *argv[]) |
| creates an Ethernet package and sends it to a device. More...
|
|
int | nl_cb_general_errno (struct sockaddr_nl *nla, struct nlmsgerr *nlerr, void *arg) |
| A callback wich prints the errno to stderr. More...
|
|
int | nl_cb_list_entry (struct nl_msg *msg, void *arg) |
| will be called for every multipart message and prints informations to stdout. More...
|
|
int | nl_cb_list_finish (struct nl_msg *msg, void *arg) |
| will be called at the end of a multipart message. More...
|
|
int | nl_cb_echo_answer (struct nl_msg *msg, void *arg) |
| Callback witch receive the message sen bach by kernel. More...
|
|
Control Area Network - Ethernet - Gateway - Control (Utility)
The gateway is configured here.
int main |
( |
int |
argc, |
|
|
char * |
argv[] |
|
) |
| |
creates an Ethernet package and sends it to a device.
- Parameters
-
argc | counts the arguments from the console param argv each word from the console is written down in this array |
- Returns
- EXIT_SUCCESS if the program was succesful, EXIT_FAILURE if an error occured
Definition at line 48 of file main.c.
References bidirectional_flag, ce_gw_add(), ce_gw_del(), ce_gw_echo(), ce_gw_list(), F_CAN_FD, nl_sk_fam_exit(), nl_sk_fam_init(), TYPE_ETH, TYPE_NET, TYPE_NONE, TYPE_TCP, TYPE_UDP, and verbose_flag.
55 "Error during initialisation of Socket or Netlink "
63 static struct option long_options[] = {
68 {
"bidirectional", no_argument, 0,
'b'},
69 {
"can-fd", no_argument, 0,
'f'},
70 {
"type", required_argument, 0,
't'},
76 c = getopt_long (argc, argv,
"bft:",
77 long_options, &option_index);
86 if (long_options[option_index].flag != 0)
88 printf (
"option %s", long_options[option_index].name);
91 printf (
" with arg %s", optarg);
104 if(!strcmp(optarg,
"none")) {
106 }
else if(!strcmp(optarg,
"eth")) {
108 }
else if (!strcmp(optarg,
"net")) {
110 }
else if (!strcmp(optarg,
"tcp")) {
112 }
else if (!strcmp(optarg,
"udp")) {
115 fprintf(stderr,
"%s: Supported Types: "
116 "none, eth, net, tcp, udp\n", argv[0]);
135 puts (
"verbose flag is set\n");
141 while (optind < argc) {
144 if(!strcmp(argv[optind],
"add") &&
145 !strcmp(argv[optind+1],
"route") && optind+4 <= argc) {
147 err =
ce_gw_add(argv[optind+3], argv[optind+2],
150 fprintf(stderr,
"%s: Error during add: %d",
156 err =
ce_gw_add(argv[optind+2], argv[optind+3],
159 fprintf(stderr,
"%s: Error during "
160 "add: %d", argv[0], err);
168 }
else if (!strcmp(argv[optind],
"add") &&
169 !strcmp(argv[optind+1],
"dev") && optind+2 <= argc) {
171 if (optind+3 <= argc) {
175 fprintf(stderr,
"%s: Error during "
176 "add: %d", argv[0], err);
185 fprintf(stderr,
"%s: Error during "
186 "add: %d", argv[0], err);
194 }
else if(!strcmp(argv[optind],
"del") &&
195 !strcmp(argv[optind+1],
"route") && optind+3 <= argc ) {
197 uintmax_t num = strtoumax(argv[optind+2], NULL, 0);
198 if (num == UINTMAX_MAX && errno == ERANGE) {
199 fprintf(stderr,
"%s: Error: Parameter "
200 "ID is not a number %d\n",
206 fprintf(stderr,
"%s: Error during del: %d\n",
214 }
else if(!strcmp(argv[optind],
"del") &&
215 !strcmp(argv[optind+1],
"dev") && optind+3 <= argc ) {
219 fprintf(stderr,
"%s: Error during del: %d\n",
227 }
else if(!strcmp(argv[optind],
"echo") && optind+2 <= argc) {
231 fprintf(stderr,
"%s: Error during echo: %d",
239 }
else if(!strcmp(argv[optind],
"route") && optind+1 <= argc) {
241 if (optind+2 <= argc) {
242 uintmax_t num = strtoumax(argv[optind+1],
244 if (num == UINTMAX_MAX && errno == ERANGE) {
245 fprintf(stderr,
"%s: Error: Parameter "
246 "ID is not a number %d\n",
259 fprintf(stderr,
"%s: Error during list: %d",
269 while(optind < argc) {
270 printf(
" %s", argv[optind]);
int nl_cb_echo_answer |
( |
struct nl_msg * |
msg, |
|
|
void * |
arg |
|
) |
| |
Callback witch receive the message sen bach by kernel.
- Parameters
-
msg | Netlink Message arg a file |
- Return values
-
- See Also
- defined as callback in ce_gw_echo()
Definition at line 448 of file netlink.c.
Referenced by ce_gw_echo().
450 struct nlmsghdr *msghdr = nlmsg_hdr(msg);
451 struct genlmsghdr *gemsghdr = nlmsg_data(msghdr);
453 struct nlattr *a_msg = genlmsg_attrdata(gemsghdr, 0);
454 char * a_msg_data = (
char *) nla_data(a_msg);
455 printf(
"kernel says: %s\n", a_msg_data);
int nl_cb_general_errno |
( |
struct sockaddr_nl * |
nla, |
|
|
struct nlmsgerr * |
nlerr, |
|
|
void * |
arg |
|
) |
| |
A callback wich prints the errno to stderr.
- Parameters
-
nla | Socket address informations |
nlerr | error Message arg a file |
A callback wich prints the errno to stderr. In nl_sk_fam_init() it is delcared as standart error callback.
- Return values
-
Definition at line 203 of file netlink.c.
Referenced by ce_gw_list(), and nl_sk_fam_init().
206 int err = nlerr->error;
207 fprintf(stderr,
"NETLINK returned Error: %s\n", strerror(err));
int nl_cb_list_entry |
( |
struct nl_msg * |
msg, |
|
|
void * |
arg |
|
) |
| |
will be called for every multipart message and prints informations to stdout.
- Parameters
-
msg | Netlink Message arg a file |
- Return values
-
- See Also
- defined as callback in ce_gw_list()
Definition at line 335 of file netlink.c.
References CE_GW_A_DROP, CE_GW_A_DST, CE_GW_A_FLAGS, CE_GW_A_HNDL, CE_GW_A_ID, CE_GW_A_MAX, CE_GW_A_SRC, CE_GW_A_TYPE, ce_gw_genl_policy, enum2str(), flags2str(), flags_array, type_array, TYPE_MAX, and USER_HDR_SIZE.
Referenced by ce_gw_list().
339 struct nlmsghdr *msghdr = nlmsg_hdr(msg);
345 fprintf(stderr,
"ERROR Kernel Message Parsing Failed\n");
347 char *a_msg_src_data = (
char *)nla_data(attrs[
CE_GW_A_SRC]);
348 char *a_msg_dst_data = (
char *)nla_data(attrs[
CE_GW_A_DST]);
349 uint32_t *a_msg_id_data = (uint32_t *)nla_data(attrs[
CE_GW_A_ID]);
350 uint32_t *a_msg_flags_data = (uint32_t *)nla_data(attrs[
CE_GW_A_FLAGS]);
351 uint8_t *a_msg_type_data = (uint8_t *)nla_data(attrs[
CE_GW_A_TYPE]);
352 uint32_t *a_msg_hndl_data = (uint32_t *)nla_data(attrs[
CE_GW_A_HNDL]);
353 uint32_t *a_msg_drop_data = (uint32_t *)nla_data(attrs[
CE_GW_A_DROP]);
361 printf(
" %-8d %-6s %-6s %-6s %-8d %-8d %s\n", *a_msg_id_data,
362 a_msg_src_data, a_msg_dst_data, type_str, *a_msg_hndl_data,
363 *a_msg_drop_data, flags_str);
int nl_cb_list_finish |
( |
struct nl_msg * |
msg, |
|
|
void * |
arg |
|
) |
| |
will be called at the end of a multipart message.
- Parameters
-
msg | Netlink Message arg a file |
- Return values
-
- See Also
- defined as callback in ce_gw_list()
Definition at line 379 of file netlink.c.
Referenced by ce_gw_list().
int bidirectional_flag = 0 |