3 kHTTPd -- the next generation
8 /****************************************************************
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2, or (at your option)
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 ****************************************************************/
25 #include "prototypes.h"
26 #include <linux/kernel.h>
27 #include <linux/net.h>
28 #include <linux/version.h>
29 #include <linux/smp_lock.h>
35 MainSocket is shared by all threads, therefore it has to be
39 struct socket
*MainSocket
=NULL
;
42 int StartListening(const int Port
)
45 struct sockaddr_in sin
;
48 EnterFunction("StartListening");
50 /* First create a socket */
52 error
= sock_create(PF_INET
,SOCK_STREAM
,IPPROTO_TCP
,&sock
);
54 (void)printk(KERN_ERR
"Error during creation of socket; terminating\n");
58 /* Now bind the socket */
60 sin
.sin_family
= AF_INET
;
61 sin
.sin_addr
.s_addr
= INADDR_ANY
;
62 sin
.sin_port
= htons((unsigned short)Port
);
64 error
= sock
->ops
->bind(sock
,(struct sockaddr
*)&sin
,sizeof(sin
));
67 (void)printk(KERN_ERR
"kHTTPd: Error binding socket. This means that some other \n");
68 (void)printk(KERN_ERR
" daemon is (or was a short time ago) using port %i.\n",Port
);
72 /* Grrr... setsockopt() does this. */
77 /* Now, start listening on the socket */
79 /* I have no idea what a sane backlog-value is. 48 works so far. */
81 error
=sock
->ops
->listen(sock
,48);
83 (void)printk(KERN_ERR
"kHTTPd: Error listening on socket \n");
84 sock
->flags
|= SO_ACCEPTCON
;
88 EnterFunction("StartListening");
92 void StopListening(void)
96 EnterFunction("StopListening");
97 if (MainSocket
==NULL
) return;
103 LeaveFunction("StopListening");