- int temp = sizeof(struct sockaddr_in);
- int ret = -1;
- int len = strlen(src) + 1;
- wchar_t *srcNonConst = (wchar_t *)malloc(len);
- memset(srcNonConst, 0, len);
- MultiByteToWideChar(CP_ACP, NULL, src, -1, srcNonConst, len);
-
- if( WSAStringToAddress(srcNonConst,af,NULL,(LPSOCKADDR)dst,&temp) == 0 )
- {
- ret = 1;
- }
- else
- {
- if( WSAGetLastError() == WSAEINVAL )
- {
- ret = -1;
- }
- }
- //free(srcNonConst);
- return ret;
-}
-
-/*
- * Check whether "cp" is a valid ascii representation of an Internet address
- * and convert to a binary address. Returns 1 if the address is valid, 0 if
- * not. This replaces inet_addr, the return value from which cannot
- * distinguish between failure and a local broadcast address.
- *
- * This implementation of the standard inet_aton() function was copied
- * (with trivial modifications) from the OpenBSD project.
- */
-int
-win32_inet_aton(const char *cp, struct in_addr *addr)
-{
- register unsigned int val;
- register int base, n;
- register char c;
- unsigned int parts[4];
- register unsigned int *pp = parts;
-
- assert(sizeof(val) == 4);
-
- c = *cp;
- while(1) {
- /*
- * Collect number up to ``.''.
- * Values are specified as for C:
- * 0x=hex, 0=octal, isdigit=decimal.
- */
- if(!isdigit(c))
- return (0);
- val = 0; base = 10;
- if(c == '0') {
- c = *++cp;
- if(c == 'x' || c == 'X')
- base = 16, c = *++cp;
- else
- base = 8;
- }
- while(1) {
- if(isascii(c) && isdigit(c)) {
- val = (val * base) + (c - '0');
- c = *++cp;
- } else if(base == 16 && isascii(c) && isxdigit(c)) {
- val = (val << 4) |
- (c + 10 - (islower(c) ? 'a' : 'A'));
- c = *++cp;
- } else
- break;
- }
- if(c == '.') {
- /*
- * Internet format:
- * a.b.c.d
- * a.b.c (with c treated as 16 bits)
- * a.b (with b treated as 24 bits)
- */
- if(pp >= parts + 3)
- return (0);
- *pp++ = val;
- c = *++cp;
- } else
- break;
- }
- /*
- * Check for trailing characters.
- */
- if(c != '\0' && (!isascii(c) || !isspace(c)))
- return (0);
- /*
- * Concoct the address according to
- * the number of parts specified.
- */
- n = pp - parts + 1;
- switch(n) {
-
- case 0:
- return (0); /* initial nondigit */
-
- case 1: /* a -- 32 bits */
- break;
-
- case 2: /* a.b -- 8.24 bits */
- if((val > 0xffffff) || (parts[0] > 0xff))
- return (0);
- val |= parts[0] << 24;
- break;
-
- case 3: /* a.b.c -- 8.8.16 bits */
- if((val > 0xffff) || (parts[0] > 0xff) || (parts[1] > 0xff))
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16);
- break;
-
- case 4: /* a.b.c.d -- 8.8.8.8 bits */
- if((val > 0xff) || (parts[0] > 0xff) ||
- (parts[1] > 0xff) || (parts[2] > 0xff))
- return (0);
- val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
- break;
- }
- if(addr)
- addr->s_addr = htonl(val);
- return (1);
-}
-
-unsigned int
-win32_sleep(unsigned int seconds)
-{
- Sleep(seconds * 1000);
- return 0;
-}
-
-int win32_poll(struct pollfd *fds, int nfsd, int timeout)
-{
- fd_set rfds, wfds, efds;
- int ret;
+ struct sockaddr_in sa;
+ int len = sizeof(SOCKADDR);
+ int ret = -1;
+ int strLen = strlen(src) + 1;
+#ifdef UNICODE
+ wchar_t *srcNonConst = (wchar_t *)malloc(strLen*sizeof(wchar_t));
+ memset(srcNonConst, 0, strLen);
+ MultiByteToWideChar(CP_ACP, 0, src, -1, srcNonConst, strLen);
+#else
+ char *srcNonConst = (char *)malloc(strLen);
+ memset(srcNonConst, 0, strLen);
+ strncpy(srcNonConst, src, strLen);
+#endif