From a4d22b52ee1a88bad5522c3faae4db63e73c93cc Mon Sep 17 00:00:00 2001 From: Sven Robertz <sven@cs.lth.se> Date: Wed, 14 Dec 2011 11:47:47 +0100 Subject: [PATCH] parameters for eth if name and dest MAC addr for thr examples --- examples/simple_java/thr_decoder.c | 16 +++++++++++++-- examples/simple_java/thr_encoder.c | 19 +++++++++++++++--- examples/simple_java/udp_compile.sh | 4 ++-- lib/c/Makefile | 11 +++++++---- lib/c/ethaddr.c | 30 +++++++++++++++++++++++++++++ lib/c/ethaddr.h | 8 ++++++++ 6 files changed, 77 insertions(+), 11 deletions(-) create mode 100644 lib/c/ethaddr.c create mode 100644 lib/c/ethaddr.h diff --git a/examples/simple_java/thr_decoder.c b/examples/simple_java/thr_decoder.c index de5907c..4014168 100644 --- a/examples/simple_java/thr_decoder.c +++ b/examples/simple_java/thr_decoder.c @@ -24,8 +24,20 @@ int main(int argc, char *argv[]) { unsigned short freq = 1000; /* milliseconds */ unsigned char data[200]; - char *filename = argv[1]; - if (-1 == thr_init("eth2")) + char *ifname = argv[1]; + char *dest_mac_str = argv[2]; + + if(argc != 3) { + printf("usage: thr_encoder ethN xx:xx:xx:xx:xx:xx\n"); + return 1; + } + + if(parse_MAC_address(dest_mac_str, dest_mac)) { + printf("failed to parse dest MAC address\n"); + return 1; + } + + if (-1 == thr_init(ifname)) { printf("Throttle Init failure."); } diff --git a/examples/simple_java/thr_encoder.c b/examples/simple_java/thr_encoder.c index 6466175..492c8c2 100644 --- a/examples/simple_java/thr_encoder.c +++ b/examples/simple_java/thr_encoder.c @@ -10,13 +10,26 @@ int main(int argc, char *argv[]) { struct thr_chn_t *p_thr_chn = NULL; struct labcomm_encoder *encoder; int i, j; - unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0x10, 0xf3, 0x80}; /* other host MAC address, hardcoded...... :-( */ +// unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0x10, 0xf3, 0x80}; /* other host MAC address, hardcoded...... :-( */ + unsigned char dest_mac[ETH_ADR_SIZE] = {0x00, 0x09, 0x6b, 0xe3, 0x81, 0xbf}; /* other host MAC address, hardcoded...... :-( */ unsigned char chn_id = 0x01; unsigned short frag_size = 60; unsigned short freq = 1000; /* milliseconds */ - char *filename = argv[1]; - if (-1 == thr_init("eth0")) + char *ifname = argv[1]; + char *dest_mac_str = argv[2]; + + if(argc != 3) { + printf("usage: thr_encoder ethN xx:xx:xx:xx:xx:xx\n"); + return 1; + } + + if(parse_MAC_address(dest_mac_str, dest_mac)) { + printf("failed to parse dest MAC address\n"); + return 1; + } + + if (-1 == thr_init(ifname)) { printf("Throttle Init failure."); } diff --git a/examples/simple_java/udp_compile.sh b/examples/simple_java/udp_compile.sh index 6d3c565..9f34795 100644 --- a/examples/simple_java/udp_compile.sh +++ b/examples/simple_java/udp_compile.sh @@ -1,3 +1,3 @@ -gcc -o udp_encoder -L ../../lib/c -I . -I ../../lib/c udp_encoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm +gcc -g -o udp_encoder -L ../../lib/c -I . -I ../../lib/c udp_encoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm -gcc -o udp_decoder -L ../../lib/c -I . -I ../../lib/c udp_decoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm +gcc -g -o udp_decoder -L ../../lib/c -I . -I ../../lib/c udp_decoder.c gen/simple.c ../../lib/c/labcomm_udp_reader_writer.c ../../lib/c/udp_hack.c -llabcomm diff --git a/lib/c/Makefile b/lib/c/Makefile index 13e4974..7ef5643 100644 --- a/lib/c/Makefile +++ b/lib/c/Makefile @@ -1,11 +1,14 @@ -liblabcomm.a : labcomm.o labcomm_fd_reader_writer.o - ar -r liblabcomm.a labcomm.o labcomm_fd_reader_writer.o +CC = gcc +CFLAGS = -g + +liblabcomm.a : labcomm.o labcomm_fd_reader_writer.o ethaddr.o + ar -r liblabcomm.a labcomm.o labcomm_fd_reader_writer.o ethaddr.o labcomm.o : labcomm.c labcomm.h labcomm_private.h - gcc -c labcomm.c labcomm_fd_reader_writer.o : labcomm_fd_reader_writer.c labcomm_fd_reader_writer.h labcomm.h labcomm_private.h - gcc -c labcomm_fd_reader_writer.c + +ethaddr.o: ethaddr.c clean: rm *.o diff --git a/lib/c/ethaddr.c b/lib/c/ethaddr.c new file mode 100644 index 0000000..29dab1a --- /dev/null +++ b/lib/c/ethaddr.c @@ -0,0 +1,30 @@ +#include <stdio.h> +#include "ethaddr.h" + + +/* parse a string on the format 00:01:02:0d:0e:0f into a char array + * the mac_addr argument must be at least six bytes. + * returns 0 on success, or -1 on error + */ +int parse_MAC_address(const char *str, unsigned char mac_addr[]) +{ + int res = sscanf(str, "%x:%x:%x:%x:%x:%x", &mac_addr[0], &mac_addr[1], + &mac_addr[2], &mac_addr[3], &mac_addr[4], &mac_addr[5]); + return (res == 6? 0 : -1); + +} + +#if 0 +/* test program */ +int main(int argc, char *argv[]) +{ + int i; + unsigned char a[6]; + int res = parse_MAC_address(argv[1], a); + if(res) { + perror("Failed to parse MAC address"); + } + printf("%x.%x.%x.%x.%x.%x\n", a[0], a[1], a[2], a[3], a[4], a[5]); + return 0; +} +#endif diff --git a/lib/c/ethaddr.h b/lib/c/ethaddr.h new file mode 100644 index 0000000..605c86e --- /dev/null +++ b/lib/c/ethaddr.h @@ -0,0 +1,8 @@ +#ifndef ETHADDR_H +#define ETHADDR_H +/* parse a string on the format 00:01:02:0d:0e:0f into a char array + * the mac_addr argument must be at least six bytes. + * returns 0 on success, or -1 on error + */ +int parse_MAC_address(const char *str, unsigned char mac_addr[]); +#endif -- GitLab