summaryrefslogtreecommitdiffstats
path: root/WDL/jnetlib/util.cpp
blob: fedd9116cc9f89edb751edd61b789cce0502d420 (plain) (blame)
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
/*
** JNetLib
** Copyright (C) 2000-2001 Nullsoft, Inc.
** Author: Justin Frankel
** File: util.cpp - JNL implementation of basic network utilities
** License: see jnetlib.h
*/

#include "netinc.h"

#include "util.h"
#include "../wdlcstring.h"

int JNL::open_socketlib()
{
#ifdef _WIN32
  WSADATA wsaData;
  if (WSAStartup(MAKEWORD(1, 1), &wsaData)) return 1;
#endif
  return 0;
}
void JNL::close_socketlib()
{
#ifdef _WIN32
  WSACleanup();
#endif
}
unsigned int JNL::ipstr_to_addr(const char *cp) 
{ 
  return ::inet_addr(cp); 
}

void JNL::addr_to_ipstr(unsigned int addr, char *host, int maxhostlen) 
{ 
  struct in_addr a; a.s_addr=addr;
  char *p=::inet_ntoa(a);
  lstrcpyn_safe(host,p?p:"",maxhostlen);
}