GNUnet  0.10.x
Functions
w32nsp-install.c File Reference

W32 integration installer for GNS. More...

#include <ws2spi.h>
#include <windows.h>
#include <nspapi.h>
#include <initguid.h>
#include "gnunet_w32nsp_lib.h"
#include <stdio.h>
Include dependency graph for w32nsp-install.c:

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Detailed Description

W32 integration installer for GNS.

Author
LRN

Definition in file w32nsp-install.c.

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 34 of file w32nsp-install.c.

References pi, and ret.

35 {
36  int ret;
37  int r = 1;
38  WSADATA wsd;
39  GUID id = GNUNET_NAMESPACE_PROVIDER_DNS;
40  wchar_t *cmdl;
41  int wargc;
42  wchar_t **wargv;
43  /* Allocate a 4K buffer to retrieve all the namespace providers */
44  DWORD dwInitialBufferLen = 4096;
45  DWORD dwBufferLen;
46  WSANAMESPACE_INFO *pi;
47  int p_count;
48  int i;
49 
50  if (WSAStartup (MAKEWORD (2,2), &wsd) != 0)
51  {
52  fprintf (stderr, "WSAStartup () failed: %lu\n", GetLastError ());
53  return 5;
54  }
55 
56  dwBufferLen = dwInitialBufferLen;
57  pi = malloc (dwBufferLen);
58  if (NULL == pi)
59  {
60  fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
61  WSACleanup ();
62  return 6;
63  }
64  p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi);
65  if (SOCKET_ERROR == p_count)
66  {
67  DWORD err = GetLastError ();
68  if (WSAEFAULT == err && dwBufferLen != dwInitialBufferLen)
69  {
70  free (pi);
71 
72  pi = malloc (dwBufferLen);
73  if (pi == NULL)
74  {
75  fprintf (stderr, "malloc (%lu) failed: %d\n", dwBufferLen, errno);
76  WSACleanup ();
77  return 6;
78  }
79 
80  p_count = WSAEnumNameSpaceProviders (&dwBufferLen, pi);
81  if (SOCKET_ERROR == p_count)
82  {
83  fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ());
84  free (pi);
85  WSACleanup ();
86  return 7;
87  }
88  }
89  else
90  {
91  fprintf (stderr, "WSAEnumNameSpaceProviders (&%lu, %p) failed: %lu\n", dwBufferLen, pi, GetLastError ());
92  free (pi);
93  WSACleanup ();
94  return 8;
95  }
96  }
97  for (i= 0; i < p_count; i++)
98  {
99  if (IsEqualGUID (&pi[i].NSProviderId, &id))
100  {
101  fprintf (stderr, "GNUnet DNS provider is already installed\n");
102  free (pi);
103  WSACleanup ();
104  return 0;
105  }
106  }
107  free (pi);
108 
109  cmdl = GetCommandLineW ();
110  if (cmdl == NULL)
111  {
112  WSACleanup ();
113  return 2;
114  }
115  wargv = CommandLineToArgvW (cmdl, &wargc);
116  if (wargv == NULL)
117  {
118  WSACleanup ();
119  return 3;
120  }
121  r = 4;
122 
123  if (wargc == 2)
124  {
125  ret = WSCInstallNameSpace (L"GNUnet DNS provider", wargv[1], NS_DNS, 0, &id);
126  if (ret == NO_ERROR)
127  {
128  fprintf (stderr, "Installed GNUnet DNS provider\n");
129  r = 0;
130  }
131  else
132  {
133  r = 1;
134  fprintf (stderr,
135  "WSCInstallNameSpace (L\"GNUnet DNS provider\", \"%S\", %d, 0, %p) failed: %lu\n",
136  wargv[1], NS_DNS, &id, GetLastError ());
137  }
138  }
139  else
140  fprintf (stderr, "Usage: %S <path-to-libw32nsp>\n", wargv[0]);
141  WSACleanup ();
142  return r;
143 }
static struct GNUNET_PEERINFO_Handle * pi
Handle to peerinfo service.
static int ret
Final status code.
Definition: gnunet-arm.c:89