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"
32 CoreExport const char *insp_inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
37 struct sockaddr_in in;
38 memset(&in, 0, sizeof(in));
39 in.sin_family = AF_INET;
40 memcpy(&in.sin_addr, src, sizeof(struct in_addr));
41 getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in), dst, cnt, NULL, 0, NI_NUMERICHOST);
44 else if (af == AF_INET6)
46 struct sockaddr_in6 in;
47 memset(&in, 0, sizeof(in));
48 in.sin6_family = AF_INET6;
49 memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
50 getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6), dst, cnt, NULL, 0, NI_NUMERICHOST);
56 CoreExport int insp_inet_pton(int af, const char *src, void *dst)
59 int len = sizeof(SOCKADDR);
60 int rv = WSAStringToAddressA((LPSTR)src, af, NULL, (LPSOCKADDR)&sa, &len);
63 if(WSAGetLastError() == WSAEINVAL)
68 memcpy(dst, &sa.sin_addr, sizeof(struct in_addr));
72 CoreExport DIR * opendir(const char * path)
74 std::string search_path = std::string(path) + "\\*.*";
76 HANDLE f = FindFirstFileA(search_path.c_str(), &fd);
77 if (f != INVALID_HANDLE_VALUE)
80 memcpy(&d->find_data, &fd, sizeof(WIN32_FIND_DATA));
91 CoreExport dirent * readdir(DIR * handle)
94 handle->first = false;
97 if (!FindNextFileA(handle->find_handle, &handle->find_data))
101 strncpy(handle->dirent_pointer.d_name, handle->find_data.cFileName, MAX_PATH);
102 return &handle->dirent_pointer;
105 CoreExport void closedir(DIR * handle)
107 FindClose(handle->find_handle);
113 int getopt_long(int ___argc, char *const *___argv, const char *__shortopts, const struct option *__longopts, int *__longind)
115 // burlex todo: handle the shortops, at the moment it only works with longopts.
117 if (___argc == 1 || optind == ___argc) // No arguments (apart from filename)
120 const char * opt = ___argv[optind];
123 // if we're not an option, return an error.
124 if (strnicmp(opt, "--", 2) != 0)
130 // parse argument list
132 for (; __longopts[i].name != 0; ++i)
134 if (!strnicmp(__longopts[i].name, opt, strlen(__longopts[i].name)))
136 // woot, found a valid argument =)
138 if ((optind) != ___argc)
140 // grab the parameter from the next argument (if its not another argument)
141 if (strnicmp(___argv[optind], "--", 2) != 0)
143 // optind++; // Trash this next argument, we won't be needing it.
144 par = ___argv[optind-1];
148 // increment the argument for next time
151 // determine action based on type
152 if (__longopts[i].has_arg == required_argument && !par)
154 // parameter missing and its a required parameter option
158 // store argument in optarg
160 strncpy(optarg, par, 514);
162 if (__longopts[i].flag != 0)
164 // this is a variable, we have to set it if this argument is found.
165 *__longopts[i].flag = 1;
170 if (__longopts[i].val == -1 || par == 0)
173 return __longopts[i].val;
179 // return 1 (invalid argument)
183 #include "../src/modules/m_spanningtree/link.h"
184 #include "../src/modules/ssl.h"
185 template class reference<Link>;
186 template class reference<Autoconnect>;
187 template class reference<ssl_cert>;
188 template class reference<OperInfo>;