RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 798512 - getaddrinfo() with hints.ai_family = AF_UNSPEC changes behavior in glibc
Summary: getaddrinfo() with hints.ai_family = AF_UNSPEC changes behavior in glibc
Keywords:
Status: CLOSED NOTABUG
Alias: None
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: glibc
Version: 6.3
Hardware: All
OS: Unspecified
medium
medium
Target Milestone: rc
: ---
Assignee: Jeff Law
QA Contact: qe-baseos-tools-bugs
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2012-02-29 05:58 UTC by Hangbin Liu
Modified: 2016-11-24 15:38 UTC (History)
2 users (show)

Fixed In Version:
Doc Type: Bug Fix
Doc Text:
Clone Of:
Environment:
Last Closed: 2012-03-01 07:07:22 UTC
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)

Description Hangbin Liu 2012-02-29 05:58:17 UTC
Description of problem:
When use getaddrinfo to write ipv4/ipv6 programs, res->ai_family should be set to zero if hints.ai_family = AF_UNSPEC and host set to NULL

Version-Release number of selected component (if applicable):
glibc-2.12

How reproducible:
every time

Steps to Reproduce:

reproducer : 
#include	<stdio.h> 
#include	<sys/socket.h> 
#include	<sys/types.h> 
#include	<string.h> 
#include	<netdb.h>
#include	<errno.h>
#include	<stdlib.h>

int main(int argc, char** argv)
{
	int errno;
	struct addrinfo hints, *res;
	
	bzero(&hints, sizeof(struct addrinfo));
	hints.ai_family = PF_UNSPEC;    /* Allow IPv4 or IPv6 */
	hints.ai_socktype = SOCK_STREAM; /* Datagram socket */
	hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
	hints.ai_protocol = 0;          /* Any protocol */
	hints.ai_canonname = NULL;
	hints.ai_addr = NULL;
	hints.ai_next = NULL;

	if ((errno = getaddrinfo(NULL, "12345", &hints, &res)) != 0) {
			printf("getaddrinfo error %s\n", gai_strerror(errno));
			exit(1);
	}

	printf("family type is %d\n", res->ai_family);
	
	freeaddrinfo(res);
	return 0;
}

  
Actual results:
family type is 2

Expected results:
family type is 3

Additional info:

Comment 1 Hangbin Liu 2012-02-29 06:00:34 UTC
Sorry, Expected results should be :
family type is 0

Comment 2 Jeff Law 2012-03-01 07:07:22 UTC
What makes you think the family type for the result should be zero?

The result is going to be a linked list of addrinfo structures.  Some of those addrinfo structures will be suitable for IPV4, others for IPV6.  Those suitable for IPV4 will the IPV4 family (2); those suitable for IPV6 will have the IPV6 family (10).

If you put a breakpoint after the call to getaddrinfo you can look at the linked list of structures:

(gdb) p *res
$1 = {ai_flags = 1, ai_family = 2, ai_socktype = 1, ai_protocol = 6, ai_addrlen = 16, ai_addr = 0x6010a0, ai_canonname = 0x0, ai_next = 0x601010}
(gdb) p *res->ai_next
$2 = {ai_flags = 1, ai_family = 10, ai_socktype = 1, ai_protocol = 6, ai_addrlen = 28, ai_addr = 0x601040, ai_canonname = 0x0, ai_next = 0x0}

The first one is the AF_INET addrinfo structure, the second is the AF_INET6 addrinfo structure.

This implementation is rfc3493 compliant as far as I know.  If you disagree, can you please be more specific about why you think getaddrinfo should be returning AF_UNSPEC values?

Comment 3 Hangbin Liu 2012-03-02 03:38:13 UTC
It turned out what I thought was wrong. 

I thought this function will create a list which ai_family = 0, then we can create a socket by socket(res->ai_family, res->ai_socktype,0), which can handle both IPv4 and IPv6 connections. Now I known we can't create socket with family = 0 ....

But if we set hints.ai_family = PF_UNSPEC and got a linked list with family equal to 2 and 10, then we have to create 2 sockets to handle IPv4/IPv6 connections. I can't see the difference with 2 programs/processes manage IPv4/IPv6 separately. Because we can use a single socket to connect both IPv4/IPv6 servers on client, although we can only use one family at a time.

I know I made a mistake on "same time" and "single time". this comment is only to explain why I thought the family type for the result should be zero before. Sorry for disturbing you

Comment 4 Jeff Law 2012-03-02 17:59:33 UTC
No worries.  I've been looking closely at the rfcs related to getaddrinfo recently, so it was already fresh in my mind.  You didn't disturb me at all.

If anything else comes up, don't hesitate to file a report.


Note You need to log in before you can comment on or make changes to this bug.