diff options
Diffstat (limited to 'src/daemon/daemon.c')
-rw-r--r-- | src/daemon/daemon.c | 43 |
1 files changed, 42 insertions, 1 deletions
diff --git a/src/daemon/daemon.c b/src/daemon/daemon.c index 93017ae3..e971c9b2 100644 --- a/src/daemon/daemon.c +++ b/src/daemon/daemon.c | |||
@@ -172,10 +172,12 @@ MHD_handle_connection (void *data) | |||
172 | static int | 172 | static int |
173 | MHD_accept_connection (struct MHD_Daemon *daemon) | 173 | MHD_accept_connection (struct MHD_Daemon *daemon) |
174 | { | 174 | { |
175 | struct MHD_Connection *pos; | ||
175 | struct MHD_Connection *connection; | 176 | struct MHD_Connection *connection; |
176 | struct sockaddr_in6 addr6; | 177 | struct sockaddr_in6 addr6; |
177 | struct sockaddr *addr = (struct sockaddr *) &addr6; | 178 | struct sockaddr *addr = (struct sockaddr *) &addr6; |
178 | socklen_t addrlen; | 179 | socklen_t addrlen; |
180 | unsigned int have; | ||
179 | int s; | 181 | int s; |
180 | #if OSX | 182 | #if OSX |
181 | static int on = 1; | 183 | static int on = 1; |
@@ -202,7 +204,42 @@ MHD_accept_connection (struct MHD_Daemon *daemon) | |||
202 | #if DEBUG_CONNECT | 204 | #if DEBUG_CONNECT |
203 | MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); | 205 | MHD_DLOG (daemon, "Accepted connection on socket %d\n", s); |
204 | #endif | 206 | #endif |
205 | if (daemon->max_connections == 0) | 207 | have = 0; |
208 | if ( (daemon->per_ip_connection_limit != 0) && | ||
209 | (daemon->max_connections > 0) ) | ||
210 | { | ||
211 | pos = daemon->connections; | ||
212 | while (pos != NULL) | ||
213 | { | ||
214 | if ( (pos->addr != NULL) && | ||
215 | (pos->addr_len == addrlen) ) | ||
216 | { | ||
217 | if (addrlen == sizeof(struct sockaddr_in)) | ||
218 | { | ||
219 | const struct sockaddr_in * a1 = (const struct sockaddr_in *) &addr; | ||
220 | const struct sockaddr_in * a2 = (const struct sockaddr_in *) pos->addr; | ||
221 | if (0 == memcmp(&a1->sin_addr, | ||
222 | &a2->sin_addr, | ||
223 | sizeof(struct in_addr))) | ||
224 | have++; | ||
225 | } | ||
226 | if (addrlen == sizeof(struct sockaddr_in6)) | ||
227 | { | ||
228 | const struct sockaddr_in6 * a1 = (const struct sockaddr_in6 *) &addr; | ||
229 | const struct sockaddr_in6 * a2 = (const struct sockaddr_in6 *) pos->addr; | ||
230 | if (0 == memcmp(&a1->sin6_addr, | ||
231 | &a2->sin6_addr, | ||
232 | sizeof(struct in6_addr))) | ||
233 | have++; | ||
234 | } | ||
235 | } | ||
236 | pos = pos->next; | ||
237 | } | ||
238 | } | ||
239 | |||
240 | if ( (daemon->max_connections == 0) || | ||
241 | ( (daemon->per_ip_connection_limit != 0) && | ||
242 | (daemon->per_ip_connection_limit <= have) ) ) | ||
206 | { | 243 | { |
207 | /* above connection limit - reject */ | 244 | /* above connection limit - reject */ |
208 | #if HAVE_MESSAGES | 245 | #if HAVE_MESSAGES |
@@ -631,6 +668,10 @@ MHD_start_daemon (unsigned int options, | |||
631 | va_arg (ap, MHD_RequestCompletedCallback); | 668 | va_arg (ap, MHD_RequestCompletedCallback); |
632 | retVal->notify_completed_cls = va_arg (ap, void *); | 669 | retVal->notify_completed_cls = va_arg (ap, void *); |
633 | break; | 670 | break; |
671 | case MHD_OPTION_PER_IP_CONNECTION_LIMIT: | ||
672 | retVal->per_ip_connection_limit | ||
673 | = va_arg (ap, unsigned int); | ||
674 | break; | ||
634 | default: | 675 | default: |
635 | #if HAVE_MESSAGES | 676 | #if HAVE_MESSAGES |
636 | fprintf (stderr, | 677 | fprintf (stderr, |