degesch: fix IPv6:port in irc_split_host_port()
This commit is contained in:
		
							
								
								
									
										26
									
								
								degesch.c
									
									
									
									
									
								
							
							
						
						
									
										26
									
								
								degesch.c
									
									
									
									
									
								
							@@ -5642,25 +5642,27 @@ irc_finish_connection (struct server *s, int socket, const char *hostname)
 | 
				
			|||||||
	refresh_prompt (s->ctx);
 | 
						refresh_prompt (s->ctx);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					/// Unwrap IPv6 addresses in format_host_port_pair() format
 | 
				
			||||||
static void
 | 
					static void
 | 
				
			||||||
irc_split_host_port (char *s, char **host, char **port)
 | 
					irc_split_host_port (char *s, char **host, char **port)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
	// FIXME: this won't work if this is an IPv6 address w/o a port
 | 
						*host = s;
 | 
				
			||||||
	char *colon = strrchr (s, ':');
 | 
						*port = "6667";
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char *right_bracket = strchr (s, ']');
 | 
				
			||||||
 | 
						if (s[0] == '[' && right_bracket)
 | 
				
			||||||
 | 
						{
 | 
				
			||||||
 | 
							*right_bracket = '\0';
 | 
				
			||||||
 | 
							*host = s + 1;
 | 
				
			||||||
 | 
							s = right_bracket + 1;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						char *colon = strchr (s, ':');
 | 
				
			||||||
	if (colon)
 | 
						if (colon)
 | 
				
			||||||
	{
 | 
						{
 | 
				
			||||||
		*colon = '\0';
 | 
							*colon = '\0';
 | 
				
			||||||
		*port = ++colon;
 | 
							*port = colon + 1;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
	else
 | 
					 | 
				
			||||||
		*port = "6667";
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	// Unwrap IPv6 addresses in format_host_port_pair() format
 | 
					 | 
				
			||||||
	size_t host_end = strlen (s) - 1;
 | 
					 | 
				
			||||||
	if (*s == '[' && s[host_end] == ']')
 | 
					 | 
				
			||||||
		s++[host_end] = '\0';
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
	*host = s;
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
					// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user