10 Ekim 2018 Çarşamba

getnameinfo metodu

Örnek
Şöyle yaparız.
struct sockaddr_in saGNI;
char servInfo[NI_MAXSERV];

saGNI.sin_family = AF_INET;
saGNI.sin_addr.s_addr = inet_addr("10.80.101.162");
saGNI.sin_port = htons(64);

char host[512]; // <-- information to obtain
getnameinfo((struct sockaddr *) &saGNI, sizeof(struct sockaddr),
 host, NI_MAXHOST, servInfo, NI_MAXSERV, NI_NUMERICSERV);
Örnek
Şöyle yaparız.
std::string computer_name;
computer_name.resize(NI_MAXHOST);
struct sockaddr_in socket_address = ...;
char service_info[NI_MAXSERV] = {};


getnameinfo((struct sockaddr *) &socket_address,
            sizeof(socket_address),
            &computer_name[0],
            NI_MAXHOST, service_info, NI_MAXSERV, NI_NUMERICSERV);

Hiç yorum yok:

Yorum Gönder