-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwsprocs.cpp
More file actions
54 lines (49 loc) · 1.46 KB
/
wsprocs.cpp
File metadata and controls
54 lines (49 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#include "wsprocs.hpp"
int wsInit(void) {
WSADATA wsaData;
return WSAStartup(MAKEWORD(1,1), &wsaData);
}
char* getHostIP(char* hostname/*, DWORD* dwError*/) {
struct hostent *remoteHost;
struct in_addr addr;
remoteHost=gethostbyname(hostname);
if(remoteHost==NULL) {
// *dwError=WSAGetLastError();
return NULL;
/*
if(dwError!=0) {
if(dwError == WSAHOST_NOT_FOUND) {
std::cout << "Host not found." << std::endl;
}
else if(dwError == WSANO_DATA) {
std::cout << "No data record found." << std::endl;
}
else {
std::cout << "Function failed with error: " << dwError << std::endl;
}
}
*/
}
else {
// *dwError=0;
if(remoteHost->h_addrtype == AF_INET) {
/*
int i=0;
while(remoteHost->h_addr_list[i] != 0) {
addr.s_addr = *(u_long *) remoteHost->h_addr_list[i++];
std::cout << "IP #" << i << ": " << inet_ntoa(addr) << std::endl;
}
*/
if(remoteHost->h_addr_list[0] != 0) {
addr.s_addr = *(u_long *) remoteHost->h_addr_list[0];
return inet_ntoa(addr);
}
else {
return NULL;
}
}
else {
return NULL;
}
}
}