#include <stdlib.h>
#include <string.h>
#include <errno.h>
-#ifdef HAVE_UNISTD_H
#include <unistd.h>
-#endif /* HAVE_UNISTD_H */
#include <sys/un.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <netdb.h>
-
-#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
-#endif /* HAVE_SYS_TYPES_H */
-#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
-#endif /* HAVE_SYS_TIME_H */
-
#include <atalk/logger.h>
+#include <atalk/compat.h>
#include "usockfd.h"
#include <sys/select.h>
hints.ai_socktype = SOCK_STREAM;
if ((ret = getaddrinfo(host, port, &hints, &servinfo)) != 0) {
- LOG(log_error, logtype_default, "tsockfd_create: getaddrinfo: %s\n", gai_strerror(ret));
- return 0;
+ LOG(log_error, logtype_cnid, "tsockfd_create: getaddrinfo: %s\n", gai_strerror(ret));
+ return -1;
}
/* create a socket */
/* loop through all the results and bind to the first we can */
for (p = servinfo; p != NULL; p = p->ai_next) {
if ((sockfd = socket(p->ai_family, p->ai_socktype, p->ai_protocol)) == -1) {
- LOG(log_info, logtype_default, "tsockfd_create: socket: %s", strerror(errno));
+ LOG(log_info, logtype_cnid, "tsockfd_create: socket: %s", strerror(errno));
continue;
}
if (bind(sockfd, p->ai_addr, p->ai_addrlen) == -1) {
close(sockfd);
- LOG(log_info, logtype_default, "tsockfd_create: bind: %s\n", strerror(errno));
+ LOG(log_info, logtype_cnid, "tsockfd_create: bind: %s\n", strerror(errno));
continue;
}
if (listen(sockfd, backlog) < 0) {
close(sockfd);
- LOG(log_info, logtype_default, "tsockfd_create: listen: %s\n", strerror(errno));
+ LOG(log_info, logtype_cnid, "tsockfd_create: listen: %s\n", strerror(errno));
continue;
}
}
if (p == NULL) {
- LOG(log_error, logtype_default, "tsockfd_create: no suitable network config %s:%s", host, port);
+ LOG(log_error, logtype_cnid, "tsockfd_create: no suitable network config %s:%s", host, port);
freeaddrinfo(servinfo);
return -1;
}
socklen_t size;
fd_set readfds;
int ret;
- struct timeval tv;
FD_ZERO(&readfds);
FD_SET(sockfd, &readfds);
strerror(errno));
return -1;
}
- if (setnonblock(fd, 1) != 0) {
- LOG(log_error, logtype_cnid, "setnonblock: %s", strerror(errno));
- return -1;
- }
return fd;
} else
return 0;