Browse Source

Const correctness.

Guus Sliepen 6 years ago
parent
commit
061c3fcaf9

+ 1 - 3
src/bsd/device.c

@@ -55,7 +55,7 @@ typedef enum device_type {
 int device_fd = -1;
 char *device = NULL;
 char *iface = NULL;
-static char *device_info = NULL;
+static const char *device_info = "OS X utun device";
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
 #if defined(ENABLE_TUNEMU)
@@ -117,8 +117,6 @@ static bool setup_utun(void) {
 		iface = xstrdup(name);
 	}
 
-	device_info = "OS X utun device";
-
 	logger(LOG_INFO, "%s is a %s", device, device_info);
 
 	return true;

+ 1 - 3
src/cygwin/device.c

@@ -37,7 +37,7 @@ int device_fd = -1;
 static HANDLE device_handle = INVALID_HANDLE_VALUE;
 char *device = NULL;
 char *iface = NULL;
-static char *device_info = NULL;
+static const char *device_info = "Windows tap device";
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
@@ -221,8 +221,6 @@ static bool setup_device(void) {
 		return false;
 	}
 
-	device_info = "Windows tap device";
-
 	logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
 
 	return true;

+ 4 - 3
src/dummy_device.c

@@ -22,15 +22,16 @@
 #include "device.h"
 #include "logger.h"
 #include "net.h"
+#include "xalloc.h"
 
-static char *device_info = "dummy device";
+static const char *device_info = "dummy device";
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
 
 static bool setup_device(void) {
-	device = "dummy";
-	iface = "dummy";
+	device = xstrdup("dummy");
+	iface = xstrdup("dummy");
 	logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
 	return true;
 }

+ 1 - 1
src/linux/device.c

@@ -47,7 +47,7 @@ char *device = NULL;
 char *iface = NULL;
 static char *type = NULL;
 static char ifrname[IFNAMSIZ];
-static char *device_info;
+static const char *device_info;
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;

+ 1 - 3
src/mingw/device.c

@@ -37,7 +37,7 @@ int device_fd = -1;
 static HANDLE device_handle = INVALID_HANDLE_VALUE;
 char *device = NULL;
 char *iface = NULL;
-static char *device_info = NULL;
+static const char *device_info = "Windows tap device";
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
@@ -236,8 +236,6 @@ static bool setup_device(void) {
 	status = true;
 	DeviceIoControl(device_handle, TAP_IOCTL_SET_MEDIA_STATUS, &status, sizeof(status), &status, sizeof(status), &len, NULL);
 
-	device_info = "Windows tap device";
-
 	logger(LOG_INFO, "%s (%s) is a %s", device, iface, device_info);
 
 	return true;

+ 1 - 3
src/multicast_device.c

@@ -29,7 +29,7 @@
 #include "route.h"
 #include "xalloc.h"
 
-static char *device_info;
+static const char *device_info = "multicast socket";
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
@@ -43,8 +43,6 @@ static bool setup_device(void) {
 	char *space;
 	int ttl = 1;
 
-	device_info = "multicast socket";
-
 	get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
 	if(!get_config_string(lookup_config(config_tree, "Device"), &device)) {

+ 1 - 3
src/raw_socket_device.c

@@ -33,7 +33,7 @@
 #include "xalloc.h"
 
 #if defined(PF_PACKET) && defined(ETH_P_ALL) && defined(AF_PACKET) && defined(SIOCGIFINDEX)
-static char *device_info;
+static const char *device_info = "raw_socket";
 
 static uint64_t device_total_in = 0;
 static uint64_t device_total_out = 0;
@@ -50,8 +50,6 @@ static bool setup_device(void) {
 		device = xstrdup(iface);
 	}
 
-	device_info = "raw socket";
-
 	if((device_fd = socket(PF_PACKET, SOCK_RAW, htons(ETH_P_ALL))) < 0) {
 		logger(LOG_ERR, "Could not open %s: %s", device_info,
 		       strerror(errno));

+ 1 - 1
src/solaris/device.c

@@ -53,7 +53,7 @@ static int if_fd = -1;
 static int ip_fd = -1;
 char *device = NULL;
 char *iface = NULL;
-static char *device_info = NULL;
+static const char *device_info = NULL;
 
 uint64_t device_total_in = 0;
 uint64_t device_total_out = 0;

+ 1 - 3
src/uml_device.c

@@ -35,7 +35,7 @@ static int request_fd = -1;
 static int data_fd = -1;
 static int write_fd = -1;
 static int state = 0;
-static char *device_info;
+static const char *device_info = "UML network socket";
 
 extern char *identname;
 extern volatile bool running;
@@ -70,8 +70,6 @@ static bool setup_device(void) {
 
 	get_config_string(lookup_config(config_tree, "Interface"), &iface);
 
-	device_info = "UML network socket";
-
 	if((write_fd = socket(PF_UNIX, SOCK_DGRAM, 0)) < 0) {
 		logger(LOG_ERR, "Could not open write %s: %s", device_info, strerror(errno));
 		running = false;

+ 1 - 3
src/vde_device.c

@@ -33,7 +33,7 @@ static struct vdepluglib plug;
 static struct vdeconn *conn = NULL;
 static int port = 0;
 static char *group = NULL;
-static char *device_info;
+static const char *device_info = "VDE socket";
 
 extern char *identname;
 extern volatile bool running;
@@ -59,8 +59,6 @@ static bool setup_device(void) {
 
 	get_config_string(lookup_config(config_tree, "VDEGroup"), &group);
 
-	device_info = "VDE socket";
-
 	struct vde_open_args args = {
 		.port = port,
 		.group = group,