File: src___socket.cc.patch

package info (click to toggle)
dhttpd 1.02a-18
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 256 kB
  • ctags: 55
  • sloc: cpp: 622; sh: 185; makefile: 43
file content (74 lines) | stat: -rw-r--r-- 1,611 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
--- a/src/socket.cc
+++ b/src/socket.cc
@@ -24,10 +24,12 @@
 #include <stdio.h>
 #include <string.h>
 #include <unistd.h>
+#include <syslog.h>
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/types.h>
 #include <sys/wait.h>
+#include <arpa/inet.h>		/* inet_addr */
 
 #include "socket.hh"
 
@@ -76,34 +78,41 @@
  * ListenSocket::ListenSocket():
  *   Start up the socket listening routines
  */
-ListenSocket::ListenSocket( int port )
+ListenSocket::ListenSocket( int port, char *bind_addr )
 {
 	int status;
-	struct sockaddr_in sin;
+	struct sockaddr_in s_in;
 	int one;
   
 	status = 0;
 	one = 1;
-	memset( &sin, 0, sizeof( sin ) );
-	sin.sin_family = AF_INET;
-	sin.sin_addr.s_addr = htonl( INADDR_ANY );
-	sin.sin_port = htons( port );
+	memset( &s_in, 0, sizeof( s_in ) );
+	s_in.sin_family = AF_INET;
+	s_in.sin_addr.s_addr = inet_addr( bind_addr );
+	s_in.sin_port = htons( port );
 
 	sock = socket( AF_INET, SOCK_STREAM, 0 );
  
 	if( sock==-1 )
 	{
+		syslog(LOG_ERR,"Error creating socket (%m)");
 		status = 1;
 	}
 
 	if( !status )
 	{
 		status = setsockopt( sock, SOL_SOCKET, SO_REUSEADDR, (char*) &one, sizeof( one ) );
+		if(status)
+			syslog(LOG_ERR,"Error setting socket options (%m)");
 	}
-  
+
 	if( !status )
 	{
-		status = bind( sock, (struct sockaddr *) &sin, sizeof( sin ) );
+		status = bind( sock, (struct sockaddr *) &s_in, sizeof( s_in ) );
+		if(status)
+		{
+			syslog(LOG_ERR,"Error binding to port %d (%m)",port);
+		}
 	}	
 	if( !status )
 	{
@@ -143,7 +152,7 @@
  */
 int ListenSocket::newsock()
 {
-	int cSidLen;
+	unsigned int cSidLen;
 	int s;
 	
 	do