Guest_imported
New member
- Jan 1, 1970
- 0
#include <stdlib.h>
#include <stdio.h>
#include <iostream.h>
#define _System __syscall
extern "C"
{
#include "types.h"
#include "netdb.h"
#include "sys/socket.h"
#include "netinet/in.h"
}
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,"EXCEPTION:Sockinit error!"
res_code = getinetversion(inet_ver);
EXCEPTION(res_code != 0,"EXCEPTION:getinetversion error!"
cout << "Inet version: " << inet_ver << endl;
switch(argc)
{
case 1: cout << "Enter the host name: ";
cin >> inp_addr;
break;
case 2: cout << "Looking up " << argv[1] << endl;
strcpy(inp_addr, argv[1]);
break;
default: cout << "Format: prog1.exe [hostname]\n";
return 1;
}
phost_entry = prog1byname(inp_addr);
EXCEPTION(phost_entry == NULL,"EXCEPTIONrog1byname error!"
cout << "Host name: " << 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 << "Dotted address: " << szIPAddr << endl;
return 0;
}
void EXCEPTION(int cond, char szMsg[])
{
if(cond)
{
cerr << szMsg <<endl;
exit(1);
}
}
#include <stdio.h>
#include <iostream.h>
#define _System __syscall
extern "C"
{
#include "types.h"
#include "netdb.h"
#include "sys/socket.h"
#include "netinet/in.h"
}
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,"EXCEPTION:Sockinit error!"
res_code = getinetversion(inet_ver);
EXCEPTION(res_code != 0,"EXCEPTION:getinetversion error!"
cout << "Inet version: " << inet_ver << endl;
switch(argc)
{
case 1: cout << "Enter the host name: ";
cin >> inp_addr;
break;
case 2: cout << "Looking up " << argv[1] << endl;
strcpy(inp_addr, argv[1]);
break;
default: cout << "Format: prog1.exe [hostname]\n";
return 1;
}
phost_entry = prog1byname(inp_addr);
EXCEPTION(phost_entry == NULL,"EXCEPTIONrog1byname error!"
cout << "Host name: " << 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 << "Dotted address: " << szIPAddr << endl;
return 0;
}
void EXCEPTION(int cond, char szMsg[])
{
if(cond)
{
cerr << szMsg <<endl;
exit(1);
}
}