/[LeafOK_CVS]/lbbs/src/net_server.c
ViewVC logotype

Contents of /lbbs/src/net_server.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (show annotations)
Mon Oct 18 11:34:15 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Changes since 1.1: +26 -15 lines
Content type: text/x-csrc
Fix bug

1 /***************************************************************************
2 net_server.c - description
3 -------------------
4 begin : Mon Oct 11 2004
5 copyright : (C) 2004 by Leaflet
6 email : leaflet@leafok.com
7 ***************************************************************************/
8
9 /***************************************************************************
10 * *
11 * This program is free software; you can redistribute it and/or modify *
12 * it under the terms of the GNU General Public License as published by *
13 * the Free Software Foundation; either version 2 of the License, or *
14 * (at your option) any later version. *
15 * *
16 ***************************************************************************/
17
18 #include "common.h"
19 #include <netinet/in.h>
20 #include <netdb.h>
21
22 int
23 net_server (const char *hostaddr, unsigned int port)
24 {
25 int sock_server, sock_client, namelen, seq, netint;
26 struct sockaddr_in sin;
27 char temp[256];
28
29 sock_server = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
30
31 if (sock_server < 0)
32 {
33 log_error ("Create socket failed\n");
34 exit (1);
35 }
36
37 sin.sin_family = AF_INET;
38 sin.sin_addr.s_addr =
39 (strlen (hostaddr) > 0 ? inet_addr (hostaddr) : INADDR_ANY);
40 sin.sin_port = htons (port);
41
42 if (bind (sock_server, (struct sockaddr *)&sin, sizeof(sin)) < 0)
43 {
44 log_error ("Bind address failed\n");
45 exit (2);
46 }
47
48 if (listen (sock_server, 10) < 0)
49 {
50 log_error ("Socket listen failed\n");
51 exit (3);
52 }
53
54 namelen = sizeof (sin);
55 while(1)
56 {
57 if ((sock_client = accept (sock_server, (struct sockaddr *) &sin, &namelen)) < 0)
58 {
59 log_error ("Accept connection error\n");
60 }
61 else
62 {
63 sprintf(temp, "Accept connection from %s\n",
64 inet_ntoa(sin.sin_addr));
65 log_std (temp);
66 }
67
68 if (fork_server(sock_server, sock_client, &sin)<0)
69 {
70 log_error ("Fork error\n");
71 }
72 }
73
74 return 0;
75 }

webmaster@leafok.com
ViewVC Help
Powered by ViewVC 1.3.0-beta1