Small typo fix and set slpd sockt O_NONBLOCK
This commit is contained in:
parent
756a6607e1
commit
99e0f5777c
2 changed files with 20 additions and 1 deletions
|
@ -1628,7 +1628,7 @@ void handle_incoming_slpd_data(void *data, int flags) {
|
||||||
sockaddr_t addr = {};
|
sockaddr_t addr = {};
|
||||||
socklen_t addrlen = sizeof addr;
|
socklen_t addrlen = sizeof addr;
|
||||||
|
|
||||||
logger(DEBUG_SCARY_THINGS, LOG_INFO, "Receiving LPD packet");
|
logger(DEBUG_SCARY_THINGS, LOG_INFO, "Receiving SLPD packet");
|
||||||
|
|
||||||
int len = recvfrom(ls->udp.fd, (void *)&pkt, MAXSIZE, 0, &addr.sa, &addrlen);
|
int len = recvfrom(ls->udp.fd, (void *)&pkt, MAXSIZE, 0, &addr.sa, &addrlen);
|
||||||
|
|
||||||
|
|
|
@ -323,6 +323,23 @@ int setup_slpd_in_socket(void) {
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifdef FD_CLOEXEC
|
||||||
|
fcntl(nfd, F_SETFD, FD_CLOEXEC);
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#ifdef O_NONBLOCK
|
||||||
|
{
|
||||||
|
int flags = fcntl(nfd, F_GETFL);
|
||||||
|
|
||||||
|
if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) {
|
||||||
|
closesocket(nfd);
|
||||||
|
logger(DEBUG_ALWAYS, LOG_ERR, "System call `%s' failed: %s", "fcntl",
|
||||||
|
strerror(errno));
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
int reuse = 1;
|
int reuse = 1;
|
||||||
if(setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
|
if(setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, (char *)&reuse, sizeof(reuse)) < 0) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Can not set SO_REUSEADDR for SLPD %s", sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Can not set SO_REUSEADDR for SLPD %s", sockstrerror(sockerrno));
|
||||||
|
@ -343,11 +360,13 @@ int setup_slpd_in_socket(void) {
|
||||||
|
|
||||||
group.imr_multiaddr.s_addr = inet_addr(my_slpd_group);
|
group.imr_multiaddr.s_addr = inet_addr(my_slpd_group);
|
||||||
group.imr_interface.s_addr = htonl(INADDR_ANY);
|
group.imr_interface.s_addr = htonl(INADDR_ANY);
|
||||||
|
|
||||||
if(setsockopt(nfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0) {
|
if(setsockopt(nfd, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&group, sizeof(group)) < 0) {
|
||||||
logger(DEBUG_ALWAYS, LOG_ERR, "Can not join group for SLPD %s", sockstrerror(sockerrno));
|
logger(DEBUG_ALWAYS, LOG_ERR, "Can not join group for SLPD %s", sockstrerror(sockerrno));
|
||||||
closesocket(nfd);
|
closesocket(nfd);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
logger(DEBUG_STATUS, LOG_INFO, "SLPD socket ready (%d)", nfd);
|
logger(DEBUG_STATUS, LOG_INFO, "SLPD socket ready (%d)", nfd);
|
||||||
|
|
||||||
return nfd;
|
return nfd;
|
||||||
|
|
Loading…
Reference in a new issue