|
|
1.1 root 1: /* sockopts.c */
2:
3: /* Set socket options based on contents of ctrl/sockopts.ini */
4:
5: /* $Id: sockopts.c,v 1.23 2005/10/19 09:06:23 rswindell Exp $ */
6:
7: /****************************************************************************
8: * @format.tab-size 4 (Plain Text/Source Code File Header) *
9: * @format.use-tabs true (see http://www.synchro.net/ptsc_hdr.html) *
10: * *
11: * Copyright 2005 Rob Swindell - http://www.synchro.net/copyright.html *
12: * *
13: * This program is free software; you can redistribute it and/or *
14: * modify it under the terms of the GNU General Public License *
15: * as published by the Free Software Foundation; either version 2 *
16: * of the License, or (at your option) any later version. *
17: * See the GNU General Public License for more details: gpl.txt or *
18: * http://www.fsf.org/copyleft/gpl.html *
19: * *
20: * Anonymous FTP access to the most recent released source is available at *
21: * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net *
22: * *
23: * Anonymous CVS access to the development source and modification history *
24: * is available at cvs.synchro.net:/cvsroot/sbbs, example: *
25: * cvs -d :pserver:[email protected]:/cvsroot/sbbs login *
26: * (just hit return, no password is necessary) *
27: * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src *
28: * *
29: * For Synchronet coding style and modification guidelines, see *
30: * http://www.synchro.net/source.html *
31: * *
32: * You are encouraged to submit any modifications (preferably in Unix diff *
33: * format) via e-mail to [email protected] *
34: * *
35: * Note: If this box doesn't appear square, then you need to fix your tabs. *
36: ****************************************************************************/
37:
38: #include "sbbs.h"
39: #include "ini_file.h" /* ini file API */
40:
41: int DLLCALL set_socket_options(scfg_t* cfg, SOCKET sock, const char* protocol, char* error, size_t errlen)
42: {
43: char cfgfile[MAX_PATH+1];
44: FILE* fp;
45: int type;
46: int result=0;
47: str_list_t list;
48: socklen_t len;
49:
50: len = sizeof(type);
51: result=getsockopt(sock,SOL_SOCKET,SO_TYPE,(void*)&type,&len);
52: if(result) {
53: safe_snprintf(error,errlen,"%d getting socket option type (%d)"
54: ,ERROR_VALUE, SO_TYPE);
55: return(result);
56: }
57:
58: /* Set user defined socket options */
59: iniFileName(cfgfile,sizeof(cfgfile),cfg->ctrl_dir,"sockopts.ini");
60: if((fp=iniOpenFile(cfgfile,FALSE))==NULL)
61: return(0);
62: list=iniReadFile(fp);
63: fclose(fp);
64:
65: result=iniGetSocketOptions(list,ROOT_SECTION,sock,error,errlen);
66:
67: if(result==0)
68: result=iniGetSocketOptions(list,type==SOCK_STREAM ? "tcp":"udp",sock,error,errlen);
69: if(result==0 && protocol!=NULL && *protocol!=0)
70: result=iniGetSocketOptions(list,protocol,sock,error,errlen);
71:
72: iniFreeStringList(list);
73:
74: return(result);
75: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.