mirror of
https://github.com/kiwix/kiwix-tools.git
synced 2025-09-23 03:52:35 -04:00
Add a few comments
This commit is contained in:
parent
912fb35fae
commit
b7f6ddd3f5
@ -1,5 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright 2009-2014 Emmanuel Engelhart <kelson@kiwix.org>
|
* Copyright 2009-2016 Emmanuel Engelhart <kelson@kiwix.org>
|
||||||
*
|
*
|
||||||
* This program is free software; you can redistribute it and/or modify
|
* This program is free software; you can redistribute it and/or modify
|
||||||
* it under the terms of the GNU General Public License as published by
|
* it under the terms of the GNU General Public License as published by
|
||||||
@ -693,38 +693,49 @@ int main(int argc, char **argv) {
|
|||||||
/* Start the HTTP daemon */
|
/* Start the HTTP daemon */
|
||||||
void *page = NULL;
|
void *page = NULL;
|
||||||
if (interface.length() > 0) {
|
if (interface.length() > 0) {
|
||||||
#ifndef _WIN32
|
|
||||||
|
#ifndef _WIN32
|
||||||
|
|
||||||
/* TBD IPv6 support */
|
/* TBD IPv6 support */
|
||||||
struct sockaddr_in sockAddr;
|
struct sockaddr_in sockAddr;
|
||||||
|
|
||||||
struct ifaddrs *ifaddr, *ifa;
|
struct ifaddrs *ifaddr, *ifa;
|
||||||
int family, n;
|
int family, n;
|
||||||
char host[NI_MAXHOST];
|
char host[NI_MAXHOST];
|
||||||
|
|
||||||
memset(&sockAddr,0, sizeof(sockAddr));
|
/* Search all available interfaces */
|
||||||
|
|
||||||
if (getifaddrs(&ifaddr) == -1) {
|
if (getifaddrs(&ifaddr) == -1) {
|
||||||
cerr << "Getifaddrs() failed while searching for '" << interface << "'" << endl;
|
cerr << "Getifaddrs() failed while searching for '" << interface << "'" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Init 'sockAddr' with zeros */
|
||||||
|
memset(&sockAddr,0, sizeof(sockAddr));
|
||||||
|
|
||||||
|
/* Try to find interfaces in the list of available interfaces */
|
||||||
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
|
for (ifa = ifaddr, n = 0; ifa != NULL; ifa = ifa->ifa_next, n++) {
|
||||||
if (ifa->ifa_addr == NULL)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
family = ifa->ifa_addr->sa_family;
|
/* Ignore if no IP attributed to the interface */
|
||||||
|
if (ifa->ifa_addr == NULL)
|
||||||
|
continue;
|
||||||
|
|
||||||
if (family == AF_INET) {
|
/* Check if the interface is the right one */
|
||||||
if (strcasecmp(ifa->ifa_name, interface.c_str()) == 0) {
|
family = ifa->ifa_addr->sa_family;
|
||||||
sockAddr.sin_family = family;
|
if (family == AF_INET) {
|
||||||
sockAddr.sin_port = htons(serverPort);
|
if (strcasecmp(ifa->ifa_name, interface.c_str()) == 0) {
|
||||||
sockAddr.sin_addr.s_addr = ((struct sockaddr_in*) ifa->ifa_addr)->sin_addr.s_addr;
|
sockAddr.sin_family = family;
|
||||||
break;
|
sockAddr.sin_port = htons(serverPort);
|
||||||
}
|
sockAddr.sin_addr.s_addr = ((struct sockaddr_in*) ifa->ifa_addr)->sin_addr.s_addr;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Free 'ifaddr' */
|
||||||
freeifaddrs(ifaddr);
|
freeifaddrs(ifaddr);
|
||||||
|
|
||||||
|
/* Dies if interface was not found in the list */
|
||||||
if (sockAddr.sin_family == 0) {
|
if (sockAddr.sin_family == 0) {
|
||||||
cerr << "I couldn't find interface '" << interface << "'" << endl;
|
cerr << "Unable to find interface '" << interface << "'" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -737,10 +748,11 @@ int main(int argc, char **argv) {
|
|||||||
MHD_OPTION_SOCK_ADDR,
|
MHD_OPTION_SOCK_ADDR,
|
||||||
&sockAddr,
|
&sockAddr,
|
||||||
MHD_OPTION_END);
|
MHD_OPTION_END);
|
||||||
#else
|
#else
|
||||||
cerr << "Setting interface - not yet implemented in Windows" << endl;
|
cerr << "Setting 'interface' not yet implemented for Windows" << endl;
|
||||||
exit(1);
|
exit(1);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY,
|
daemon = MHD_start_daemon(MHD_USE_SELECT_INTERNALLY,
|
||||||
serverPort,
|
serverPort,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user