Tue, 30 Aug 2005 00:32:32 +0000
[gaim-migrate @ 13588]
Make the stun stuff compile on win32. This is largely untested since this code will not currently ever be called, but it compiles. This is based on a patch from François Gagné."
| 3712 | 1 | /* |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
2 | * gaim |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
3 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
4 | * File: libc_interface.c |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
5 | * Date: October 14, 2002 |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
6 | * Description: libc interface for Windows api |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
7 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
8 | * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
9 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
10 | * This program is free software; you can redistribute it and/or modify |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
11 | * it under the terms of the GNU General Public License as published by |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
12 | * the Free Software Foundation; either version 2 of the License, or |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
13 | * (at your option) any later version. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
14 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
15 | * This program is distributed in the hope that it will be useful, |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
18 | * GNU General Public License for more details. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
19 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
20 | * You should have received a copy of the GNU General Public License |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
21 | * along with this program; if not, write to the Free Software |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
23 | * |
| 3712 | 24 | */ |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
25 | #include <winsock2.h> |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
26 | #include <ws2tcpip.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
27 | #include <io.h> |
| 3712 | 28 | #include <stdlib.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
29 | #include <stdio.h> |
| 3712 | 30 | #include <errno.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
31 | #include <sys/timeb.h> |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
32 | #include <sys/stat.h> |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
33 | #include <time.h> |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
34 | #include <glib.h> |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
35 | #include "debug.h" |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
36 | #include "libc_internal.h" |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
37 | #if GLIB_CHECK_VERSION(2,6,0) |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
38 | # include <glib/gstdio.h> |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
39 | #else |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
40 | #define g_remove remove |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
41 | #define g_rename rename |
|
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
42 | #define g_stat stat |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
43 | #endif |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
44 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
45 | * PROTOS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
46 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
47 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
48 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
49 | * LOCALS |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
50 | */ |
| 3712 | 51 | |
| 52 | static char errbuf[1024]; | |
| 53 | ||
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
54 | /* |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
55 | * CODE |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
56 | */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
57 | |
| 3712 | 58 | /* helpers */ |
| 59 | static int wgaim_is_socket( int fd ) { | |
| 60 | int optval; | |
| 61 | unsigned int optlen = sizeof(int); | |
| 62 | ||
| 63 | if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { | |
| 64 | int error = WSAGetLastError(); | |
| 65 | if( error == WSAENOTSOCK ) | |
| 66 | return FALSE; | |
| 67 | else { | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
68 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_is_socket: getsockopt returned error: %d\n", error); |
| 3712 | 69 | return FALSE; |
| 70 | } | |
| 71 | } | |
| 72 | return TRUE; | |
| 73 | } | |
| 74 | ||
| 75 | /* socket.h */ | |
| 76 | int wgaim_socket (int namespace, int style, int protocol) { | |
| 77 | int ret; | |
| 78 | ||
| 79 | ret = socket( namespace, style, protocol ); | |
| 80 | ||
| 81 | if( ret == INVALID_SOCKET ) { | |
| 82 | errno = WSAGetLastError(); | |
| 83 | return -1; | |
| 84 | } | |
| 85 | return ret; | |
| 86 | } | |
| 87 | ||
| 88 | int wgaim_connect(int socket, struct sockaddr *addr, u_long length) { | |
| 89 | int ret; | |
| 90 | ||
| 91 | ret = connect( socket, addr, length ); | |
| 92 | ||
| 93 | if( ret == SOCKET_ERROR ) { | |
| 94 | errno = WSAGetLastError(); | |
| 95 | if( errno == WSAEWOULDBLOCK ) | |
| 96 | errno = WSAEINPROGRESS; | |
| 97 | return -1; | |
| 98 | } | |
| 99 | return 0; | |
| 100 | } | |
| 101 | ||
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
102 | int wgaim_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlenptr) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
103 | if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
104 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
105 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
106 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
107 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
108 | } |
| 3712 | 109 | |
| 9611 | 110 | int wgaim_setsockopt(int socket, int level, int optname, const void *optval, socklen_t optlen) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
111 | if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) { |
| 3712 | 112 | errno = WSAGetLastError(); |
| 113 | return -1; | |
| 114 | } | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
115 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
116 | } |
| 3712 | 117 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
118 | int wgaim_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
119 | if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
120 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
121 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
122 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
123 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
124 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
125 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
126 | int wgaim_bind(int socket, struct sockaddr *addr, socklen_t length) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
127 | if(bind(socket, addr, length) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
128 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
129 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
130 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
131 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
132 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
133 | |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
134 | int wgaim_listen(int socket, unsigned int n) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
135 | if(listen(socket, n) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
136 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
137 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
138 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
139 | return 0; |
| 3712 | 140 | } |
| 141 | ||
| 142 | /* fcntl.h */ | |
| 143 | /* This is not a full implementation of fcntl. Update as needed.. */ | |
| 144 | int wgaim_fcntl(int socket, int command, int val) { | |
| 145 | switch( command ) { | |
| 146 | case F_SETFL: | |
| 147 | { | |
| 148 | int ret=0; | |
| 149 | ||
| 150 | switch( val ) { | |
| 151 | case O_NONBLOCK: | |
| 152 | { | |
| 153 | u_long imode=1; | |
| 154 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 155 | break; | |
| 156 | } | |
| 157 | case 0: | |
| 158 | { | |
| 159 | u_long imode=0; | |
| 160 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 161 | break; | |
| 162 | } | |
| 163 | default: | |
| 164 | errno = EINVAL; | |
| 165 | return -1; | |
| 166 | }/*end switch*/ | |
| 167 | if( ret == SOCKET_ERROR ) { | |
| 168 | errno = WSAGetLastError(); | |
| 169 | return -1; | |
| 170 | } | |
| 171 | return 0; | |
| 172 | } | |
| 173 | default: | |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
174 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_fcntl: Unsupported command\n"); |
| 3712 | 175 | return -1; |
| 176 | }/*end switch*/ | |
| 177 | } | |
| 178 | ||
| 179 | /* sys/ioctl.h */ | |
| 180 | int wgaim_ioctl(int fd, int command, void* val) { | |
| 181 | switch( command ) { | |
| 182 | case FIONBIO: | |
| 183 | { | |
| 184 | if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { | |
| 185 | errno = WSAGetLastError(); | |
| 186 | return -1; | |
| 187 | } | |
| 188 | return 0; | |
| 189 | } | |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
190 | case SIOCGIFCONF: |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
191 | { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
192 | INTERFACE_INFO InterfaceList[20]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
193 | unsigned long nBytesReturned; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
194 | if (WSAIoctl(fd, SIO_GET_INTERFACE_LIST, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
195 | 0, 0, &InterfaceList, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
196 | sizeof(InterfaceList), &nBytesReturned, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
197 | 0, 0) == SOCKET_ERROR) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
198 | errno = WSAGetLastError(); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
199 | return -1; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
200 | } else { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
201 | int i; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
202 | struct ifconf *ifc = val; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
203 | char *tmp = ifc->ifc_buf; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
204 | int nNumInterfaces = |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
205 | nBytesReturned / sizeof(INTERFACE_INFO); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
206 | for (i = 0; i < nNumInterfaces; i++) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
207 | INTERFACE_INFO ii = InterfaceList[i]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
208 | struct ifreq *ifr = (struct ifreq *) tmp; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
209 | struct sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
210 | |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
211 | sa->sin_family = ii.iiAddress.AddressIn.sin_family; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
212 | sa->sin_port = ii.iiAddress.AddressIn.sin_port; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
213 | sa->sin_addr.s_addr = ii.iiAddress.AddressIn.sin_addr.s_addr; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
214 | tmp += sizeof(struct ifreq); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
215 | |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
216 | /* Make sure that we can fit in the original buffer */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
217 | if (tmp >= (ifc->ifc_buf + ifc->ifc_len + sizeof(struct ifreq))) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
218 | break; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
219 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
220 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
221 | /* Replace the length with the actually used length */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
222 | ifc->ifc_len = ifc->ifc_len - (ifc->ifc_buf - tmp); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
223 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
224 | } |
| 3712 | 225 | default: |
| 226 | errno = EINVAL; | |
| 227 | return -1; | |
| 228 | }/*end switch*/ | |
| 229 | } | |
| 230 | ||
| 231 | /* arpa/inet.h */ | |
| 232 | int wgaim_inet_aton(const char *name, struct in_addr *addr) { | |
| 233 | if((addr->s_addr = inet_addr(name)) == INADDR_NONE) | |
| 234 | return 0; | |
| 235 | else | |
| 236 | return 1; | |
| 237 | } | |
| 238 | ||
| 239 | /* netdb.h */ | |
| 240 | struct hostent* wgaim_gethostbyname(const char *name) { | |
| 241 | struct hostent *hp; | |
| 242 | ||
| 243 | if((hp = gethostbyname(name)) == NULL) { | |
| 244 | errno = WSAGetLastError(); | |
| 245 | return NULL; | |
| 246 | } | |
| 247 | return hp; | |
| 248 | } | |
| 249 | ||
| 250 | /* string.h */ | |
| 251 | char* wgaim_strerror( int errornum ) { | |
| 252 | if( errornum > WSABASEERR ) { | |
| 253 | sprintf( errbuf, "Windows socket error #%d", errornum ); | |
| 254 | return errbuf; | |
| 255 | } | |
| 256 | else | |
| 257 | return strerror( errornum ); | |
| 258 | } | |
| 259 | ||
| 260 | /* unistd.h */ | |
| 261 | ||
| 262 | /* | |
| 263 | * We need to figure out whether fd is a file or socket handle. | |
| 264 | */ | |
| 265 | int wgaim_read(int fd, void *buf, unsigned int size) { | |
| 266 | int ret; | |
| 267 | ||
| 268 | if( wgaim_is_socket(fd) ) { | |
| 269 | if( (ret = recv(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 270 | errno = WSAGetLastError(); | |
| 271 | return -1; | |
| 272 | } | |
| 273 | else if( ret == 0 ) { | |
| 274 | /* connection has been gracefully closed */ | |
| 275 | errno = WSAENOTCONN; | |
| 276 | return -1; | |
| 277 | } | |
| 278 | else { | |
| 279 | /* success reading socket */ | |
| 280 | return ret; | |
| 281 | } | |
| 282 | } | |
| 283 | else { | |
| 284 | /* fd is not a socket handle.. pass it off to read */ | |
| 285 | return read(fd, buf, size); | |
| 286 | } | |
| 287 | } | |
| 288 | ||
| 289 | int wgaim_write(int fd, const void *buf, unsigned int size) { | |
| 290 | int ret; | |
| 291 | ||
| 292 | if( wgaim_is_socket(fd) ) { | |
| 293 | if( (ret = send(fd, buf, size, 0)) == SOCKET_ERROR ) { | |
| 294 | errno = WSAGetLastError(); | |
| 295 | return -1; | |
| 296 | } | |
| 297 | else { | |
| 298 | /* success */ | |
| 299 | return ret; | |
| 300 | } | |
| 301 | ||
| 302 | } | |
| 303 | else | |
| 304 | return write(fd, buf, size); | |
| 305 | } | |
| 306 | ||
| 307 | int wgaim_close(int fd) { | |
| 308 | int ret; | |
| 309 | ||
| 310 | if( wgaim_is_socket(fd) ) { | |
| 311 | if( (ret = closesocket(fd)) == SOCKET_ERROR ) { | |
| 312 | errno = WSAGetLastError(); | |
| 313 | return -1; | |
| 314 | } | |
| 315 | else | |
| 316 | return 0; | |
| 317 | } | |
| 318 | else | |
| 319 | return close(fd); | |
| 320 | } | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
321 | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
322 | int wgaim_gethostname(char *name, size_t size) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
323 | if(gethostname(name, size) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
324 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
325 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
326 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
327 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
328 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
329 | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
330 | /* sys/time.h */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
331 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
332 | int wgaim_gettimeofday(struct timeval *p, struct timezone *z) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
333 | int res = 0; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
334 | struct _timeb timebuffer; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
335 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
336 | if (z != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
337 | _tzset(); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
338 | z->tz_minuteswest = _timezone/60; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
339 | z->tz_dsttime = _daylight; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
340 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
341 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
342 | if (p != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
343 | _ftime(&timebuffer); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
344 | p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
345 | p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
346 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
347 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
348 | return res; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
349 | } |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
350 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
351 | /* stdio.h */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
352 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
353 | int wgaim_rename (const char *oldname, const char *newname) { |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
354 | struct stat oldstat, newstat; |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
355 | |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
356 | if(g_stat(oldname, &oldstat) == 0) { |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
357 | /* newname exists */ |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
358 | if(g_stat(newname, &newstat) == 0) { |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
359 | /* oldname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
360 | if(_S_ISDIR(oldstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
361 | if(!_S_ISDIR(newstat.st_mode)) { |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
362 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
363 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
364 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
365 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
366 | /* This is not quite right.. If newname is empty and |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
367 | is not a sub dir of oldname, newname should be |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
368 | deleted and oldname should be renamed. |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
369 | */ |
|
6425
3e86c949c98a
[gaim-migrate @ 6933]
Herman Bloggs <herman@bluedigits.com>
parents:
5913
diff
changeset
|
370 | gaim_debug(GAIM_DEBUG_WARNING, "wgaim", "wgaim_rename does not behave here as it should\n"); |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
371 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
372 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
373 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
374 | /* oldname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
375 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
376 | /* newname is a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
377 | if(_S_ISDIR(newstat.st_mode)) { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
378 | errno = EISDIR; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
379 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
380 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
381 | /* newname is not a dir */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
382 | else { |
|
10589
4e10236e06d4
[gaim-migrate @ 11994]
Daniel Atallah <datallah@pidgin.im>
parents:
9611
diff
changeset
|
383 | g_remove(newname); |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
384 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
385 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
386 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
387 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
388 | /* newname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
389 | else |
|
10601
84245a6eba0e
[gaim-migrate @ 12028]
Daniel Atallah <datallah@pidgin.im>
parents:
10589
diff
changeset
|
390 | return g_rename(oldname, newname); |
|
4905
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
391 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
392 | else { |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
393 | /* oldname doesn't exist */ |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
394 | errno = ENOENT; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
395 | return -1; |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
396 | } |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
397 | |
|
1464e05926f0
[gaim-migrate @ 5239]
Herman Bloggs <herman@bluedigits.com>
parents:
4193
diff
changeset
|
398 | } |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
399 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
400 | /* time.h */ |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
401 | |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
402 | struct tm * wgaim_localtime_r (const time_t *time, struct tm *resultp) { |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
403 | struct tm* tmptm; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
404 | |
|
5474
eec4dad3e035
[gaim-migrate @ 5868]
Herman Bloggs <herman@bluedigits.com>
parents:
5113
diff
changeset
|
405 | if(!time) |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
406 | return NULL; |
|
5113
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
407 | tmptm = localtime(time); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
408 | if(resultp && tmptm) |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
409 | return memcpy(resultp, tmptm, sizeof(struct tm)); |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
410 | else |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
411 | return NULL; |
|
8e545faf3d80
[gaim-migrate @ 5476]
Herman Bloggs <herman@bluedigits.com>
parents:
5084
diff
changeset
|
412 | } |