13
13
* Library General Public License for more details.
15
15
* You should have received a copy of the GNU Library General Public
16
* License along with this library; if not, write to the
16
* License along with this library; if not, write to the
17
17
* Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18
18
* Boston, MA 02111-1307, USA.
29
29
* Create an internet address from a sockaddr struct. WARNING: This
30
30
* may go away or be hidden in a future version.
32
* Returns: a new InetAddr, or NULL if there was a failure.
32
* Returns: a new InetAddr, or NULL if there was a failure.
36
36
gnet_private_inetaddr_sockaddr_new(const struct sockaddr sa)
38
38
GInetAddr* ia = g_new0(GInetAddr, 1);
71
71
* gnet_udp_socket_get_MTU:
72
72
* @us: GUdpSocket to get MTU from.
74
* Get the MTU for outgoing packets.
74
* Get the MTU for outgoing packets.
76
76
* Returns: MTU; -1 if unknown.
84
84
/* FIX: Not everyone has ethernet, right? */
85
85
strncpy (ifr.ifr_name, "eth0", sizeof (ifr.ifr_name));
86
if (!ioctl(us->sockfd, SIOCGIFMTU, &ifr))
86
if (!ioctl(us->sockfd, SIOCGIFMTU, &ifr))
87
87
return ifr.ifr_mtu;
136
136
code were fixed so only a few gnet functions still use this method.
138
138
I believe I have taken care of the multi-threaded issues by using
143
143
#ifdef GNET_WIN32
145
145
WNDCLASSEX gnetWndClass;
147
147
guint gnet_io_watch_ID;
148
148
GIOChannel *gnet_iochannel;
150
150
GHashTable *gnet_hash;
152
152
HANDLE gnet_hostent_Mutex;
156
156
gnet_MainCallBack(GIOChannel *iochannel, GIOCondition condition, void *nodata)
166
166
/*Take the msg off the message queue */
167
i = PeekMessage (&msg, gnet_hWnd, 0, 0, PM_REMOVE);
167
i = PeekMessage (&msg, gnet_hWnd, 0, 0, PM_REMOVE);
169
169
return 1; /* you have a buggy version of glib that is calling this func when it shouldn't*/
176
176
data = g_hash_table_lookup(gnet_hash, (gpointer)msg.wParam);
177
177
g_hash_table_remove(gnet_hash, (gpointer)msg.wParam);
178
178
ReleaseMutex(gnet_Mutex);
180
180
IAstate = (GInetAddrAsyncState*) data;
181
181
IAstate->errorcode = WSAGETASYNCERROR(msg.lParam); /* NULL if OK */
195
195
IARstate = (GInetAddrReverseAsyncState*) data;
196
196
IARstate->errorcode = WSAGETASYNCERROR(msg.lParam); /* NULL if OK */
198
198
/* Now call the callback function */
199
199
gnet_inetaddr_get_name_async_cb(NULL, G_IO_IN, (gpointer)IARstate);
210
210
UINT uMsg, /* message identifier */
211
211
WPARAM wParam, /* first message parameter */
212
212
LPARAM lParam) /* second message parameter */
218
218
/* Initialize the window. */
222
/* Paint the window's client area. */
226
/* Set the size and position of the window. */
222
/* Paint the window's client area. */
226
/* Set the size and position of the window. */
230
230
/* Clean up window-specific data objects. */
234
Process other messages.
238
return DefWindowProc(hwnd, uMsg, wParam, lParam);
234
Process other messages.
238
return DefWindowProc(hwnd, uMsg, wParam, lParam);
245
245
DllMain(HINSTANCE hinstDLL, /* handle to DLL module */
246
246
DWORD fdwReason, /* reason for calling functionm */
247
247
LPVOID lpvReserved /* reserved */)
252
252
case DLL_PROCESS_ATTACH:
253
253
/* The DLL is being mapped into process's address space */
256
256
WORD wVersionRequested;
260
260
wVersionRequested = MAKEWORD( 2, 0 );
262
262
err = WSAStartup( wVersionRequested, &wsaData );
265
265
/* Tell the user that we could not find a usable */
266
266
/* WinSock DLL. */
270
270
/* Confirm that the WinSock DLL supports 2.0.*/
271
271
/* Note that if the DLL supports versions greater */
272
272
/* than 2.0 in addition to 2.0, it will still return */
273
273
/* 2.0 in wVersion since that is the version we */
276
276
if ( LOBYTE( wsaData.wVersion ) != 2 ||
277
277
HIBYTE( wsaData.wVersion ) != 0 ) {
278
278
/* Tell the user that we could not find a usable */
279
279
/* WinSock DLL. */
284
284
/* The WinSock DLL is acceptable. Proceed. */
286
286
/* Setup and register a windows class that we use for our GIOchannel */
287
gnetWndClass.cbSize = sizeof(WNDCLASSEX);
288
gnetWndClass.style = CS_SAVEBITS; /* doesn't matter, need something? */
289
gnetWndClass.lpfnWndProc = (WNDPROC) GnetWndProc;
290
gnetWndClass.cbClsExtra = 0;
291
gnetWndClass.cbWndExtra = 0;
292
gnetWndClass.hInstance = hinstDLL;
293
gnetWndClass.hIcon = NULL;
294
gnetWndClass.hCursor = NULL;
295
gnetWndClass.hbrBackground = NULL;
296
gnetWndClass.lpszMenuName = NULL;
297
gnetWndClass.lpszClassName = "Gnet";
298
gnetWndClass.hIconSm = NULL;
287
gnetWndClass.cbSize = sizeof(WNDCLASSEX);
288
gnetWndClass.style = CS_SAVEBITS; /* doesn't matter, need something? */
289
gnetWndClass.lpfnWndProc = (WNDPROC) GnetWndProc;
290
gnetWndClass.cbClsExtra = 0;
291
gnetWndClass.cbWndExtra = 0;
292
gnetWndClass.hInstance = hinstDLL;
293
gnetWndClass.hIcon = NULL;
294
gnetWndClass.hCursor = NULL;
295
gnetWndClass.hbrBackground = NULL;
296
gnetWndClass.lpszMenuName = NULL;
297
gnetWndClass.lpszClassName = "Gnet";
298
gnetWndClass.hIconSm = NULL;
300
300
if (!RegisterClassEx(&gnetWndClass))
305
305
gnet_hWnd = CreateWindowEx
327
327
/* Add a watch */
328
328
gnet_io_watch_ID = g_io_add_watch(gnet_iochannel,
329
329
(GIOCondition)(G_IO_IN|G_IO_ERR|G_IO_HUP|G_IO_NVAL),
333
gnet_hash = g_hash_table_new(NULL, NULL);
333
gnet_hash = g_hash_table_new(NULL, NULL);
335
gnet_Mutex = CreateMutex(
335
gnet_Mutex = CreateMutex(
336
336
NULL, /* no security attributes */
337
337
FALSE, /* initially not owned */
338
338
"gnet_Mutex"); /* name of mutex */
340
if (gnet_Mutex == NULL)
340
if (gnet_Mutex == NULL)
345
gnet_hostent_Mutex = CreateMutex(
345
gnet_hostent_Mutex = CreateMutex(
346
346
NULL, /* no security attributes */
347
347
FALSE, /* initially not owned */
348
348
"gnet_hostent_Mutex"); /* name of mutex */
350
if (gnet_hostent_Mutex == NULL)
350
if (gnet_hostent_Mutex == NULL)