| 1 |
sysadm |
1.1 |
/*
|
| 2 |
|
|
* Copyright (C) 1999 Philippe Dubois (pdubois1@hotmail.com)
|
| 3 |
|
|
* Copyright (C) 1999 Ross Combs (rocombs@cs.nmsu.edu)
|
| 4 |
|
|
*
|
| 5 |
|
|
* This program is free software; you can redistribute it and/or
|
| 6 |
|
|
* modify it under the terms of the GNU General Public License
|
| 7 |
|
|
* as published by the Free Software Foundation; either version 2
|
| 8 |
|
|
* of the License, or (at your option) any later version.
|
| 9 |
|
|
*
|
| 10 |
|
|
* This program is distributed in the hope that it will be useful,
|
| 11 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 12 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 13 |
|
|
* GNU General Public License for more details.
|
| 14 |
|
|
*
|
| 15 |
|
|
* You should have received a copy of the GNU General Public License
|
| 16 |
|
|
* along with this program; if not, write to the Free Software
|
| 17 |
|
|
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
| 18 |
|
|
*/
|
| 19 |
|
|
#include "common/setup_before.h"
|
| 20 |
|
|
#ifdef WIN32
|
| 21 |
|
|
|
| 22 |
|
|
#include <Winsock2.h>
|
| 23 |
|
|
#include "psock.h"
|
| 24 |
|
|
#include "common/setup_after.h"
|
| 25 |
|
|
|
| 26 |
|
|
|
| 27 |
|
|
extern int psock_init(void)
|
| 28 |
|
|
{
|
| 29 |
|
|
WORD wVersionRequested;
|
| 30 |
|
|
WSADATA wsaData;
|
| 31 |
|
|
|
| 32 |
|
|
wVersionRequested = MAKEWORD(2, 2);
|
| 33 |
|
|
|
| 34 |
|
|
if (WSAStartup(wVersionRequested, &wsaData)!=0)
|
| 35 |
|
|
{
|
| 36 |
|
|
/* FIXME: Tell the user that we could not find a usable WinSock DLL. */
|
| 37 |
|
|
return -1;
|
| 38 |
|
|
}
|
| 39 |
|
|
|
| 40 |
|
|
return 0;
|
| 41 |
|
|
}
|
| 42 |
|
|
|
| 43 |
|
|
extern int psock_deinit(void)
|
| 44 |
|
|
{
|
| 45 |
|
|
|
| 46 |
|
|
if (WSACleanup()!=0)
|
| 47 |
|
|
{
|
| 48 |
|
|
return -1;
|
| 49 |
|
|
}
|
| 50 |
|
|
|
| 51 |
|
|
return 0;
|
| 52 |
|
|
}
|
| 53 |
|
|
|
| 54 |
|
|
extern int psock_ctl(int sd, int mode)
|
| 55 |
|
|
{
|
| 56 |
|
|
unsigned long nParam=1; /* u_long or DWORD or what? */
|
| 57 |
|
|
|
| 58 |
|
|
return ioctlsocket(sd,mode,&nParam);
|
| 59 |
|
|
}
|
| 60 |
|
|
|
| 61 |
|
|
#else
|
| 62 |
|
|
|
| 63 |
|
|
#ifdef HAVE_UNISTD_H
|
| 64 |
|
|
# include <unistd.h>
|
| 65 |
|
|
#endif
|
| 66 |
|
|
#ifdef HAVE_FCNTL_H
|
| 67 |
|
|
# include <fcntl.h>
|
| 68 |
|
|
#else
|
| 69 |
|
|
# ifdef HAVE_SYS_FILE_H
|
| 70 |
|
|
# include <sys/file.h>
|
| 71 |
|
|
# endif
|
| 72 |
|
|
#endif
|
| 73 |
|
|
#include "psock.h"
|
| 74 |
|
|
#include "common/setup_after.h"
|
| 75 |
|
|
|
| 76 |
|
|
|
| 77 |
|
|
extern int psock_ctl(int sd, long int mode)
|
| 78 |
|
|
{
|
| 79 |
|
|
long int oldmode;
|
| 80 |
|
|
|
| 81 |
|
|
if ((oldmode = fcntl(sd,F_GETFL))<0)
|
| 82 |
|
|
oldmode = 0;
|
| 83 |
|
|
oldmode |= mode;
|
| 84 |
|
|
return fcntl(sd,F_SETFL,mode);
|
| 85 |
|
|
}
|
| 86 |
|
|
|
| 87 |
|
|
#endif
|