Lines 1-4
Link Here
|
1 |
--- protocol/discovery/mdns.c.orig 2019-10-22 06:18:12 UTC |
1 |
Use a dynamically allocated port instead of binding port 5353. The bind(2) |
|
|
2 |
call fails when Avahi has already claimed port 5353. On top of that, HPLIP |
3 |
only performs one-shot queries and those shouldn't be using port 5353 according |
4 |
to RFC 6762. |
5 |
|
6 |
Don't disable loop-back. It's harmless. |
7 |
|
8 |
Use default TTL of 1. RFC 6762 requires 255 for responses, not for queries. |
9 |
|
10 |
There's no need to join the multicast group for one-shot queries. Responses |
11 |
are sent to the unicast address. |
12 |
|
13 |
--- protocol/discovery/mdns.c.orig 2020-07-01 14:48:56 UTC |
2 |
+++ protocol/discovery/mdns.c |
14 |
+++ protocol/discovery/mdns.c |
3 |
@@ -24,7 +24,11 @@ |
15 |
@@ -24,7 +24,11 @@ |
4 |
Author: Sanjay Kumar |
16 |
Author: Sanjay Kumar |
Lines 13-27
Link Here
|
13 |
#include <string.h> |
25 |
#include <string.h> |
14 |
#include <syslog.h> |
26 |
#include <syslog.h> |
15 |
#include <sys/socket.h> |
27 |
#include <sys/socket.h> |
16 |
@@ -85,6 +89,11 @@ static int mdns_open_socket(int *psocket) |
28 |
@@ -70,57 +74,13 @@ static int mdns_convert_name_to_dns(const char *name, |
|
|
29 |
static int mdns_open_socket(int *psocket) |
30 |
{ |
31 |
int stat = MDNS_STATUS_ERROR; |
32 |
- int udp_socket = -1, yes = 1; |
33 |
- char loop = 0, ttl = 255; |
34 |
- struct sockaddr_in recv_addr , addr; |
35 |
- struct ip_mreq mreq; |
36 |
+ int udp_socket; |
17 |
|
37 |
|
18 |
/* Get rid of "address already in use" error message. */ |
38 |
DBG("mdns_open_socket entry.\n"); |
19 |
if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) |
39 |
|
20 |
+ { |
40 |
if ((udp_socket = socket(AF_INET, SOCK_DGRAM, 0)) == -1) |
21 |
+ BUG("unable to setsockopt: %m\n"); |
|
|
22 |
+ goto bugout; |
23 |
+ } |
24 |
+ if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEPORT, &yes, sizeof(yes)) == -1) |
25 |
{ |
41 |
{ |
26 |
BUG("unable to setsockopt: %m\n"); |
42 |
BUG("unable to create udp socket: %m\n"); |
|
|
43 |
- goto bugout; |
44 |
- } |
45 |
- |
46 |
- /* Get rid of "address already in use" error message. */ |
47 |
- if (setsockopt(udp_socket, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(yes)) == -1) |
48 |
- { |
49 |
- BUG("unable to setsockopt: %m\n"); |
50 |
- goto bugout; |
51 |
- } |
52 |
- |
53 |
- /* Bind the socket to port and IP equal to INADDR_ANY. */ |
54 |
- bzero(&recv_addr, sizeof(recv_addr)); |
55 |
- recv_addr.sin_family = AF_INET; |
56 |
- recv_addr.sin_addr.s_addr = htonl(INADDR_ANY); |
57 |
- recv_addr.sin_port = htons(5353); |
58 |
- if (bind(udp_socket, (struct sockaddr *) &recv_addr, sizeof(recv_addr)) == -1) |
59 |
- { |
60 |
- BUG("unable to bind udp socket: %m\n"); |
61 |
- goto bugout; |
62 |
- } |
63 |
- |
64 |
- /* Set multicast loopback off. */ |
65 |
- if (setsockopt(udp_socket, IPPROTO_IP, IP_MULTICAST_LOOP, &loop, sizeof(loop)) == -1) |
66 |
- { |
67 |
- BUG("unable to setsockopt: %m\n"); |
68 |
- goto bugout; |
69 |
- } |
70 |
- |
71 |
- /* Set ttl to 255. Required by mdns. */ |
72 |
- if (setsockopt(udp_socket, IPPROTO_IP, IP_MULTICAST_TTL, &ttl, sizeof(ttl))== -1) |
73 |
- { |
74 |
- BUG("unable to setsockopt: %m\n"); |
75 |
- goto bugout; |
76 |
- } |
77 |
- |
78 |
- /* Join the .local multicast group */ |
79 |
- mreq.imr_multiaddr.s_addr = inet_addr("224.0.0.251"); |
80 |
- mreq.imr_interface.s_addr = htonl(INADDR_ANY); |
81 |
- if (setsockopt(udp_socket, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mreq, sizeof(struct ip_mreq)) == -1) { |
82 |
- BUG("unable to add to multicast group: %m\n"); |
83 |
- close(udp_socket); |
27 |
goto bugout; |
84 |
goto bugout; |
|
|
85 |
} |
86 |
|