| 16 |
|
#else |
| 17 |
|
#include <sys/tk_types.h> |
| 18 |
|
#endif |
| 19 |
+ |
#ifndef WIN32 |
| 20 |
|
#include <sys/socket.h> |
| 21 |
|
#include <netinet/in.h> |
| 22 |
|
#include <netdb.h> |
| 23 |
+ |
#else |
| 24 |
+ |
#include <winsock2.h> |
| 25 |
+ |
#endif |
| 26 |
|
|
| 27 |
|
#include <stdlib.h> |
| 28 |
|
#include <string.h> |
| 45 |
|
char c; |
| 46 |
|
|
| 47 |
|
if (sscanf(hostname, "%d.%d.%d.%d%c", &b3, &b2, &b1, &b0, &c) == 4) { |
| 48 |
< |
unsigned long val; |
| 48 |
> |
unsigned long val; |
| 49 |
|
|
| 50 |
< |
val = (b3 << 24) | (b2 << 16) | (b1 << 8) | b0; |
| 51 |
< |
p_addr->s_addr = htonl(val); |
| 52 |
< |
return 0; |
| 50 |
> |
val = (b3 << 24) | (b2 << 16) | (b1 << 8) | b0; |
| 51 |
> |
p_addr->s_addr = htonl(val); |
| 52 |
> |
return 0; |
| 53 |
|
} |
| 54 |
|
|
| 55 |
+ |
#ifdef WIN32 |
| 56 |
+ |
/* Init the winsock, because we all love windows */ |
| 57 |
+ |
WSADATA wsaData; |
| 58 |
+ |
|
| 59 |
+ |
if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { |
| 60 |
+ |
errf("Unable to init a winsock"); |
| 61 |
+ |
return -1; |
| 62 |
+ |
} |
| 63 |
+ |
#endif |
| 64 |
|
if ((h = gethostbyname(hostname)) == NULL) { |
| 65 |
|
errf("Can't find address of %s", hostname); |
| 66 |
|
return -1; |
| 93 |
|
*p_port = htons(hport); |
| 94 |
|
return 0; |
| 95 |
|
} |
| 96 |
+ |
|
| 97 |
+ |
#ifdef WIN32 |
| 98 |
+ |
/* Init the winsock, because we all love windows */ |
| 99 |
+ |
WSADATA wsaData; |
| 100 |
+ |
|
| 101 |
+ |
if(WSAStartup(MAKEWORD(2,2), &wsaData) != NO_ERROR) { |
| 102 |
+ |
errf("Unable to init a winsock"); |
| 103 |
+ |
return -1; |
| 104 |
+ |
} |
| 105 |
+ |
#endif |
| 106 |
|
|
| 107 |
|
if ((sp = getservbyname(servname, "tcp")) == NULL) { |
| 108 |
|
errf("Unknown service `%s'", servname); |