How to get domain name from Given IP in MFC (VC++)?


How to get domain name from Given IP in MFC (VC++) ? The code i am using is as below:

#include "stdafx.h" #include <winsock2.h> #include <ws2tcpip.h> #include <stdio.h> // link with ws2_32.lib #pragma comment(lib, "Ws2_32.lib") int _tmain(int argc, char **argv) { //----------------------------------------- // Declare and initialize variables WSADATA wsaData = {0}; int iResult = 0; DWORD dwRetval; struct sockaddr_in saGNI; char hostname[NI_MAXHOST]; char servInfo[NI_MAXSERV]; u_short port = 27015; // Initialize Winsock iResult = WSAStartup(MAKEWORD(2, 2), &wsaData); if (iResult != 0) { printf("WSAStartup failed: %d\n", iResult); return 1; } //----------------------------------------- // Set up sockaddr_in structure which is passed // to the getnameinfo function saGNI.sin_family = AF_INET; saGNI.sin_addr.s_addr = inet_addr(argv[1]); saGNI.sin_port = htons(port); //----------------------------------------- // Call getnameinfo dwRetval = getnameinfo((struct sockaddr *) &saGNI, sizeof (struct sockaddr), hostname, NI_MAXHOST, servInfo, NI_MAXSERV, NI_NUMERICSERV); if (dwRetval != 0) { printf("getnameinfo failed with error # %ld\n", WSAGetLastError()); return 1; } else { printf("getnameinfo returned hostname = %s\n", hostname); return 0; }

} This code is returning me hostname as = not the domain name .


int WSAAPI getnameinfo( __in const struct sockaddr FAR *sa, __in socklen_t salen, __out char FAR *host, __in DWORD hostlen, __out char FAR *serv, __in DWORD servlen, __in int flags );

<a href="http://msdn.microsoft.com/en-us/library/ms738532(v=VS.85).aspx" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms738532(v=VS.85).aspx</a>

This API call deprecates gethostbyaddr.


  • How to link a library with clang and llvm-link
  • What specs do I need to know to develop bluetooth (AVRCP 1.4) iPhone app
  • Why did my winsocks2 send result in 10057 error sometimes?
  • ODOO : Run cron at a specific time
  • Strange closesocket() behavior
  • Listening to a UDP broadcast
  • auto increment - internal reference odoo9
  • Odoo 8 (Openerp): Setting values using Wizard from list view
  • Odoo v9 domain filter with value user.id throws error that user is not defined
  • Verify digital signature using php
  • re-connection using socket in c
  • C chat program get an error Segmentation fault (core dumped)
  • Python Selenium. How to use driver.set_page_load_timeout() properly?
  • Server does not respond to new clients using select(), cpp
  • Not able to add the group sale_manger to action_invoice_cancel button
  • odoo 9 migrate binary field db to filestore
  • Is it possible to specify a hexademical number in LLVM IR code?
  • How to remove Save Button from form view
  • Winsock, accept request only from specific IP address
  • replace letters in python string
  • In IEEE 754, why does adding negative zero result in a no-op but adding positive zero does not?
  • Integrating a redirection-included method of payment in django-oscar
  • Nested Tree View in Odoo v8
  • How to Fire Windows Service stop event on System restart?
  • x86: Count transitions from 1 to 0 in 32 bit number
  • Ansible: setting user on dynamic ec2
  • How to obtain service credentials for a service instance created on IBM Bluemix without binding the
  • What does the lower left pane in OllyDbg displays?
  • How to autoplay video in angularjs?
  • Laravel Eloquent integration in Codeigniter
  • Complex trait requirements on struct
  • Unix Network Programming Clarification
  • Google map in top corner left
  • Monotouch crashes with NullReferenceException on non nullable object
  • sweetalert2 inputoptions from file in select example
  • Simple linked list-C
  • Android activity accessing service's static reference before the service is ready
  • Are Kotlin's Float, Int etc optimised to built-in types in the JVM? [duplicate]
  • Does armcc optimizes non-volatile variables with -O0?
  • Conditional In-Line CSS for IE and Others?