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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can anyone tell me what this program does?

Status
Not open for further replies.

clickshah

Programmer
Dec 12, 2001
3
GB
#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);
}
}
 
Returns the IP address of the host name passed into the command line?
Any man willing to sacrifice liberty for security deserves neither liberty nor security.

-Ben Franklin
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top