Surround IPv6 literals with [] in Host: headers
This commit is contained in:
		
							parent
							
								
									736e052dc1
								
							
						
					
					
						commit
						121a11d8e5
					
				
							
								
								
									
										12
									
								
								src/reqs.c
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								src/reqs.c
									
									
									
									
									
								
							@ -268,6 +268,7 @@ static int
 | 
				
			|||||||
establish_http_connection (struct conn_s *connptr, struct request_s *request)
 | 
					establish_http_connection (struct conn_s *connptr, struct request_s *request)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
        char portbuff[7];
 | 
					        char portbuff[7];
 | 
				
			||||||
 | 
					        char dst[sizeof(struct in6_addr)];
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        /* Build a port string if it's not a standard port */
 | 
					        /* Build a port string if it's not a standard port */
 | 
				
			||||||
        if (request->port != HTTP_PORT && request->port != HTTP_PORT_SSL)
 | 
					        if (request->port != HTTP_PORT && request->port != HTTP_PORT_SSL)
 | 
				
			||||||
@ -275,12 +276,23 @@ establish_http_connection (struct conn_s *connptr, struct request_s *request)
 | 
				
			|||||||
        else
 | 
					        else
 | 
				
			||||||
                portbuff[0] = '\0';
 | 
					                portbuff[0] = '\0';
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					        if (inet_pton(AF_INET6, request->host, dst) > 0) {
 | 
				
			||||||
 | 
					                /* host is an IPv6 address literal, so surround it with
 | 
				
			||||||
 | 
					                 * [] */
 | 
				
			||||||
 | 
					                return write_message (connptr->server_fd,
 | 
				
			||||||
 | 
					                                      "%s %s HTTP/1.0\r\n"
 | 
				
			||||||
 | 
					                                      "Host: [%s]%s\r\n"
 | 
				
			||||||
 | 
					                                      "Connection: close\r\n",
 | 
				
			||||||
 | 
					                                      request->method, request->path,
 | 
				
			||||||
 | 
					                                      request->host, portbuff);
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
                return write_message (connptr->server_fd,
 | 
					                return write_message (connptr->server_fd,
 | 
				
			||||||
                                      "%s %s HTTP/1.0\r\n"
 | 
					                                      "%s %s HTTP/1.0\r\n"
 | 
				
			||||||
                                      "Host: %s%s\r\n"
 | 
					                                      "Host: %s%s\r\n"
 | 
				
			||||||
                                      "Connection: close\r\n",
 | 
					                                      "Connection: close\r\n",
 | 
				
			||||||
                                      request->method, request->path,
 | 
					                                      request->method, request->path,
 | 
				
			||||||
                                      request->host, portbuff);
 | 
					                                      request->host, portbuff);
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
/*
 | 
					/*
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user