sockets - c++ - What does ptr->ai_family do vs AF_INET -
i going through msdn's "getting started winsock" , open socket parameters
struct addrinfo *result = null, *ptr = null, hints; iresult = getaddrinfo( argv[1], default_port, &hints, &result ); ptr=result; connectsocket = socket( ptr->ai_family, // address family (address families ipv6 ipv4) ptr->ai_socktype, // type (like tcp, udp ect) ptr->ai_protocol // protocol use (0 = service provider chooses) );
but binarytides "winsock tutorial" (they using c have seen people in c++)
s = socket( af_inet , sock_stream , 0 )
what ptr-> do? , why use on setting af_inet?
also if have free time , know sockets appreciate help.
socket(ptr->ai_family,ptr->ai_socktype, ptr->ai_protocol);
passes in variables create socket, instead of hard coding values. advantage code works both ipv4 , ipv6.
ptr->ai_family
integer, member of struct addrinfo. (and if wondering particular syntax of ptr->
, can go through this question ), have value of either af_inet
or af_inet6
(or in theory other supported protocol)
the call getaddrinfo()
host name, , resolve either ipv4 or ipv6, , pass in result socket() create socket of proper type. if hostname resolves ipv4 host, create socket can deal ipv4, if resolves ipv6, create ipv6 socket.
if instead hard coded values, e.g. af_inet
, support ipv4, whilst ptr->ai_family
either af_inet
or af_inet6
.
Comments
Post a Comment