Browse Source

dns_server: fix bind device issue

Nick Peng 2 năm trước cách đây
mục cha
commit
e416a15684
1 tập tin đã thay đổi với 5 bổ sung1 xóa
  1. 5 1
      src/dns_server.c

+ 5 - 1
src/dns_server.c

@@ -5349,6 +5349,10 @@ static int _dns_create_socket(const char *host_ip, int type)
 
 	safe_strncpy(host_ip_device, host_ip, sizeof(host_ip_device));
 	ifname = strstr(host_ip_device, "@");
+	if (ifname) {
+		*(char *)ifname = '\0';
+		ifname++;
+	}
 
 	if (parse_ip(host_ip_device, ip, &port) == 0) {
 		host = ip;
@@ -5388,7 +5392,7 @@ static int _dns_create_socket(const char *host_ip, int type)
 	if (ifname != NULL) {
 		struct ifreq ifr;
 		memset(&ifr, 0, sizeof(struct ifreq));
-		safe_strncpy(ifr.ifr_name, ifname + 1, sizeof(ifr.ifr_name));
+		safe_strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
 		ioctl(fd, SIOCGIFINDEX, &ifr);
 		if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(struct ifreq)) < 0) {
 			tlog(TLOG_ERROR, "bind socket to device %s faild, %s\n", ifr.ifr_name, strerror(errno));