1 /* +------------------------------------+
2 * | Inspire Internet Relay Chat Daemon |
3 * +------------------------------------+
5 * Inspire is copyright (C) 2002-2004 ChatSpike-Dev.
7 * <brain@chatspike.net>
8 * <Craig@chatspike.net>
10 * Written by Craig Edwards, Craig McLure, and others.
11 * This program is free but copyrighted software; see
12 * the file COPYING for details.
14 * ---------------------------------------------------
19 #include "inspircd_config.h"
21 #include <sys/resource.h>
22 #include <sys/types.h>
29 #include "inspircd_io.h"
30 #include "inspircd_util.h"
31 #include "inspstring.h"
32 #include "helperfuncs.h"
35 extern ServerConfig *Config;
36 extern InspIRCd* ServerInstance;
37 extern int openSockfd[MAXSOCKS];
41 ServerConfig::ServerConfig()
44 *ServerName = *Network = *ServerDesc = *AdminName = '\0';
45 *AdminEmail = *AdminNick = *diepass = *restartpass = '\0';
46 *motd = *rules = *PrefixQuit = *DieValue = *DNSServer = '\0';
47 *ModPath = *MyExecutable = *DisabledCommands = *PID = '\0';
53 NetBufferSize = 10240;
54 SoftLimit = MAXCLIENTS;
62 void ServerConfig::ClearStack()
64 include_stack.clear();
68 void ServerConfig::Read(bool bail, userrec* user)
70 char dbg[MAXBUF],pauseval[MAXBUF],Value[MAXBUF],timeout[MAXBUF],NB[MAXBUF],flood[MAXBUF],MW[MAXBUF],MCON[MAXBUF];
71 char AH[MAXBUF],AP[MAXBUF],AF[MAXBUF],DNT[MAXBUF],pfreq[MAXBUF],thold[MAXBUF],sqmax[MAXBUF],rqmax[MAXBUF],SLIMT[MAXBUF];
73 std::stringstream errstr;
74 include_stack.clear();
76 if (!LoadConf(CONFIG_FILE,&Config->config_f,&errstr))
79 log(DEFAULT,"There were errors in your configuration:\n%s",errstr.str().c_str());
82 printf("There were errors in your configuration:\n%s",errstr.str().c_str());
90 WriteServ(user->fd,"NOTICE %s :There were errors in the configuration file:",user->nick);
93 errstr.getline(dataline,1024);
94 WriteServ(user->fd,"NOTICE %s :%s",user->nick,dataline);
99 WriteOpers("There were errors in the configuration file:");
100 while (!errstr.eof())
102 errstr.getline(dataline,1024);
103 WriteOpers(dataline);
110 ConfValue("server","name",0,Config->ServerName,&Config->config_f);
111 ConfValue("server","description",0,Config->ServerDesc,&Config->config_f);
112 ConfValue("server","network",0,Config->Network,&Config->config_f);
113 ConfValue("admin","name",0,Config->AdminName,&Config->config_f);
114 ConfValue("admin","email",0,Config->AdminEmail,&Config->config_f);
115 ConfValue("admin","nick",0,Config->AdminNick,&Config->config_f);
116 ConfValue("files","motd",0,Config->motd,&Config->config_f);
117 ConfValue("files","rules",0,Config->rules,&Config->config_f);
118 ConfValue("power","diepass",0,Config->diepass,&Config->config_f);
119 ConfValue("power","pause",0,pauseval,&Config->config_f);
120 ConfValue("power","restartpass",0,Config->restartpass,&Config->config_f);
121 ConfValue("options","prefixquit",0,Config->PrefixQuit,&Config->config_f);
122 ConfValue("die","value",0,Config->DieValue,&Config->config_f);
123 ConfValue("options","loglevel",0,dbg,&Config->config_f);
124 ConfValue("options","netbuffersize",0,NB,&Config->config_f);
125 ConfValue("options","maxwho",0,MW,&Config->config_f);
126 ConfValue("options","allowhalfop",0,AH,&Config->config_f);
127 ConfValue("options","allowprotect",0,AP,&Config->config_f);
128 ConfValue("options","allowfounder",0,AF,&Config->config_f);
129 ConfValue("dns","server",0,Config->DNSServer,&Config->config_f);
130 ConfValue("dns","timeout",0,DNT,&Config->config_f);
131 ConfValue("options","moduledir",0,Config->ModPath,&Config->config_f);
132 ConfValue("disabled","commands",0,Config->DisabledCommands,&Config->config_f);
133 ConfValue("options","somaxconn",0,MCON,&Config->config_f);
134 ConfValue("options","softlimit",0,SLIMT,&Config->config_f);
136 Config->SoftLimit = atoi(SLIMT);
137 if ((Config->SoftLimit < 1) || (Config->SoftLimit > MAXCLIENTS))
139 log(DEFAULT,"WARNING: <options:softlimit> value is greater than %d or less than 0, set to %d.",MAXCLIENTS,MAXCLIENTS);
140 Config->SoftLimit = MAXCLIENTS;
142 Config->MaxConn = atoi(MCON);
143 if (Config->MaxConn > SOMAXCONN)
144 log(DEFAULT,"WARNING: <options:somaxconn> value may be higher than the system-defined SOMAXCONN value!");
145 Config->NetBufferSize = atoi(NB);
146 Config->MaxWhoResults = atoi(MW);
147 Config->dns_timeout = atoi(DNT);
148 if (!Config->dns_timeout)
149 Config->dns_timeout = 5;
150 if (!Config->MaxConn)
151 Config->MaxConn = SOMAXCONN;
152 if (!*Config->DNSServer)
153 strlcpy(Config->DNSServer,"127.0.0.1",MAXBUF);
154 if (!*Config->ModPath)
155 strlcpy(Config->ModPath,MOD_PATH,MAXBUF);
156 Config->AllowHalfop = ((!strcasecmp(AH,"true")) || (!strcasecmp(AH,"1")) || (!strcasecmp(AH,"yes")));
157 if ((!Config->NetBufferSize) || (Config->NetBufferSize > 65535) || (Config->NetBufferSize < 1024))
159 log(DEFAULT,"No NetBufferSize specified or size out of range, setting to default of 10240.");
160 Config->NetBufferSize = 10240;
162 if ((!Config->MaxWhoResults) || (Config->MaxWhoResults > 65535) || (Config->MaxWhoResults < 1))
164 log(DEFAULT,"No MaxWhoResults specified or size out of range, setting to default of 128.");
165 Config->MaxWhoResults = 128;
167 Config->LogLevel = DEFAULT;
168 if (!strcmp(dbg,"debug"))
170 Config->LogLevel = DEBUG;
171 Config->debugging = 1;
173 if (!strcmp(dbg,"verbose"))
174 Config->LogLevel = VERBOSE;
175 if (!strcmp(dbg,"default"))
176 Config->LogLevel = DEFAULT;
177 if (!strcmp(dbg,"sparse"))
178 Config->LogLevel = SPARSE;
179 if (!strcmp(dbg,"none"))
180 Config->LogLevel = NONE;
182 readfile(Config->MOTD,Config->motd);
183 log(DEFAULT,"Reading message of the day...");
184 readfile(Config->RULES,Config->rules);
185 log(DEFAULT,"Reading connect classes...");
187 for (int i = 0; i < ConfValueEnum("connect",&Config->config_f); i++)
190 ConfValue("connect","allow",i,Value,&Config->config_f);
191 ConfValue("connect","timeout",i,timeout,&Config->config_f);
192 ConfValue("connect","flood",i,flood,&Config->config_f);
193 ConfValue("connect","pingfreq",i,pfreq,&Config->config_f);
194 ConfValue("connect","threshold",i,thold,&Config->config_f);
195 ConfValue("connect","sendq",i,sqmax,&Config->config_f);
196 ConfValue("connect","recvq",i,rqmax,&Config->config_f);
199 strlcpy(c.host,Value,MAXBUF);
201 strlcpy(Value,"",MAXBUF);
202 ConfValue("connect","password",i,Value,&Config->config_f);
203 strlcpy(c.pass,Value,MAXBUF);
204 c.registration_timeout = 90; // default is 2 minutes
206 c.flood = atoi(flood);
208 c.sendqmax = 262144; // 256k
209 c.recvqmax = 4096; // 4k
212 c.threshold = atoi(thold);
216 c.sendqmax = atoi(sqmax);
220 c.recvqmax = atoi(rqmax);
224 c.registration_timeout = atoi(timeout);
228 c.pingtime = atoi(pfreq);
230 Classes.push_back(c);
234 ConfValue("connect","deny",i,Value,&Config->config_f);
235 strlcpy(c.host,Value,MAXBUF);
237 Classes.push_back(c);
238 log(DEBUG,"Read connect class type DENY, host=%s",c.host);
242 log(DEFAULT,"Reading K lines,Q lines and Z lines from config...");
243 read_xline_defaults();
244 log(DEFAULT,"Applying K lines, Q lines and Z lines...");
245 apply_lines(APPLY_ALL);
247 ConfValue("pid","file",0,Config->PID,&Config->config_f);
248 // write once here, to try it out and make sure its ok
249 WritePID(Config->PID);
251 log(DEFAULT,"Done reading configuration file, InspIRCd is now starting.");
254 log(DEFAULT,"Adding and removing modules due to rehash...");
256 std::vector<std::string> old_module_names, new_module_names, added_modules, removed_modules;
258 // store the old module names
259 for (std::vector<std::string>::iterator t = module_names.begin(); t != module_names.end(); t++)
261 old_module_names.push_back(*t);
264 // get the new module names
265 for (int count2 = 0; count2 < ConfValueEnum("module",&Config->config_f); count2++)
267 ConfValue("module","name",count2,Value,&Config->config_f);
268 new_module_names.push_back(Value);
271 // now create a list of new modules that are due to be loaded
272 // and a seperate list of modules which are due to be unloaded
273 for (std::vector<std::string>::iterator _new = new_module_names.begin(); _new != new_module_names.end(); _new++)
276 for (std::vector<std::string>::iterator old = old_module_names.begin(); old != old_module_names.end(); old++)
282 added_modules.push_back(*_new);
284 for (std::vector<std::string>::iterator oldm = old_module_names.begin(); oldm != old_module_names.end(); oldm++)
287 for (std::vector<std::string>::iterator newm = new_module_names.begin(); newm != new_module_names.end(); newm++)
293 removed_modules.push_back(*oldm);
295 // now we have added_modules, a vector of modules to be loaded, and removed_modules, a vector of modules
297 int rem = 0, add = 0;
298 if (!removed_modules.empty())
299 for (std::vector<std::string>::iterator removing = removed_modules.begin(); removing != removed_modules.end(); removing++)
301 if (ServerInstance->UnloadModule(removing->c_str()))
303 WriteOpers("*** REHASH UNLOADED MODULE: %s",removing->c_str());
304 WriteServ(user->fd,"973 %s %s :Module %s successfully unloaded.",user->nick, removing->c_str(), removing->c_str());
309 WriteServ(user->fd,"972 %s %s :Failed to unload module %s: %s",user->nick, removing->c_str(), removing->c_str(), ServerInstance->ModuleError());
312 if (!added_modules.empty())
313 for (std::vector<std::string>::iterator adding = added_modules.begin(); adding != added_modules.end(); adding++)
315 if (ServerInstance->LoadModule(adding->c_str()))
317 WriteOpers("*** REHASH LOADED MODULE: %s",adding->c_str());
318 WriteServ(user->fd,"975 %s %s :Module %s successfully loaded.",user->nick, adding->c_str(), adding->c_str());
323 WriteServ(user->fd,"974 %s %s :Failed to load module %s: %s",user->nick, adding->c_str(), adding->c_str(), ServerInstance->ModuleError());
326 log(DEFAULT,"Successfully unloaded %lu of %lu modules and loaded %lu of %lu modules.",(unsigned long)rem,(unsigned long)removed_modules.size(),
327 (unsigned long)add,(unsigned long)added_modules.size());
332 void Exit (int status)
334 if (Config->log_file)
335 fclose(Config->log_file);
336 send_error("Server shutdown.");
340 void Killed(int status)
342 if (Config->log_file)
343 fclose(Config->log_file);
344 send_error("Server terminated.");
348 void Rehash(int status)
350 WriteOpers("Rehashing config file %s due to SIGHUP",CONFIG_FILE);
351 Config->Read(false,NULL);
358 printf("\033[1;32mInspire Internet Relay Chat Server, compiled %s at %s\n",__DATE__,__TIME__);
359 printf("(C) ChatSpike Development team.\033[0m\n\n");
360 printf("Developers:\033[1;32m Brain, FrostyCoolSlug\033[0m\n");
361 printf("Documentation:\033[1;32m FrostyCoolSlug, w00t\033[0m\n");
362 printf("Testers:\033[1;32m typobox43, piggles, Lord_Zathras, CC\033[0m\n");
363 printf("Name concept:\033[1;32m Lord_Zathras\033[0m\n\n");
366 void WritePID(std::string filename)
368 ofstream outfile(filename.c_str());
369 if (outfile.is_open())
376 printf("Failed to write PID-file '%s', exiting.\n",filename.c_str());
377 log(DEFAULT,"Failed to write PID-file '%s', exiting.",filename.c_str());
383 int DaemonSeed (void)
386 signal (SIGALRM, SIG_IGN);
387 signal (SIGHUP, Rehash);
388 signal (SIGPIPE, SIG_IGN);
389 signal (SIGTERM, Exit);
390 signal (SIGSEGV, Error);
391 if ((childpid = fork ()) < 0)
393 else if (childpid > 0)
397 printf("InspIRCd Process ID: \033[1;32m%lu\033[0m\n",(unsigned long)getpid());
399 setpriority(PRIO_PROCESS,(int)getpid(),15);
401 if (Config->unlimitcore)
404 if (getrlimit(RLIMIT_CORE, &rl) == -1)
406 log(DEFAULT,"Failed to getrlimit()!");
411 rl.rlim_cur = rl.rlim_max;
412 if (setrlimit(RLIMIT_CORE, &rl) == -1)
413 log(DEFAULT,"setrlimit() failed, cannot increase coredump size.");
421 /* Make Sure Modules Are Avaliable!
422 * (BugFix By Craig.. See? I do work! :p)
423 * Modified by brain, requires const char*
424 * to work with other API functions
427 bool FileExists (const char* file)
430 if ((input = fopen (file, "r")) == NULL)
441 /* ConfProcess does the following things to a config line in the following order:
443 * Processes the line for syntax errors as shown below
444 * (1) Line void of quotes or equals (a malformed, illegal tag format)
445 * (2) Odd number of quotes on the line indicating a missing quote
446 * (3) number of equals signs not equal to number of quotes / 2 (missing an equals sign)
447 * (4) Spaces between the opening bracket (<) and the keyword
448 * (5) Spaces between a keyword and an equals sign
449 * (6) Spaces between an equals sign and a quote
450 * Removes trailing spaces
451 * Removes leading spaces
452 * Converts tabs to spaces
453 * Turns multiple spaces that are outside of quotes into single spaces
456 std::string ServerConfig::ConfProcess(char* buffer, long linenumber, std::stringstream* errorstream, bool &error, std::string filename)
458 long number_of_quotes = 0;
459 long number_of_equals = 0;
460 bool has_open_bracket = false;
461 bool in_quotes = false;
467 // firstly clean up the line by stripping spaces from the start and end and converting tabs to spaces
468 for (unsigned int d = 0; d < strlen(buffer); d++)
469 if ((buffer[d]) == 9)
471 while ((buffer[0] == ' ') && (strlen(buffer)>0)) buffer++;
472 while ((buffer[strlen(buffer)-1] == ' ') && (strlen(buffer)>0)) buffer[strlen(buffer)-1] = '\0';
474 // empty lines are syntactically valid, as are comments
475 if (!(*buffer) || buffer[0] == '#')
478 for (unsigned int c = 0; c < strlen(buffer); c++)
480 // convert all spaces that are OUTSIDE quotes into hardspace (0xA0) as this will make them easier to
481 // search and replace later :)
482 if ((!in_quotes) && (buffer[c] == ' '))
484 if ((buffer[c] == '<') && (!in_quotes))
486 has_open_bracket = true;
487 if (strlen(buffer) == 1)
489 *errorstream << "Tag without identifier at " << filename << ":" << linenumber << endl;
493 else if ((tolower(buffer[c+1]) < 'a') || (tolower(buffer[c+1]) > 'z'))
495 *errorstream << "Invalid characters in identifier at " << filename << ":" << linenumber << endl;
500 if (buffer[c] == '"')
503 in_quotes = (!in_quotes);
505 if ((buffer[c] == '=') && (!in_quotes))
508 if (strlen(buffer) == c)
510 *errorstream << "Variable without a value at " << filename << ":" << linenumber << endl;
514 else if (buffer[c+1] != '"')
516 *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
522 *errorstream << "Value without a variable (line starts with '=') at " << filename << ":" << linenumber << endl;
526 else if (buffer[c-1] == '\xA0')
528 *errorstream << "Variable name not followed immediately by its value at " << filename << ":" << linenumber << endl;
534 // no quotes, and no equals. something freaky.
535 if ((!number_of_quotes) || (!number_of_equals) && (strlen(buffer)>2) && (buffer[0]=='<'))
537 *errorstream << "Malformed tag at " << filename << ":" << linenumber << endl;
541 // odd number of quotes. thats just wrong.
542 if ((number_of_quotes % 2) != 0)
544 *errorstream << "Missing \" at " << filename << ":" << linenumber << endl;
548 if (number_of_equals < (number_of_quotes/2))
550 *errorstream << "Missing '=' at " << filename << ":" << linenumber << endl;
552 if (number_of_equals > (number_of_quotes/2))
554 *errorstream << "Too many '=' at " << filename << ":" << linenumber << endl;
557 std::string parsedata = buffer;
558 // turn multispace into single space
559 while (parsedata.find("\xA0\xA0") != std::string::npos)
561 parsedata.erase(parsedata.find("\xA0\xA0"),1);
564 // turn our hardspace back into softspace
565 for (unsigned int d = 0; d < parsedata.length(); d++)
567 if (parsedata[d] == '\xA0')
571 // and we're done, the line is fine!
575 int ServerConfig::fgets_safe(char* buffer, size_t maxsize, FILE* &file)
578 unsigned int bufptr = 0;
579 while ((!feof(file)) && (c_read != '\n') && (c_read != '\r') && (bufptr < maxsize))
581 c_read = fgetc(file);
582 if ((c_read != '\n') && (c_read != '\r'))
583 buffer[bufptr++] = c_read;
585 buffer[bufptr] = '\0';
589 bool ServerConfig::LoadConf(const char* filename, std::stringstream *target, std::stringstream* errorstream)
592 errorstream->str("");
594 // first, check that the file exists before we try to do anything with it
595 if (!FileExists(filename))
597 *errorstream << "File " << filename << " not found." << endl;
600 // Fix the chmod of the file to restrict it to the current user and group
601 chmod(filename,0600);
602 for (unsigned int t = 0; t < include_stack.size(); t++)
604 if (std::string(filename) == include_stack[t])
606 *errorstream << "File " << filename << " is included recursively (looped inclusion)." << endl;
610 include_stack.push_back(filename);
612 FILE* conf = fopen(filename,"r");
618 if (fgets_safe(buffer, MAXBUF, conf))
620 if ((!feof(conf)) && (buffer) && (strlen(buffer)))
622 if ((buffer[0] != '#') && (buffer[0] != '\r') && (buffer[0] != '\n'))
624 if (!strncmp(buffer,"<include file=\"",15))
627 char confpath[10240],newconf[10240];
628 // include file directive
629 buf += 15; // advance to filename
630 for (unsigned int j = 0; j < strlen(buf); j++)
640 log(DEFAULT,"Opening included file '%s'",buf);
643 strlcpy(confpath,CONFIG_FILE,10240);
644 if (strstr(confpath,"/inspircd.conf"))
646 // leaves us with just the path
647 *(strstr(confpath,"/inspircd.conf")) = '\0';
649 snprintf(newconf,10240,"%s/%s",confpath,buf);
651 else snprintf(newconf,10240,"%s",buf);
652 std::stringstream merge(stringstream::in | stringstream::out);
653 // recursively call LoadConf and get the new data, use the same errorstream
654 if (LoadConf(newconf, &merge, errorstream))
656 // append to the end of the file
657 std::string newstuff = merge.str();
662 // the error propogates up to its parent recursively
663 // causing the config reader to bail at the top level.
671 std::string data = this->ConfProcess(buffer,linenumber++,errorstream,error,filename);
689 /* Counts the number of tags of a certain type within the config file, e.g. to enumerate opers */
691 int ServerConfig::EnumConf(std::stringstream *config, const char* tag)
694 char buffer[MAXBUF], c_tag[MAXBUF], c, lastc;
695 int in_token, in_quotes, tptr, idx = 0;
697 const char* buf = config->str().c_str();
699 long len = strlen(buf);
709 if ((c == '#') && (lastc == '\n'))
711 while ((c != '\n') && (bptr<len))
717 if ((c == '<') && (!in_quotes))
732 in_quotes = (!in_quotes);
734 if ((c == '>') && (!in_quotes))
737 if (!strcmp(c_tag,tag))
739 /* correct tag, but wrong index */
749 if ((in_token) && (c != '\n') && (c != '\r'))
759 /* Counts the number of values within a certain tag */
761 int ServerConfig::EnumValues(std::stringstream *config, const char* tag, int index)
764 char buffer[MAXBUF], c_tag[MAXBUF], c, lastc;
765 int in_token, in_quotes, tptr, idx = 0;
767 bool correct_tag = false;
770 const char* buf = config->str().c_str();
772 long len = strlen(buf);
782 if ((c == '#') && (lastc == '\n'))
784 while ((c != '\n') && (bptr<len))
790 if ((c == '<') && (!in_quotes))
801 if ((!strcmp(c_tag,tag)) && (idx == index))
810 in_quotes = (!in_quotes);
813 if ( (correct_tag) && (!in_quotes) && ( (c == ' ') || (c == '\n') || (c == '\r') ) )
817 if ((c == '>') && (!in_quotes))
822 if (!strcmp(c_tag,tag))
824 /* correct tag, but wrong index */
834 if ((in_token) && (c != '\n') && (c != '\r'))
846 int ServerConfig::ConfValueEnum(char* tag, std::stringstream* config)
848 return EnumConf(config,tag);
853 /* Retrieves a value from the config file. If there is more than one value of the specified
854 * key and section (e.g. for opers etc) then the index value specifies which to retreive, e.g.
856 * ConfValue("oper","name",2,result);
859 int ServerConfig::ReadConf(std::stringstream *config, const char* tag, const char* var, int index, char *result)
862 char buffer[65535], c_tag[MAXBUF], c, lastc;
863 int in_token, in_quotes, tptr, idx = 0;
866 const char* buf = config->str().c_str();
868 long len = config->str().length();
880 // FIX: Treat tabs as spaces
883 if ((c == '<') && (!in_quotes))
894 // FIX: Tab can follow a tagname as well as space.
895 } while ((c != ' ') && (c != 9));
899 in_quotes = (!in_quotes);
901 if ((c == '>') && (!in_quotes))
906 if (!strcmp(c_tag,tag))
908 if ((buffer) && (c_tag) && (var))
910 key = strstr(buffer,var);
913 /* value not found in tag */
931 for (unsigned j = 0; j < strlen(key); j++)
938 strlcpy(result,key,MAXBUF);
944 if (!strcmp(c_tag,tag))
946 /* correct tag, but wrong index */
956 if ((in_token) && (c != '\n') && (c != '\r'))
963 strcpy(result,""); // value or its tag not found at all
969 int ServerConfig::ConfValue(char* tag, char* var, int index, char *result,std::stringstream *config)
971 ReadConf(config, tag, var, index, result);
977 // This will bind a socket to a port. It works for UDP/TCP
978 int BindSocket (int sockfd, struct sockaddr_in client, struct sockaddr_in server, int port, char* addr)
980 memset((char *)&server,0,sizeof(server));
982 inet_aton(addr,&addy);
983 server.sin_family = AF_INET;
984 if (!strcmp(addr,""))
986 server.sin_addr.s_addr = htonl(INADDR_ANY);
990 server.sin_addr = addy;
992 server.sin_port = htons(port);
993 if (bind(sockfd,(struct sockaddr*)&server,sizeof(server))<0)
999 listen(sockfd, Config->MaxConn);
1005 // Open a TCP Socket
1006 int OpenTCPSocket (void)
1010 struct linger linger = { 0 };
1012 if ((sockfd = socket (AF_INET, SOCK_STREAM, 0)) < 0)
1016 setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR, (const char*)&on, sizeof(on));
1017 /* This is BSD compatible, setting l_onoff to 0 is *NOT* http://web.irc.org/mla/ircd-dev/msg02259.html */
1019 linger.l_linger = 1;
1020 setsockopt(sockfd, SOL_SOCKET, SO_LINGER, (const char*)&linger,sizeof(linger));
1027 char configToken[MAXBUF], Addr[MAXBUF], Type[MAXBUF];
1028 sockaddr_in client,server;
1029 int clientportcount = 0;
1030 int BoundPortCount = 0;
1031 for (int count = 0; count < Config->ConfValueEnum("bind",&Config->config_f); count++)
1033 Config->ConfValue("bind","port",count,configToken,&Config->config_f);
1034 Config->ConfValue("bind","address",count,Addr,&Config->config_f);
1035 Config->ConfValue("bind","type",count,Type,&Config->config_f);
1036 if (strcmp(Type,"servers"))
1038 // modules handle server bind types now,
1039 // its not a typo in the strcmp.
1040 Config->ports[clientportcount] = atoi(configToken);
1041 strlcpy(Config->addrs[clientportcount],Addr,256);
1043 log(DEBUG,"InspIRCd: startup: read binding %s:%s [%s] from config",Addr,configToken, Type);
1046 int PortCount = clientportcount;
1048 for (int count = 0; count < PortCount; count++)
1050 if ((openSockfd[BoundPortCount] = OpenTCPSocket()) == ERROR)
1052 log(DEBUG,"InspIRCd: startup: bad fd %lu",(unsigned long)openSockfd[BoundPortCount]);
1055 if (BindSocket(openSockfd[BoundPortCount],client,server,Config->ports[count],Config->addrs[count]) == ERROR)
1057 log(DEFAULT,"InspIRCd: startup: failed to bind port %lu",(unsigned long)Config->ports[count]);
1059 else /* well we at least bound to one socket so we'll continue */
1065 /* if we didn't bind to anything then abort */
1066 if (!BoundPortCount)
1068 log(DEFAULT,"InspIRCd: startup: no ports bound, bailing!");
1069 printf("\nERROR: Was not able to bind any of %lu ports! Please check your configuration.\n\n", (unsigned long)PortCount);
1073 return BoundPortCount;