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

Annotation of /lbbs/src/net_server.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Mon Oct 18 08:44:39 2004 UTC (21 years, 5 months ago) by sysadm
Branch: MAIN
Content type: text/x-csrc
Socket server

1 sysadm 1.1 /***************************************************************************
2     bbsd.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 <sys/socket.h>
20     #include <netinet/in.h>
21     #include <netdb.h>
22    
23     int
24     net_server (const char *hostaddr, unsigned int port)
25     {
26     int sock, namelen, seq, netint;
27     struct sockaddr_in sin;
28     char msgsock;
29     char buf[1024];
30    
31     sock = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP);
32    
33     if (sock < 0)
34     {
35     perror ("socket");
36     exit (1);
37     }
38    
39     sin.sin_family = AF_INET;
40     sin.sin_addr.s_addr =
41     (strlen (hostaddr) > 0 ? inet_addr (hostaddr) : INADDR_ANY);
42     sin.sin_port = htons (port);
43    
44     if (bind (sock, (struct sockaddr *) &sin, sizeof (sin)) < 0)
45     {
46     perror ("bind");
47     exit (2);
48     }
49    
50     if (listen (sock, 10) < 0)
51     {
52     perror ("listen");
53     exit (3);
54     }
55    
56     namelen = sizeof (sin);
57     if ((msgsock = accept (sock, (struct sockaddr *) &sin, &namelen)) < 0)
58     {
59     perror ("accept");
60     exit (4);
61     }
62    
63     return 0;
64     }

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