nexmon – Blame information for rev 1

Subversion Repositories:
Rev:
Rev Author Line No. Line
1 office 1 /* -*- mode: C; c-file-style: "gnu"; indent-tabs-mode: nil; -*- */
2  
3 /* GIO - GLib Input, Output and Streaming Library
4 *
5 * Copyright (C) 2011 Red Hat, Inc.
6 *
7 * This library is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2 of the License, or (at your option) any later version.
11 *
12 * This library is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General
18 * Public License along with this library; if not, see <http://www.gnu.org/licenses/>.
19 */
20  
21 #include "config.h"
22  
23 #include "gnetworking.h"
24  
25 #ifdef G_OS_WIN32
26 /* For Windows XP run-time compatibility */
27 #include "gwin32networking.h"
28  
29 GWin32WinsockFuncs ws2funcs = {0};
30 #endif
31  
32 /**
33 * SECTION:gnetworking
34 * @title: gnetworking.h
35 * @short_description: System networking includes
36 * @include: gio/gnetworking.h
37 *
38 * The `<gio/gnetworking.h>` header can be included to get
39 * various low-level networking-related system headers, automatically
40 * taking care of certain portability issues for you.
41 *
42 * This can be used, for example, if you want to call setsockopt()
43 * on a #GSocket.
44 *
45 * Note that while WinSock has many of the same APIs as the
46 * traditional UNIX socket API, most of them behave at least slightly
47 * differently (particularly with respect to error handling). If you
48 * want your code to work under both UNIX and Windows, you will need
49 * to take these differences into account.
50 *
51 * Also, under GNU libc, certain non-portable functions are only visible
52 * in the headers if you define %_GNU_SOURCE before including them. Note
53 * that this symbol must be defined before including any headers, or it
54 * may not take effect.
55 */
56  
57 /**
58 * g_networking_init:
59 *
60 * Initializes the platform networking libraries (eg, on Windows, this
61 * calls WSAStartup()). GLib will call this itself if it is needed, so
62 * you only need to call it if you directly call system networking
63 * functions (without calling any GLib networking functions first).
64 *
65 * Since: 2.36
66 */
67 void
68 g_networking_init (void)
69 {
70 #ifdef G_OS_WIN32
71 static volatile gsize inited = 0;
72  
73 if (g_once_init_enter (&inited))
74 {
75 WSADATA wsadata;
76 HMODULE ws2dll, iphlpapidll;
77  
78 if (WSAStartup (MAKEWORD (2, 0), &wsadata) != 0)
79 g_error ("Windows Sockets could not be initialized");
80  
81 /* We want to use these functions if they are available, but
82 * still need to make sure the code still runs on Windows XP
83 */
84 ws2dll = LoadLibraryW (L"ws2_32.dll");
85 iphlpapidll = LoadLibraryW (L"iphlpapi.dll");
86  
87 if (ws2dll != NULL)
88 {
89 ws2funcs.pInetNtop =
90 (PFN_InetNtop) GetProcAddress (ws2dll, "inet_ntop");
91 ws2funcs.pInetPton =
92 (PFN_InetPton) GetProcAddress (ws2dll, "inet_pton");
93 FreeLibrary (ws2dll);
94 }
95 else
96 {
97 ws2funcs.pInetNtop = NULL;
98 ws2funcs.pInetPton = NULL;
99 }
100  
101 if (iphlpapidll != NULL)
102 {
103 ws2funcs.pIfNameToIndex =
104 (PFN_IfNameToIndex) GetProcAddress (iphlpapidll, "if_nametoindex");
105 FreeLibrary (iphlpapidll);
106 }
107 else
108 ws2funcs.pIfNameToIndex = NULL;
109  
110 g_once_init_leave (&inited, 1);
111 }
112 #endif
113 }