2 * InspIRCd -- Internet Relay Chat Daemon
4 * Copyright (C) 2011 Adam <Adam@anope.org>
5 * Copyright (C) 2007, 2009 Dennis Friis <peavey@inspircd.org>
6 * Copyright (C) 2009 Daniel De Graaf <danieldg@inspircd.org>
7 * Copyright (C) 2007-2009 Craig Edwards <craigedwards@brainbox.cc>
8 * Copyright (C) 2008 John Brooks <john.brooks@dereferenced.net>
9 * Copyright (C) 2007 Burlex <???@???>
10 * Copyright (C) 2007 Robin Burchell <robin+git@viroteck.net>
12 * This file is part of InspIRCd. InspIRCd is free software: you can
13 * redistribute it and/or modify it under the terms of the GNU General Public
14 * License as published by the Free Software Foundation, version 2.
16 * This program is distributed in the hope that it will be useful, but WITHOUT
17 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
18 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
21 * You should have received a copy of the GNU General Public License
22 * along with this program. If not, see <http://www.gnu.org/licenses/>.
25 #include "inspircd_win32wrapper.h"
27 #include "configreader.h"
33 #pragma comment(lib, "Winmm.lib")
35 CoreExport const char *insp_inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
40 struct sockaddr_in in;
41 memset(&in, 0, sizeof(in));
42 in.sin_family = AF_INET;
43 memcpy(&in.sin_addr, src, sizeof(struct in_addr));
44 getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST);
47 else if (af == AF_INET6)
49 struct sockaddr_in6 in;
50 memset(&in, 0, sizeof(in));
51 in.sin6_family = AF_INET6;
52 memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
53 getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST);
59 CoreExport int insp_inet_pton(int af, const char *src, void *dst)
62 int len = sizeof(SOCKADDR);
63 int rv = WSAStringToAddressA((LPSTR)src, af, NULL, (LPSOCKADDR)&sa, &len);
66 if(WSAGetLastError() == WSAEINVAL)
71 memcpy(dst, &sa.sin_addr, sizeof(struct in_addr));
75 CoreExport DIR * opendir(const char * path)
77 std::string search_path = std::string(path) + "\\*.*";
79 HANDLE f = FindFirstFileA(search_path.c_str(), &fd);
80 if (f != INVALID_HANDLE_VALUE)
83 memcpy(&d->find_data, &fd, sizeof(WIN32_FIND_DATA));
94 CoreExport dirent * readdir(DIR * handle)
97 handle->first = false;
100 if (!FindNextFileA(handle->find_handle, &handle->find_data))
104 strncpy(handle->dirent_pointer.d_name, handle->find_data.cFileName, MAX_PATH);
105 return &handle->dirent_pointer;
108 CoreExport void closedir(DIR * handle)
110 FindClose(handle->find_handle);
116 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
118 // burlex todo: handle the shortops, at the moment it only works with longopts.
120 if (___argc == 1 || optind == ___argc) // No arguments (apart from filename)
123 const char * opt = ___argv[optind];
126 // if we're not an option, return an error.
127 if (strnicmp(opt, "--", 2) != 0)
133 // parse argument list
135 for (; __longopts[i].name != 0; ++i)
137 if (!strnicmp(__longopts[i].name, opt, strlen(__longopts[i].name)))
139 // woot, found a valid argument =)
141 if ((optind) != ___argc)
143 // grab the parameter from the next argument (if its not another argument)
144 if (strnicmp(___argv[optind], "--", 2) != 0)
146 // optind++; // Trash this next argument, we won't be needing it.
147 par = ___argv[optind-1];
151 // increment the argument for next time
154 // determine action based on type
155 if (__longopts[i].has_arg == required_argument && !par)
157 // parameter missing and its a required parameter option
161 // store argument in optarg
163 strncpy(optarg, par, 514);
165 if (__longopts[i].flag != 0)
167 // this is a variable, we have to set it if this argument is found.
168 *__longopts[i].flag = 1;
173 if (__longopts[i].val == -1 || par == 0)
176 return __longopts[i].val;
182 // return 1 (invalid argument)
186 #include "../src/modules/m_spanningtree/link.h"
187 #include "../src/modules/ssl.h"
188 template class reference<Link>;
189 template class reference<Autoconnect>;
190 template class reference<ssl_cert>;
191 template class reference<OperInfo>;