Browse Source

gluon-radv-filterd: Seperate macros for printf() and scanf()

Jan-Philipp Litza 7 years ago
parent
commit
5fce0b5932

+ 3 - 3
package/gluon-radv-filterd/src/gluon-radv-filterd.c

@@ -348,7 +348,7 @@ static void update_tqs() {
 		while (fgetc(f) != '\n') {}
 		while (fgetc(f) != '\n') {}
 		while (fgetc(f) != '\n') {}
 		while (fgetc(f) != '\n') {}
 		while (fscanf(f, " %*[*+] " F_MAC "%*[0-9 -] (%*3u) via " F_MAC " %*[^]]]\n",
 		while (fscanf(f, " %*[*+] " F_MAC "%*[0-9 -] (%*3u) via " F_MAC " %*[^]]]\n",
-				F_MAC_VAR(&mac_a), F_MAC_VAR(&mac_b)) == 12) {
+				F_MAC_VAR_REF(mac_a), F_MAC_VAR_REF(mac_b)) == 12) {
 
 
 			foreach(router, G.routers) {
 			foreach(router, G.routers) {
 				if (!memcmp(router->src, mac_a, sizeof(macaddr_t))) {
 				if (!memcmp(router->src, mac_a, sizeof(macaddr_t))) {
@@ -373,7 +373,7 @@ static void update_tqs() {
 	while (fgetc(f) != '\n');
 	while (fgetc(f) != '\n');
 	while (fgetc(f) != '\n');
 	while (fgetc(f) != '\n');
 	while (fscanf(f, F_MAC " %*fs (%hhu) %*[^\n]\n",
 	while (fscanf(f, F_MAC " %*fs (%hhu) %*[^\n]\n",
-			F_MAC_VAR(&mac_a), &tq) == 7) {
+			F_MAC_VAR_REF(mac_a), &tq) == 7) {
 
 
 		foreach(router, G.routers) {
 		foreach(router, G.routers) {
 			if (!memcmp(router->originator, mac_a, sizeof(macaddr_t))) {
 			if (!memcmp(router->originator, mac_a, sizeof(macaddr_t))) {
@@ -403,7 +403,7 @@ static void update_tqs() {
 		// skip header
 		// skip header
 		while (fgetc(f) != '\n');
 		while (fgetc(f) != '\n');
 		while (fgetc(f) != '\n');
 		while (fgetc(f) != '\n');
-		while (fscanf(f, " * " F_MAC " [%*5s] %*f", F_MAC_VAR(&mac_a)) == 6) {
+		while (fscanf(f, " * " F_MAC " [%*5s] %*f", F_MAC_VAR_REF(mac_a)) == 6) {
 			foreach(router, G.routers) {
 			foreach(router, G.routers) {
 				if (!memcmp(router->src, mac_a, sizeof(macaddr_t))) {
 				if (!memcmp(router->src, mac_a, sizeof(macaddr_t))) {
 					DEBUG_MSG("Found router " F_MAC " in transtable_local, assigning TQ %d", F_MAC_VAR(router->src), LOCAL_TQ);
 					DEBUG_MSG("Found router " F_MAC " in transtable_local, assigning TQ %d", F_MAC_VAR(router->src), LOCAL_TQ);

+ 2 - 1
package/gluon-radv-filterd/src/mac.h

@@ -4,6 +4,7 @@
 #define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
 #define F_MAC "%02hhx:%02hhx:%02hhx:%02hhx:%02hhx:%02hhx"
 #define F_MAC_LEN 17
 #define F_MAC_LEN 17
 #define F_MAC_IGN "%*2x:%*2x:%*2x:%*2x:%*2x:%*2x"
 #define F_MAC_IGN "%*2x:%*2x:%*2x:%*2x:%*2x:%*2x"
-#define F_MAC_VAR(var) var[0], var[1], var[2], var[3], var[4], var[5]
+#define F_MAC_VAR(var) (var)[0], (var)[1], (var)[2], (var)[3], (var)[4], (var)[5]
+#define F_MAC_VAR_REF(var) &(var)[0], &(var)[1], &(var)[2], &(var)[3], &(var)[4], &(var)[5]
 
 
 typedef uint8_t macaddr_t[ETH_ALEN];
 typedef uint8_t macaddr_t[ETH_ALEN];

+ 1 - 1
package/gluon-radv-filterd/src/respondd.c

@@ -18,7 +18,7 @@ static struct json_object * get_radv_filter() {
 		return NULL;
 		return NULL;
 
 
 	while (getline(&line, &len, f) > 0) {
 	while (getline(&line, &len, f) > 0) {
-		if (sscanf(line, "-s " F_MAC " -j ACCEPT\n", F_MAC_VAR(&mac)) == ETH_ALEN)
+		if (sscanf(line, "-s " F_MAC " -j ACCEPT\n", F_MAC_VAR_REF(mac)) == ETH_ALEN)
 			break;
 			break;
 	}
 	}
 	free(line);
 	free(line);