Wed, 14 Oct 2020 00:40:50 -0500
remove wpurple_strerror
Remove the strerror and g_strerror replacements
Testing Done:
Compiled on linux and windows, verified no new errors on windows.
Reviewed at https://reviews.imfreedom.org/r/165/
| 3712 | 1 | /* |
| 15884 | 2 | * purple |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
3 | * |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
4 | * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com> |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
5 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
6 | * 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
|
7 | * 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
|
8 | * the Free Software Foundation; either version 2 of the License, or |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
9 | * (at your option) any later version. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
10 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
11 | * 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
|
12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
14 | * GNU General Public License for more details. |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
15 | * |
|
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
16 | * 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
|
17 | * along with this program; if not, write to the Free Software |
|
19859
71d37b57eff2
The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents:
18553
diff
changeset
|
18 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
|
5913
4d016c00bb36
[gaim-migrate @ 6345]
Herman Bloggs <herman@bluedigits.com>
parents:
5474
diff
changeset
|
19 | * |
| 3712 | 20 | */ |
|
35892
02bf3200b9cb
cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35855
diff
changeset
|
21 | |
|
02bf3200b9cb
cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35855
diff
changeset
|
22 | #include <config.h> |
|
02bf3200b9cb
cross-win32: make use of WIN32_LEAN_AND_MEAN define
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
35855
diff
changeset
|
23 | |
|
39373
47667f5c6696
libpurple: Include 'glib/gi18n-lib.h' instead of 'libintl.h'
Mike Ruprecht <cmaiku@gmail.com>
parents:
39020
diff
changeset
|
24 | #include <glib/gi18n-lib.h> |
|
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" |
|
38688
79304d0f6d43
Fix mingw32 compilation
Daniel Kamil Kozar <dkk089@gmail.com>
parents:
38259
diff
changeset
|
37 | #include "util.h" |
|
25333
182125d7b7fc
Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents:
24843
diff
changeset
|
38 | #include <glib/gstdio.h> |
|
38604
9ad76b0d9de7
win32/libc_interface: Add missing util.h include for purple_strequal()
Mike Ruprecht <cmaiku@gmail.com>
parents:
38358
diff
changeset
|
39 | #include "util.h" |
| 3712 | 40 | |
|
25333
182125d7b7fc
Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents:
24843
diff
changeset
|
41 | #ifndef S_ISDIR |
|
182125d7b7fc
Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents:
24843
diff
changeset
|
42 | # define S_ISDIR(m) (((m)&S_IFDIR)==S_IFDIR) |
|
182125d7b7fc
Fix from the QuteCom folks to compile with Glib < 2.8.5 with MSVC. Fixes #7761. Also some minor cleanup from me.
Daniel Atallah <datallah@pidgin.im>
parents:
24843
diff
changeset
|
43 | #endif |
|
21771
0df7285a6164
Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents:
21635
diff
changeset
|
44 | |
| 3712 | 45 | /* helpers */ |
| 15884 | 46 | static int wpurple_is_socket( int fd ) { |
| 3712 | 47 | int optval; |
| 29797 | 48 | int optlen = sizeof(int); |
| 3712 | 49 | |
| 50 | if( (getsockopt(fd, SOL_SOCKET, SO_TYPE, (void*)&optval, &optlen)) == SOCKET_ERROR ) { | |
| 51 | int error = WSAGetLastError(); | |
| 52 | if( error == WSAENOTSOCK ) | |
| 53 | return FALSE; | |
| 54 | else { | |
| 15884 | 55 | purple_debug(PURPLE_DEBUG_WARNING, "wpurple", "wpurple_is_socket: getsockopt returned error: %d\n", error); |
| 3712 | 56 | return FALSE; |
| 57 | } | |
| 58 | } | |
| 59 | return TRUE; | |
| 60 | } | |
| 61 | ||
| 62 | /* socket.h */ | |
| 15884 | 63 | int wpurple_socket (int namespace, int style, int protocol) { |
| 3712 | 64 | int ret; |
| 65 | ||
| 66 | ret = socket( namespace, style, protocol ); | |
| 67 | ||
|
35855
3e60f9385431
cross-win32: libpurple builds now
Tomasz Wasilczyk <twasilczyk@pidgin.im>
parents:
33884
diff
changeset
|
68 | if (ret == (int)INVALID_SOCKET) { |
| 3712 | 69 | errno = WSAGetLastError(); |
| 70 | return -1; | |
| 71 | } | |
| 72 | return ret; | |
| 73 | } | |
| 74 | ||
| 15884 | 75 | int wpurple_connect(int socket, struct sockaddr *addr, u_long length) { |
| 3712 | 76 | int ret; |
| 77 | ||
| 78 | ret = connect( socket, addr, length ); | |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
79 | |
| 3712 | 80 | if( ret == SOCKET_ERROR ) { |
| 81 | errno = WSAGetLastError(); | |
| 82 | if( errno == WSAEWOULDBLOCK ) | |
| 83 | errno = WSAEINPROGRESS; | |
| 84 | return -1; | |
| 85 | } | |
| 86 | return 0; | |
| 87 | } | |
| 88 | ||
| 15884 | 89 | int wpurple_getsockopt(int socket, int level, int optname, void *optval, socklen_t *optlenptr) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
90 | if(getsockopt(socket, level, optname, optval, optlenptr) == SOCKET_ERROR ) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
91 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
92 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
93 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
94 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
95 | } |
| 3712 | 96 | |
| 15884 | 97 | int wpurple_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
|
98 | if(setsockopt(socket, level, optname, optval, optlen) == SOCKET_ERROR ) { |
| 3712 | 99 | errno = WSAGetLastError(); |
| 100 | return -1; | |
| 101 | } | |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
102 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
103 | } |
| 3712 | 104 | |
| 15884 | 105 | int wpurple_getsockname(int socket, struct sockaddr *addr, socklen_t *lenptr) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
106 | if(getsockname(socket, addr, lenptr) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
107 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
108 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
109 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
110 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
111 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
112 | |
| 15884 | 113 | int wpurple_bind(int socket, struct sockaddr *addr, socklen_t length) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
114 | if(bind(socket, addr, length) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
115 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
116 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
117 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
118 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
119 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
120 | |
| 15884 | 121 | int wpurple_listen(int socket, unsigned int n) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
122 | if(listen(socket, n) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
123 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
124 | return -1; |
|
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 | return 0; |
| 3712 | 127 | } |
| 128 | ||
| 15884 | 129 | int wpurple_sendto(int socket, const void *buf, size_t len, int flags, const struct sockaddr *to, socklen_t tolen) { |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
130 | int ret; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
131 | if ((ret = sendto(socket, buf, len, flags, to, tolen) |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
132 | ) == SOCKET_ERROR) { |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
133 | errno = WSAGetLastError(); |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
134 | if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) |
|
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
135 | errno = EAGAIN; |
|
11431
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
136 | return -1; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
137 | } |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
138 | return ret; |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
139 | } |
|
60971f504319
[gaim-migrate @ 13668]
Daniel Atallah <datallah@pidgin.im>
parents:
11364
diff
changeset
|
140 | |
| 3712 | 141 | /* fcntl.h */ |
| 142 | /* This is not a full implementation of fcntl. Update as needed.. */ | |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
143 | int wpurple_fcntl(int socket, int command, ...) { |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
144 | |
| 3712 | 145 | switch( command ) { |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
146 | case F_GETFL: |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
147 | return 0; |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
148 | |
| 3712 | 149 | case F_SETFL: |
| 150 | { | |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
151 | va_list args; |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
152 | int val; |
| 3712 | 153 | int ret=0; |
| 154 | ||
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
155 | va_start(args, command); |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
156 | val = va_arg(args, int); |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
157 | va_end(args); |
|
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
158 | |
| 3712 | 159 | switch( val ) { |
| 160 | case O_NONBLOCK: | |
| 161 | { | |
| 162 | u_long imode=1; | |
| 163 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 164 | break; | |
| 165 | } | |
| 166 | case 0: | |
|
20239
ae122f419324
applied changes from 2762c6075c0dc52a96098c5478c5bf68cfd890a3
Luke Schierer <lschiere@pidgin.im>
parents:
19859
diff
changeset
|
167 | { |
| 3712 | 168 | u_long imode=0; |
| 169 | ret = ioctlsocket(socket, FIONBIO, &imode); | |
| 170 | break; | |
| 171 | } | |
| 172 | default: | |
| 173 | errno = EINVAL; | |
| 174 | return -1; | |
| 175 | }/*end switch*/ | |
| 176 | if( ret == SOCKET_ERROR ) { | |
| 177 | errno = WSAGetLastError(); | |
| 178 | return -1; | |
| 179 | } | |
| 180 | return 0; | |
| 181 | } | |
| 182 | default: | |
| 15884 | 183 | purple_debug(PURPLE_DEBUG_WARNING, "wpurple", "wpurple_fcntl: Unsupported command\n"); |
| 3712 | 184 | return -1; |
| 185 | }/*end switch*/ | |
| 186 | } | |
| 187 | ||
| 188 | /* sys/ioctl.h */ | |
| 15884 | 189 | int wpurple_ioctl(int fd, int command, void* val) { |
| 3712 | 190 | switch( command ) { |
| 191 | case FIONBIO: | |
| 192 | { | |
| 193 | if (ioctlsocket(fd, FIONBIO, (unsigned long *)val) == SOCKET_ERROR) { | |
| 194 | errno = WSAGetLastError(); | |
| 195 | return -1; | |
| 196 | } | |
| 197 | return 0; | |
| 198 | } | |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
199 | case SIOCGIFCONF: |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
200 | { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
201 | INTERFACE_INFO InterfaceList[20]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
202 | unsigned long nBytesReturned; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
203 | if (WSAIoctl(fd, SIO_GET_INTERFACE_LIST, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
204 | 0, 0, &InterfaceList, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
205 | sizeof(InterfaceList), &nBytesReturned, |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
206 | 0, 0) == SOCKET_ERROR) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
207 | errno = WSAGetLastError(); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
208 | return -1; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
209 | } else { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
210 | int i; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
211 | struct ifconf *ifc = val; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
212 | char *tmp = ifc->ifc_buf; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
213 | int nNumInterfaces = |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
214 | nBytesReturned / sizeof(INTERFACE_INFO); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
215 | for (i = 0; i < nNumInterfaces; i++) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
216 | INTERFACE_INFO ii = InterfaceList[i]; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
217 | struct ifreq *ifr = (struct ifreq *) tmp; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
218 | struct sockaddr_in *sa = (struct sockaddr_in *) &ifr->ifr_addr; |
|
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 | sa->sin_family = ii.iiAddress.AddressIn.sin_family; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
221 | sa->sin_port = ii.iiAddress.AddressIn.sin_port; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
222 | 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
|
223 | tmp += sizeof(struct ifreq); |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
224 | |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
225 | /* Make sure that we can fit in the original buffer */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
226 | if (tmp >= (ifc->ifc_buf + ifc->ifc_len + sizeof(struct ifreq))) { |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
227 | break; |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
228 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
229 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
230 | /* Replace the length with the actually used length */ |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
231 | ifc->ifc_len = ifc->ifc_len - (ifc->ifc_buf - tmp); |
|
12488
72878a4bf35a
[gaim-migrate @ 14800]
Daniel Atallah <datallah@pidgin.im>
parents:
11543
diff
changeset
|
232 | return 0; |
|
11364
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
233 | } |
|
d754cf40ec4b
[gaim-migrate @ 13588]
Daniel Atallah <datallah@pidgin.im>
parents:
10601
diff
changeset
|
234 | } |
| 3712 | 235 | default: |
| 236 | errno = EINVAL; | |
| 237 | return -1; | |
| 238 | }/*end switch*/ | |
| 239 | } | |
| 240 | ||
| 241 | /* arpa/inet.h */ | |
| 15884 | 242 | int wpurple_inet_aton(const char *name, struct in_addr *addr) { |
| 3712 | 243 | if((addr->s_addr = inet_addr(name)) == INADDR_NONE) |
| 244 | return 0; | |
| 245 | else | |
| 246 | return 1; | |
| 247 | } | |
| 248 | ||
|
14974
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
249 | /* Thanks to GNU wget for this inet_ntop() implementation */ |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
250 | const char * |
| 15884 | 251 | wpurple_inet_ntop (int af, const void *src, char *dst, socklen_t cnt) |
|
14974
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
252 | { |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
253 | /* struct sockaddr can't accomodate struct sockaddr_in6. */ |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
254 | union { |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
255 | struct sockaddr_in6 sin6; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
256 | struct sockaddr_in sin; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
257 | } sa; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
258 | DWORD dstlen = cnt; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
259 | size_t srcsize; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
260 | |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
261 | ZeroMemory(&sa, sizeof(sa)); |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
262 | switch (af) |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
263 | { |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
264 | case AF_INET: |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
265 | sa.sin.sin_family = AF_INET; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
266 | sa.sin.sin_addr = *(struct in_addr *) src; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
267 | srcsize = sizeof (sa.sin); |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
268 | break; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
269 | case AF_INET6: |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
270 | sa.sin6.sin6_family = AF_INET6; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
271 | sa.sin6.sin6_addr = *(struct in6_addr *) src; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
272 | srcsize = sizeof (sa.sin6); |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
273 | break; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
274 | default: |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
275 | abort (); |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
276 | } |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
277 | |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
278 | if (WSAAddressToString ((struct sockaddr *) &sa, srcsize, NULL, dst, &dstlen) != 0) |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
279 | { |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
280 | errno = WSAGetLastError(); |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
281 | return NULL; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
282 | } |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
283 | return (const char *) dst; |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
284 | } |
|
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
285 | |
|
32069
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
286 | int |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
287 | wpurple_inet_pton(int af, const char *src, void *dst) |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
288 | { |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
289 | /* struct sockaddr can't accomodate struct sockaddr_in6. */ |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
290 | union { |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
291 | struct sockaddr_in6 sin6; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
292 | struct sockaddr_in sin; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
293 | } sa; |
|
33884
3fd1628aa718
Fixing warnings (win32, glib, others)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32744
diff
changeset
|
294 | int srcsize; |
|
32069
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
295 | |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
296 | switch(af) |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
297 | { |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
298 | case AF_INET: |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
299 | sa.sin.sin_family = AF_INET; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
300 | srcsize = sizeof (sa.sin); |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
301 | break; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
302 | case AF_INET6: |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
303 | sa.sin6.sin6_family = AF_INET6; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
304 | srcsize = sizeof (sa.sin6); |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
305 | break; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
306 | default: |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
307 | errno = WSAEPFNOSUPPORT; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
308 | return -1; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
309 | } |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
310 | |
|
33884
3fd1628aa718
Fixing warnings (win32, glib, others)
Tomasz Wasilczyk <tomkiewicz@cpw.pidgin.im>
parents:
32744
diff
changeset
|
311 | if (WSAStringToAddress((LPTSTR)src, af, NULL, (struct sockaddr *) &sa, &srcsize) != 0) |
|
32069
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
312 | { |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
313 | errno = WSAGetLastError(); |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
314 | return -1; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
315 | } |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
316 | |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
317 | switch(af) |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
318 | { |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
319 | case AF_INET: |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
320 | memcpy(dst, &sa.sin.sin_addr, sizeof(sa.sin.sin_addr)); |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
321 | break; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
322 | case AF_INET6: |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
323 | memcpy(dst, &sa.sin6.sin6_addr, sizeof(sa.sin6.sin6_addr)); |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
324 | break; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
325 | } |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
326 | |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
327 | return 1; |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
328 | } |
|
fc06dd6b7c3f
Fix the compilation of the Bonjour prpl on Windows.
Eion Robb <eion@robbmob.com>
parents:
31957
diff
changeset
|
329 | |
|
14974
8180f0f2e20c
[gaim-migrate @ 17684]
Daniel Atallah <datallah@pidgin.im>
parents:
14286
diff
changeset
|
330 | |
| 3712 | 331 | /* netdb.h */ |
| 15884 | 332 | struct hostent* wpurple_gethostbyname(const char *name) { |
| 3712 | 333 | struct hostent *hp; |
| 334 | ||
| 335 | if((hp = gethostbyname(name)) == NULL) { | |
| 336 | errno = WSAGetLastError(); | |
| 337 | return NULL; | |
| 338 | } | |
| 339 | return hp; | |
| 340 | } | |
| 341 | ||
| 342 | /* unistd.h */ | |
| 343 | ||
| 344 | /* | |
| 345 | * We need to figure out whether fd is a file or socket handle. | |
| 346 | */ | |
| 15884 | 347 | int wpurple_read(int fd, void *buf, unsigned int size) { |
| 3712 | 348 | int ret; |
| 349 | ||
|
24843
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
350 | if (fd < 0) { |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
351 | errno = EBADF; |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
352 | g_return_val_if_reached(-1); |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
353 | } |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
354 | |
| 15884 | 355 | if(wpurple_is_socket(fd)) { |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
356 | if((ret = recv(fd, buf, size, 0)) == SOCKET_ERROR) { |
| 3712 | 357 | errno = WSAGetLastError(); |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
358 | if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
359 | errno = EAGAIN; |
| 3712 | 360 | return -1; |
| 361 | } | |
| 362 | else { | |
| 363 | /* success reading socket */ | |
| 364 | return ret; | |
| 365 | } | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
366 | } else { |
| 3712 | 367 | /* fd is not a socket handle.. pass it off to read */ |
|
22871
a5ba9f9d340a
Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents:
22641
diff
changeset
|
368 | return _read(fd, buf, size); |
| 3712 | 369 | } |
| 370 | } | |
| 371 | ||
| 15884 | 372 | int wpurple_send(int fd, const void *buf, unsigned int size, int flags) { |
| 3712 | 373 | int ret; |
| 374 | ||
|
13780
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
375 | ret = send(fd, buf, size, flags); |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
376 | |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
377 | if (ret == SOCKET_ERROR) { |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
378 | errno = WSAGetLastError(); |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
379 | if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) |
|
13780
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
380 | errno = EAGAIN; |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
381 | return -1; |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
382 | } |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
383 | return ret; |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
384 | } |
|
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
385 | |
| 15884 | 386 | int wpurple_write(int fd, const void *buf, unsigned int size) { |
|
13780
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
387 | |
|
24843
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
388 | if (fd < 0) { |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
389 | errno = EBADF; |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
390 | g_return_val_if_reached(-1); |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
391 | } |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
392 | |
| 15884 | 393 | if(wpurple_is_socket(fd)) |
| 394 | return wpurple_send(fd, buf, size, 0); | |
|
13780
f642a0729daa
[gaim-migrate @ 16190]
Daniel Atallah <datallah@pidgin.im>
parents:
13371
diff
changeset
|
395 | else |
|
22871
a5ba9f9d340a
Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents:
22641
diff
changeset
|
396 | return _write(fd, buf, size); |
| 3712 | 397 | } |
| 398 | ||
| 15884 | 399 | int wpurple_recv(int fd, void *buf, size_t len, int flags) { |
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
400 | int ret; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
401 | |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
402 | if((ret = recv(fd, buf, len, flags)) == SOCKET_ERROR) { |
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
403 | errno = WSAGetLastError(); |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
404 | if(errno == WSAEWOULDBLOCK || errno == WSAEINPROGRESS) |
|
13201
8c224ef70efa
[gaim-migrate @ 15563]
Daniel Atallah <datallah@pidgin.im>
parents:
12749
diff
changeset
|
405 | errno = EAGAIN; |
|
12749
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
406 | return -1; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
407 | } else { |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
408 | return ret; |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
409 | } |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
410 | } |
|
704b51d5007a
[gaim-migrate @ 15096]
Daniel Atallah <datallah@pidgin.im>
parents:
12488
diff
changeset
|
411 | |
| 15884 | 412 | int wpurple_close(int fd) { |
| 3712 | 413 | int ret; |
| 414 | ||
|
24843
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
415 | if (fd < 0) { |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
416 | errno = EBADF; |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
417 | g_return_val_if_reached(-1); |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
418 | } |
|
ab68c6d3c247
(Slightly modified) patch from fqueze to avoid exceptions with newer win32 CRTs.
Daniel Atallah <datallah@pidgin.im>
parents:
23883
diff
changeset
|
419 | |
| 15884 | 420 | if( wpurple_is_socket(fd) ) { |
| 3712 | 421 | if( (ret = closesocket(fd)) == SOCKET_ERROR ) { |
| 422 | errno = WSAGetLastError(); | |
| 423 | return -1; | |
| 424 | } | |
| 425 | else | |
| 426 | return 0; | |
| 427 | } | |
| 428 | else | |
|
22871
a5ba9f9d340a
Use g_snprintf() instead of snprintf(), which isn't really available on
Daniel Atallah <datallah@pidgin.im>
parents:
22641
diff
changeset
|
429 | return _close(fd); |
| 3712 | 430 | } |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
431 | |
| 15884 | 432 | int wpurple_gethostname(char *name, size_t size) { |
|
8244
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
433 | if(gethostname(name, size) == SOCKET_ERROR) { |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
434 | errno = WSAGetLastError(); |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
435 | return -1; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
436 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
437 | return 0; |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
438 | } |
|
014ff38feea9
[gaim-migrate @ 8967]
Herman Bloggs <herman@bluedigits.com>
parents:
6425
diff
changeset
|
439 | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
440 | /* sys/time.h */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
441 | |
| 15884 | 442 | int wpurple_gettimeofday(struct timeval *p, struct timezone *z) { |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
443 | int res = 0; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
444 | struct _timeb timebuffer; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
445 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
446 | if (z != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
447 | _tzset(); |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
448 | z->tz_minuteswest = _timezone/60; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
449 | z->tz_dsttime = _daylight; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
450 | } |
|
17666
9c32c365b852
Pretend that WSAEINPROGRESS is EAGAIN (for our purposes, I think they are equivalent). I think this might help #485. References #485.
Daniel Atallah <datallah@pidgin.im>
parents:
15884
diff
changeset
|
451 | |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
452 | if (p != 0) { |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
453 | _ftime(&timebuffer); |
|
21771
0df7285a6164
Better error messages for common Winsock errors. This was Kevin's wonderful idea.
Daniel Atallah <datallah@pidgin.im>
parents:
21635
diff
changeset
|
454 | p->tv_sec = timebuffer.time; /* seconds since 1-1-1970 */ |
|
3777
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
455 | p->tv_usec = timebuffer.millitm*1000; /* microseconds */ |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
456 | } |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
457 | |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
458 | return res; |
|
a3f8adc4c3e0
[gaim-migrate @ 3917]
Herman Bloggs <herman@bluedigits.com>
parents:
3712
diff
changeset
|
459 | } |