Search code examples
unixnetwork-programmingposixipv6ipv4

Can I assume that accept(3) returns IPv4 address if I apply it to an IPv4 socket?


Let s be a file descriptor of a socket made by socket(PF_INET, ...).

If I call accept(s, (struct sockaddr *) &addr, ...), where addr is of type struct sockaddr_in, can I assume that the format of the returned address is IPv4, i.e.,

addr.sin_family == AF_INET ?


Solution

  • From The Open Group's description:

    The accept() function shall extract the first connection on the queue of pending connections, create a new socket with the same socket type protocol and address family as the specified socket, and allocate a new file descriptor for that socket.