}
_DBUS_ASSERT_ERROR_IS_CLEAR(error);
+ reuseaddr = 1;
+ if (setsockopt (fd, SOL_SOCKET, SO_REUSEADDR, &reuseaddr, sizeof(reuseaddr))==-1)
+ {
+ dbus_set_error (error, _dbus_error_from_errno (errno),
+ "Failed to set socket option \"%s:%s\": %s",
+ host ? host : "*", port, _dbus_strerror (errno));
+ }
+
if (bind (fd, (struct sockaddr*) tmp->ai_addr, tmp->ai_addrlen) < 0)
{
+ saved_errno = errno;
_dbus_close(fd, NULL);
- if (errno == EADDRINUSE)
+ if (saved_errno == EADDRINUSE)
{
/* Depending on kernel policy, it may or may not
be neccessary to bind to both IPv4 & 6 addresses