Browse code

Lets try this TCPAddr option parsing in clamdscan one more time

Shawn Webb authored on 2014/05/14 00:10:18
Showing 2 changed files
... ...
@@ -100,13 +100,9 @@ static int isremote(const struct optstruct *opts) {
100 100
 
101 101
     opt = optget(clamdopts, "TCPAddr");
102 102
     while (opt) {
103
-        if (strcmp(opt->name, "TCPAddr"))
104
-            break;
105
-
106
-        if (opt->enabled)
103
+        ipaddr = NULL;
104
+        if (opt->strarg)
107 105
             ipaddr = (!strcmp(opt->strarg, "any") ? NULL : opt->strarg);
108
-        else
109
-            ipaddr = NULL;
110 106
 
111 107
         memset(&hints, 0x00, sizeof(struct addrinfo));
112 108
         hints.ai_family = AF_UNSPEC;
... ...
@@ -115,7 +111,7 @@ static int isremote(const struct optstruct *opts) {
115 115
 
116 116
         if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
117 117
             logg("!Can't lookup clamd hostname: %s\n", gai_strerror(res));
118
-            opt = opt->next;
118
+            opt = opt->nextarg;
119 119
             continue;
120 120
         }
121 121
 
... ...
@@ -158,7 +154,7 @@ static int isremote(const struct optstruct *opts) {
158 158
 
159 159
         freeaddrinfo(info);
160 160
 
161
-        opt = opt->next;
161
+        opt = opt->nextarg;
162 162
     }
163 163
 
164 164
     return 0;
... ...
@@ -77,6 +77,7 @@ int dconnect() {
77 77
     const struct optstruct *opt;
78 78
     struct addrinfo hints, *info, *p;
79 79
     char port[10];
80
+    char *ipaddr;
80 81
 
81 82
 #ifndef _WIN32
82 83
     opt = optget(clamdopts, "LocalSocket");
... ...
@@ -94,16 +95,17 @@ int dconnect() {
94 94
 
95 95
     opt = optget(clamdopts, "TCPAddr");
96 96
     while (opt) {
97
-        if (strcmp(opt->name, "TCPAddr"))
98
-            break;
97
+        ipaddr = NULL;
98
+        if (opt->strarg)
99
+            ipaddr = (!strcmp(opt->strarg, "any") ? NULL : opt->strarg);
99 100
 
100 101
         memset(&hints, 0x00, sizeof(struct addrinfo));
101 102
         hints.ai_family = AF_UNSPEC;
102 103
         hints.ai_socktype = SOCK_STREAM;
103 104
         hints.ai_flags = AI_PASSIVE;
104 105
 
105
-        if ((res = getaddrinfo(opt->strarg, port, &hints, &info))) {
106
-            opt = opt->next;
106
+        if ((res = getaddrinfo(ipaddr, port, &hints, &info))) {
107
+            opt = opt->nextarg;
107 108
             continue;
108 109
         }
109 110
 
... ...
@@ -124,7 +126,7 @@ int dconnect() {
124 124
 
125 125
         freeaddrinfo(info);
126 126
 
127
-        opt = opt->next;
127
+        opt = opt->nextarg;
128 128
     }
129 129
 
130 130
     return -1;