Skip to content
Snippets Groups Projects
Commit a4d22b52 authored by Sven Robertz's avatar Sven Robertz
Browse files

parameters for eth if name and dest MAC addr for thr examples

parent 35f90c3d
No related branches found
No related tags found
No related merge requests found
...@@ -24,8 +24,20 @@ int main(int argc, char *argv[]) { ...@@ -24,8 +24,20 @@ int main(int argc, char *argv[]) {
unsigned short freq = 1000; /* milliseconds */ unsigned short freq = 1000; /* milliseconds */
unsigned char data[200]; unsigned char data[200];
char *filename = argv[1]; char *ifname = argv[1];
if (-1 == thr_init("eth2")) 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."); printf("Throttle Init failure.");
} }
......
...@@ -10,13 +10,26 @@ int main(int argc, char *argv[]) { ...@@ -10,13 +10,26 @@ int main(int argc, char *argv[]) {
struct thr_chn_t *p_thr_chn = NULL; struct thr_chn_t *p_thr_chn = NULL;
struct labcomm_encoder *encoder; struct labcomm_encoder *encoder;
int i, j; 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 char chn_id = 0x01;
unsigned short frag_size = 60; unsigned short frag_size = 60;
unsigned short freq = 1000; /* milliseconds */ unsigned short freq = 1000; /* milliseconds */
char *filename = argv[1]; char *ifname = argv[1];
if (-1 == thr_init("eth0")) 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."); printf("Throttle Init failure.");
} }
......
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
liblabcomm.a : labcomm.o labcomm_fd_reader_writer.o CC = gcc
ar -r liblabcomm.a labcomm.o labcomm_fd_reader_writer.o 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 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 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: clean:
rm *.o rm *.o
......
#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
#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
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment