"Fossies" - the Fresh Open Source Software Archive  

Source code changes of the file "src/network.c" between
dnsmasq-2.82.tar.xz and dnsmasq-2.83.tar.xz

About: Dnsmasq is a lightweight caching DNS forwarder and DHCP server.

network.c  (dnsmasq-2.82.tar.xz):network.c  (dnsmasq-2.83.tar.xz)
skipping to change at line 1258 skipping to change at line 1258
close(fd); close(fd);
} }
return -1; return -1;
} }
int local_bind(int fd, union mysockaddr *addr, char *intname, unsigned int ifind ex, int is_tcp) int local_bind(int fd, union mysockaddr *addr, char *intname, unsigned int ifind ex, int is_tcp)
{ {
union mysockaddr addr_copy = *addr; union mysockaddr addr_copy = *addr;
unsigned short port;
int tries = 1, done = 0;
unsigned int ports_avail = ((unsigned short)daemon->max_port - (unsigned short
)daemon->min_port) + 1;
if (addr_copy.sa.sa_family == AF_INET)
port = addr_copy.in.sin_port;
else
port = addr_copy.in6.sin6_port;
/* cannot set source _port_ for TCP connections. */ /* cannot set source _port_ for TCP connections. */
if (is_tcp) if (is_tcp)
port = 0;
/* Bind a random port within the range given by min-port and max-port */
if (port == 0)
{
tries = ports_avail < 30 ? 3 * ports_avail : 100;
port = htons(daemon->min_port + (rand16() % ((unsigned short)ports_avail))
);
}
while (tries--)
{ {
if (addr_copy.sa.sa_family == AF_INET) if (addr_copy.sa.sa_family == AF_INET)
addr_copy.in.sin_port = 0; addr_copy.in.sin_port = port;
else else
addr_copy.in6.sin6_port = 0; addr_copy.in6.sin6_port = port;
if (bind(fd, (struct sockaddr *)&addr_copy, sa_len(&addr_copy)) != -1)
{
done = 1;
break;
}
if (errno != EADDRINUSE && errno != EACCES)
return 0;
port = htons(daemon->min_port + (rand16() % ((unsigned short)ports_avail))
);
} }
if (bind(fd, (struct sockaddr *)&addr_copy, sa_len(&addr_copy)) == -1) if (!done)
return 0; return 0;
if (!is_tcp && ifindex > 0) if (!is_tcp && ifindex > 0)
{ {
#if defined(IP_UNICAST_IF) #if defined(IP_UNICAST_IF)
if (addr_copy.sa.sa_family == AF_INET) if (addr_copy.sa.sa_family == AF_INET)
{ {
uint32_t ifindex_opt = htonl(ifindex); uint32_t ifindex_opt = htonl(ifindex);
return setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_opt, sizeof( ifindex_opt)) == 0; return setsockopt(fd, IPPROTO_IP, IP_UNICAST_IF, &ifindex_opt, sizeof( ifindex_opt)) == 0;
} }
 End of changes. 5 change blocks. 
3 lines changed or deleted 35 lines changed or added

Home  |  About  |  Features  |  All  |  Newest  |  Dox  |  Diffs  |  RSS Feeds  |  Screenshots  |  Comments  |  Imprint  |  Privacy  |  HTTP(S)