Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can you anyone tell me what this program does?

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>

#define _System __syscall
extern &quot;C&quot;
{
#include &quot;types.h&quot;
#include &quot;netdb.h&quot;
#include &quot;sys/socket.h&quot;
#include &quot;netinet/in.h&quot;
}


void EXCEPTION(int cond, char szMsg[]);

int main(int argc, char* argv[])
{

sockaddr_in host_addr;
hostent *phost_entry;
char szIPAddr[256];
char inp_addr[256];
char inet_ver[256];
int res_code;

// Init .dll and get the version number.
res_code = sock_init();
EXCEPTION(res_code != 0,&quot;EXCEPTION:Sockinit error!&quot;);
res_code = getinetversion(inet_ver);
EXCEPTION(res_code != 0,&quot;EXCEPTION:getinetversion error!&quot;);
cout << &quot;Inet version: &quot; << inet_ver << endl;

switch(argc)
{
case 1: cout << &quot;Enter the host name: &quot;;
cin >> inp_addr;
break;
case 2: cout << &quot;Looking up &quot; << argv[1] << endl;
strcpy(inp_addr, argv[1]);
break;
default: cout << &quot;Format: prog1.exe [hostname]\n&quot;;
return 1;
}


phost_entry = prog1byname(inp_addr);
EXCEPTION(phost_entry == NULL,&quot;EXCEPTION:prog1byname error!&quot;);
cout << &quot;Host name: &quot; << phost_entry->h_name << endl;

bcopy(phost_entry->h_addr, (caddr_t)&host_addr.sin_addr, phost_entry->h_length);
strcpy(szIPAddr, inet_ntoa(host_addr.sin_addr));
cout << &quot;Dotted address: &quot; << szIPAddr << endl;

return 0;
}


void EXCEPTION(int cond, char szMsg[])
{
if(cond)
{
cerr << szMsg <<endl;
exit(1);
}
}
 
Looks to me to be a name resolution program. Enter in the hostname and it returns the IP address.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top