I can not get port number when i accept with sockaddr_storage in ipv6.
Here is my v4 code:
peersockfd = accept(xtcpsock_fd,(struct sockaddr*)&addr,(socklen_t*)&len);
I am trying to do the same thing for v6 but sockaddr_storage doesn't have any member as port. How can i do that?
peersockfd = accept(xtcpsock6_fd, (struct sockaddr *)&their_addr, &sin_size);
inet_ntop(their_addr.ss_family, &((struct sockaddr_in6 *)&their_addr)->sin6_addr,s,sizeof s);
For IPv6 you need to cast to sockaddr_in6 and then the member is named sin6_port rather than sin_port.