mirror of
https://github.com/yrutschle/sslh.git
synced 2025-06-03 09:01:03 +03:00
ignore brackets in hostname in config files
This commit is contained in:
parent
7d561af423
commit
00d5872aa1
30
common.c
30
common.c
@ -442,16 +442,31 @@ char* sprintaddr(char* buf, size_t size, struct addrinfo *a)
|
|||||||
|
|
||||||
/* Turns a hostname and port (or service) into a list of struct addrinfo
|
/* Turns a hostname and port (or service) into a list of struct addrinfo
|
||||||
* returns 0 on success, -1 otherwise and logs error
|
* returns 0 on success, -1 otherwise and logs error
|
||||||
|
*
|
||||||
|
* *host gets modified
|
||||||
**/
|
**/
|
||||||
int resolve_split_name(struct addrinfo **out, const char* host, const char* serv)
|
int resolve_split_name(struct addrinfo **out, char* host, const char* serv)
|
||||||
{
|
{
|
||||||
struct addrinfo hint;
|
struct addrinfo hint;
|
||||||
|
char *end;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
memset(&hint, 0, sizeof(hint));
|
memset(&hint, 0, sizeof(hint));
|
||||||
hint.ai_family = PF_UNSPEC;
|
hint.ai_family = PF_UNSPEC;
|
||||||
hint.ai_socktype = SOCK_STREAM;
|
hint.ai_socktype = SOCK_STREAM;
|
||||||
|
|
||||||
|
/* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
|
||||||
|
* around IP address */
|
||||||
|
if (host[0] == '[') {
|
||||||
|
end = strrchr(host, ']');
|
||||||
|
if (!end) {
|
||||||
|
fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
|
||||||
|
}
|
||||||
|
host++; /* skip first bracket */
|
||||||
|
*end = 0; /* remove last bracket */
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
res = getaddrinfo(host, serv, &hint, out);
|
res = getaddrinfo(host, serv, &hint, out);
|
||||||
if (res)
|
if (res)
|
||||||
log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv);
|
log_message(LOG_ERR, "%s `%s:%s'\n", gai_strerror(res), host, serv);
|
||||||
@ -464,7 +479,7 @@ fullname: input string -- it gets clobbered
|
|||||||
*/
|
*/
|
||||||
void resolve_name(struct addrinfo **out, char* fullname)
|
void resolve_name(struct addrinfo **out, char* fullname)
|
||||||
{
|
{
|
||||||
char *serv, *host, *end;
|
char *serv, *host;
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/* Find port */
|
/* Find port */
|
||||||
@ -478,17 +493,6 @@ void resolve_name(struct addrinfo **out, char* fullname)
|
|||||||
|
|
||||||
host = fullname;
|
host = fullname;
|
||||||
|
|
||||||
/* If it is a RFC-Compliant IPv6 address ("[1234::12]:443"), remove brackets
|
|
||||||
* around IP address */
|
|
||||||
if (host[0] == '[') {
|
|
||||||
end = strrchr(host, ']');
|
|
||||||
if (!end) {
|
|
||||||
fprintf(stderr, "%s: no closing bracket in IPv6 address?\n", host);
|
|
||||||
}
|
|
||||||
host++; /* skip first bracket */
|
|
||||||
*end = 0; /* remove last bracket */
|
|
||||||
}
|
|
||||||
|
|
||||||
res = resolve_split_name(out, host, serv);
|
res = resolve_split_name(out, host, serv);
|
||||||
if (res) {
|
if (res) {
|
||||||
fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);
|
fprintf(stderr, "%s `%s'\n", gai_strerror(res), fullname);
|
||||||
|
2
common.h
2
common.h
@ -106,7 +106,7 @@ void drop_privileges(const char* user_name);
|
|||||||
void write_pid_file(const char* pidfile);
|
void write_pid_file(const char* pidfile);
|
||||||
void log_message(int type, char* msg, ...);
|
void log_message(int type, char* msg, ...);
|
||||||
void dump_connection(struct connection *cnx);
|
void dump_connection(struct connection *cnx);
|
||||||
int resolve_split_name(struct addrinfo **out, const char* hostname, const char* port);
|
int resolve_split_name(struct addrinfo **out, char* hostname, const char* port);
|
||||||
|
|
||||||
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
|
int start_listen_sockets(int *sockfd[], struct addrinfo *addr_list);
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user