IEEE 802.15.4 subsystem
Sign in or create your account | Project List | Help
IEEE 802.15.4 subsystem Commit Details
Date: | 2011-05-11 21:46:29 (12 years 10 months ago) |
---|---|
Author: | Werner Almesberger |
Commit: | de72af351f661b538add81cbc9965278a2f8c40c |
Message: | tools/dirtpan/: if given an interface conf command, run it with tunX
in $ITF - dirtpan.c (open_tun): if a command is given, set the environment variable ITF to the interface name and system(3) the command - dirtpan.c (usage, main): accept an interface configuration command as the 4th command-line argument |
Files: |
tools/dirtpan/dirtpan.c (7 diffs) |
Change Details
tools/dirtpan/dirtpan.c | ||
---|---|---|
17 | 17 | #include <unistd.h> |
18 | 18 | #include <string.h> |
19 | 19 | #include <fcntl.h> |
20 | #include <signal.h> | |
20 | 21 | #include <assert.h> |
21 | 22 | #include <sys/types.h> |
22 | 23 | #include <sys/time.h> |
24 | #include <sys/wait.h> | |
23 | 25 | #include <sys/select.h> |
24 | 26 | #include <sys/ioctl.h> |
25 | 27 | #include <sys/socket.h> |
... | ... | |
474 | 476 | } |
475 | 477 | |
476 | 478 | |
477 | static int open_tun(void) | |
479 | static int open_tun(const char *cmd) | |
478 | 480 | { |
479 | 481 | struct ifreq ifr; |
480 | int fd; | |
482 | int fd, res; | |
481 | 483 | |
482 | 484 | fd = open(TUN_DEV, O_RDWR); |
483 | 485 | if (fd < 0) { |
... | ... | |
493 | 495 | exit(1); |
494 | 496 | } |
495 | 497 | |
496 | fprintf(stderr, "%s\n", ifr.ifr_name); | |
498 | if (!cmd) { | |
499 | fprintf(stderr, "%s\n", ifr.ifr_name); | |
500 | return fd; | |
501 | } | |
502 | ||
503 | if (setenv("ITF", ifr.ifr_name, 1) < 0) { | |
504 | perror("setenv"); | |
505 | exit(1); | |
506 | } | |
507 | ||
508 | res = system(cmd); | |
509 | if (res < 0) { | |
510 | perror("system"); | |
511 | exit(1); | |
512 | } | |
513 | if (WIFEXITED(res)) { | |
514 | if (!WEXITSTATUS(res)) | |
515 | return fd; | |
516 | exit(WEXITSTATUS(res)); | |
517 | } | |
518 | if (WIFSIGNALED(res)) { | |
519 | raise(WTERMSIG(res)); | |
520 | exit(1); | |
521 | } | |
497 | 522 | |
498 | return fd; | |
523 | fprintf(stderr, "cryptic exit status %d\n", res); | |
524 | exit(1); | |
499 | 525 | } |
500 | 526 | |
501 | 527 | |
... | ... | |
504 | 530 | |
505 | 531 | static void usage(const char *name) |
506 | 532 | { |
507 | fprintf(stderr, "usage: %s [-d [-d]] pan_id src_addr dst_addr\n", | |
508 | name); | |
533 | fprintf(stderr, | |
534 | "usage: %s [-d [-d]] pan_id src_addr dst_addr [command]\n" | |
535 | , name); | |
509 | 536 | exit(1); |
510 | 537 | } |
511 | 538 | |
... | ... | |
526 | 553 | |
527 | 554 | int main(int argc, char **argv) |
528 | 555 | { |
556 | const char *cmd = NULL; | |
529 | 557 | uint16_t pan, src, dst; |
530 | 558 | int c; |
531 | 559 | |
... | ... | |
539 | 567 | } |
540 | 568 | |
541 | 569 | switch (argc-optind) { |
570 | case 4: | |
571 | cmd = argv[optind+3]; | |
572 | /* fall through */ | |
542 | 573 | case 3: |
543 | 574 | pan = addr(*argv, argv[optind]); |
544 | 575 | src = addr(*argv, argv[optind+1]); |
... | ... | |
549 | 580 | } |
550 | 581 | |
551 | 582 | net = open_net(pan, src, dst); |
552 | tun = open_tun(); | |
583 | tun = open_tun(cmd); | |
553 | 584 | while (1) |
554 | 585 | event(); |
555 | 586 |