#include "config.h"
#endif /* HAVE_CONFIG_H */
-#define USE_TCP_NODELAY
-
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <atalk/util.h>
#include <atalk/errchk.h>
-#include "dsi_private.h"
-
#define min(a,b) ((a) < (b) ? (a) : (b))
#ifndef DSI_TCPMAXPEND
#ifdef TCPWRAP
{
struct request_info req;
- request_init(&req, RQ_DAEMON, dsi->program, RQ_FILE, dsi->socket, NULL);
+ request_init(&req, RQ_DAEMON, "afpd", RQ_FILE, dsi->socket, NULL);
fromhost(&req);
if (!hosts_access(&req)) {
LOG(deny_severity, logtype_dsi, "refused connect from %s", eval_client(&req));
uint8_t block[DSI_BLOCKSIZ];
size_t stored;
- /* Immediateyl mark globally that we're a child now */
- parent_or_child = 1;
-
/* reset signals */
server_reset_signal();
getip_string((struct sockaddr *)&dsi->server), port, ifr.ifr_name);
goto iflist_done;
}
- LOG(log_info, logtype_dsi, "dsi_tcp (Chooser will not select afp/tcp) "
- "Check to make sure %s is in /etc/hosts and the correct domain is in "
- "/etc/resolv.conf: %s", hostname, strerror(errno));
+
+ LOG(log_note, logtype_dsi, "dsi_tcp: couldn't find network interface with IP address to advertice, "
+ "check to make sure \"%s\" is in /etc/hosts or can be resolved with DNS, or "
+ "add a netinterface that is not a loopback or point-2-point type", hostname);
iflist_done:
close(fd);
int dsi_tcp_init(DSI *dsi, const char *hostname, const char *inaddress, const char *inport)
{
EC_INIT;
- int flag;
- char *p, *address = NULL;
+ int flag, err;
+ char *a = NULL, *b;
+ const char *address;
+ const char *port;
struct addrinfo hints, *servinfo, *p;
/* Check whether address is of the from IP:PORT and split */
address = inaddress;
port = inport;
if (address && strchr(address, ':')) {
- EC_NULL_LOG( address = strdup(inaddress) );
- p = strchr(address, ':');
- *p = 0;
- port = p + 1;
+ EC_NULL_LOG( address = a = strdup(address) );
+ b = strchr(a, ':');
+ *b = 0;
+ port = b + 1;
}
/* Prepare hint for getaddrinfo */
EC_FAIL;
}
- /* create a socket */
- if (proxy)
- dsi->serversock = -1;
- else {
- /* loop through all the results and bind to the first we can */
- for (p = servinfo; p != NULL; p = p->ai_next) {
- if ((dsi->serversock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
- LOG(log_info, logtype_dsi, "dsi_tcp_init: socket: %s", strerror(errno));
- continue;
- }
+ /* loop through all the results and bind to the first we can */
+ for (p = servinfo; p != NULL; p = p->ai_next) {
+ if ((dsi->serversock = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
+ LOG(log_info, logtype_dsi, "dsi_tcp_init: socket: %s", strerror(errno));
+ continue;
+ }
- /*
- * Set some socket options:
- * SO_REUSEADDR deals w/ quick close/opens
- * TCP_NODELAY diables Nagle
- */
+ /*
+ * Set some socket options:
+ * SO_REUSEADDR deals w/ quick close/opens
+ * TCP_NODELAY diables Nagle
+ */
#ifdef SO_REUSEADDR
- flag = 1;
- setsockopt(dsi->serversock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
+ flag = 1;
+ setsockopt(dsi->serversock, SOL_SOCKET, SO_REUSEADDR, &flag, sizeof(flag));
#endif
#if defined(FREEBSD) && defined(IPV6_BINDV6ONLY)
- int on = 0;
- setsockopt(dsi->serversock, IPPROTO_IPV6, IPV6_BINDV6ONLY, (char *)&on, sizeof (on));
+ int on = 0;
+ setsockopt(dsi->serversock, IPPROTO_IPV6, IPV6_BINDV6ONLY, (char *)&on, sizeof (on));
#endif
-#ifdef USE_TCP_NODELAY
#ifndef SOL_TCP
#define SOL_TCP IPPROTO_TCP
#endif
- flag = 1;
- setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag));
-#endif /* USE_TCP_NODELAY */
+ flag = 1;
+ setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &flag, sizeof(flag));
- if (bind(dsi->serversock, p->ai_addr, p->ai_addrlen) == -1) {
- close(dsi->serversock);
- LOG(log_info, logtype_dsi, "dsi_tcp_init: bind: %s\n", strerror(errno));
- continue;
- }
-
- if (listen(dsi->serversock, DSI_TCPMAXPEND) < 0) {
- close(dsi->serversock);
- LOG(log_info, logtype_dsi, "dsi_tcp_init: listen: %s\n", strerror(errno));
- continue;
- }
-
- break;
+ if (bind(dsi->serversock, p->ai_addr, p->ai_addrlen) == -1) {
+ close(dsi->serversock);
+ LOG(log_info, logtype_dsi, "dsi_tcp_init: bind: %s\n", strerror(errno));
+ continue;
}
- if (p == NULL) {
- LOG(log_error, logtype_dsi, "dsi_tcp_init: no suitable network config for TCP socket");
- freeaddrinfo(servinfo);
- EC_FAIL;
+ if (listen(dsi->serversock, DSI_TCPMAXPEND) < 0) {
+ close(dsi->serversock);
+ LOG(log_info, logtype_dsi, "dsi_tcp_init: listen: %s\n", strerror(errno));
+ continue;
}
+
+ break;
+ }
- /* Copy struct sockaddr to struct sockaddr_storage */
- memcpy(&dsi->server, p->ai_addr, p->ai_addrlen);
+ if (p == NULL) {
+ LOG(log_error, logtype_dsi, "dsi_tcp_init: no suitable network config for TCP socket");
freeaddrinfo(servinfo);
- } /* if (proxy) */
+ EC_FAIL;
+ }
+
+ /* Copy struct sockaddr to struct sockaddr_storage */
+ memcpy(&dsi->server, p->ai_addr, p->ai_addrlen);
+ freeaddrinfo(servinfo);
/* Point protocol specific functions to tcp versions */
dsi->proto_open = dsi_tcp_open;
hints.ai_family = AF_UNSPEC;
hints.ai_socktype = SOCK_STREAM;
- if ((ret = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) {
- LOG(log_info, logtype_dsi, "dsi_tcp_init: getaddrinfo '%s': %s\n", hostname, gai_strerror(ret));
+ if ((err = getaddrinfo(hostname, port, &hints, &servinfo)) != 0) {
+ LOG(log_info, logtype_dsi, "dsi_tcp_init: getaddrinfo '%s': %s\n", hostname, gai_strerror(err));
goto interfaces;
}
guess_interface(dsi, hostname, port ? port : "548");
EC_CLEANUP:
- if (address)
- free(address);
+ if (a)
+ free(a);
EC_EXIT;
}