1185
1185
ip_sock=INVALID_SOCKET;
1186
1186
DBUG_PRINT("info",("calling shutdown on TCP/IP socket"));
1187
(void) shutdown(tmp_sock, SHUT_RDWR);
1187
(void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
1189
1189
tmp_sock=unix_sock;
1190
1190
if (tmp_sock != INVALID_SOCKET)
1192
1192
unix_sock=INVALID_SOCKET;
1193
1193
DBUG_PRINT("info",("calling shutdown on unix socket"));
1194
(void) shutdown(tmp_sock, SHUT_RDWR);
1194
(void) mysql_socket_shutdown(tmp_sock, SHUT_RDWR);
1195
1195
(void) unlink(mysqld_unix_port);
1197
1197
DBUG_VOID_RETURN;
1768
static my_socket create_socket(const struct addrinfo *addrinfo_list,
1770
struct addrinfo **use_addrinfo)
1772
my_socket sock= INVALID_SOCKET;
1774
for (const struct addrinfo *cur_ai= addrinfo_list; cur_ai != NULL;
1775
cur_ai= cur_ai->ai_next)
1777
if (cur_ai->ai_family != addr_family)
1780
sock= socket(cur_ai->ai_family, cur_ai->ai_socktype, cur_ai->ai_protocol);
1782
char ip_addr[INET6_ADDRSTRLEN];
1784
if (vio_get_normalized_ip_string(cur_ai->ai_addr, cur_ai->ai_addrlen,
1785
ip_addr, sizeof (ip_addr)))
1790
if (sock == INVALID_SOCKET)
1792
sql_print_error("Failed to create a socket for %s '%s': errno: %d.",
1793
(addr_family == AF_INET) ? "IPv4" : "IPv6",
1794
(const char *) ip_addr,
1795
(int) socket_errno);
1799
sql_print_information("Server socket created on IP: '%s'.",
1800
(const char *) ip_addr);
1802
*use_addrinfo= (struct addrinfo *)cur_ai;
1806
return INVALID_SOCKET;
1768
1810
static void network_init(void)
1770
1812
#ifdef HAVE_SYS_UN_H
1829
if (report_port == 0)
1831
report_port= mysqld_port;
1835
if (!opt_disable_networking)
1836
DBUG_ASSERT(report_port != 0);
1787
1839
if (mysqld_port != 0 && !opt_disable_networking && !opt_bootstrap)
1789
1841
struct addrinfo *ai, *a;
1790
1842
struct addrinfo hints;
1792
DBUG_PRINT("general",("IP Socket is %d",mysqld_port));
1844
sql_print_information("Server hostname (bind-address): '%s'; port: %d",
1845
my_bind_addr_str, mysqld_port);
1847
// Get list of IP-addresses associated with the server hostname.
1794
1848
bzero(&hints, sizeof (hints));
1795
1849
hints.ai_flags= AI_PASSIVE;
1796
1850
hints.ai_socktype= SOCK_STREAM;
1797
1851
hints.ai_family= AF_UNSPEC;
1799
1853
my_snprintf(port_buf, NI_MAXSERV, "%d", mysqld_port);
1800
error= getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai);
1803
DBUG_PRINT("error",("Got error: %d from getaddrinfo()", error));
1804
sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */
1805
unireg_abort(1); /* purecov: tested */
1808
for (a= ai; a != NULL; a= a->ai_next)
1810
ip_sock= socket(a->ai_family, a->ai_socktype, a->ai_protocol);
1811
if (ip_sock != INVALID_SOCKET)
1815
if (ip_sock == INVALID_SOCKET)
1817
DBUG_PRINT("error",("Got error: %d from socket()",socket_errno));
1818
sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */
1819
unireg_abort(1); /* purecov: tested */
1854
if (getaddrinfo(my_bind_addr_str, port_buf, &hints, &ai))
1856
sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */
1857
sql_print_error("Can't start server: cannot resolve hostname!");
1858
unireg_abort(1); /* purecov: tested */
1861
// Log all the IP-addresses.
1862
for (struct addrinfo *cur_ai= ai; cur_ai != NULL; cur_ai= cur_ai->ai_next)
1864
char ip_addr[INET6_ADDRSTRLEN];
1866
if (vio_get_normalized_ip_string(cur_ai->ai_addr, cur_ai->ai_addrlen,
1867
ip_addr, sizeof (ip_addr)))
1869
sql_print_error("Fails to print out IP-address.");
1873
sql_print_information(" - '%s' resolves to '%s';",
1874
my_bind_addr_str, ip_addr);
1878
If the 'bind-address' option specifies the hostname, which resolves to
1879
multiple IP-address, use the following rule:
1880
- if there are IPv4-addresses, use the first IPv4-address
1881
returned by getaddrinfo();
1882
- if there are IPv6-addresses, use the first IPv6-address
1883
returned by getaddrinfo();
1886
ip_sock= create_socket(ai, AF_INET, &a);
1888
if (ip_sock == INVALID_SOCKET)
1889
ip_sock= create_socket(ai, AF_INET6, &a);
1891
// Report user-error if we failed to create a socket.
1892
if (ip_sock == INVALID_SOCKET)
1894
sql_perror(ER_DEFAULT(ER_IPSOCK_ERROR)); /* purecov: tested */
1895
unireg_abort(1); /* purecov: tested */
1822
1897
#ifndef __WIN__
1824
1899
We should not use SO_REUSEADDR on windows as this would enable a
7026
7097
case (int) OPT_SKIP_STACK_TRACE:
7027
7098
test_flags|=TEST_NO_STACKTRACE;
7029
case (int) OPT_BIND_ADDRESS:
7031
struct addrinfo *res_lst, hints;
7033
bzero(&hints, sizeof(struct addrinfo));
7034
hints.ai_socktype= SOCK_STREAM;
7035
hints.ai_protocol= IPPROTO_TCP;
7037
if (getaddrinfo(argument, NULL, &hints, &res_lst) != 0)
7039
sql_print_error("Can't start server: cannot resolve hostname!");
7043
if (res_lst->ai_next)
7045
sql_print_error("Can't start server: bind-address refers to multiple interfaces!");
7048
freeaddrinfo(res_lst);
7051
7100
case OPT_CONSOLE:
7052
7101
if (opt_console)
7053
7102
opt_error_log= 0; // Force logs to stdout