* Updated the ig_tcp_server() function to allow binding to a single IP
authorArt Cancro <ajc@citadel.org>
Thu, 24 Jun 2004 15:26:34 +0000 (15:26 +0000)
committerArt Cancro <ajc@citadel.org>
Thu, 24 Jun 2004 15:26:34 +0000 (15:26 +0000)
  address.  This is not yet used by anything.

citadel/ChangeLog
citadel/serv_extensions.c
citadel/sysdep.c
citadel/sysdep_decls.h

index 0e7200b3207966941738d6f75be877b62850aa93..61c503f92b499a154f9bef0a45775fe261b3ef40 100644 (file)
@@ -1,4 +1,8 @@
  $Log$
+ Revision 622.2  2004/06/24 15:26:33  ajc
+ * Updated the ig_tcp_server() function to allow binding to a single IP
+   address.  This is not yet used by anything.
+
  Revision 622.1  2004/06/24 02:34:39  ajc
  * serv_imap.c: when an IMAP socket breaks while a folder is selected,
    auto-expunge the folder before closing it.  Fixes the "mysteriously
@@ -5875,3 +5879,4 @@ Sat Jul 11 00:20:48 EDT 1998 Nathan Bryant <bryant@cs.usm.maine.edu>
 
 Fri Jul 10 1998 Art Cancro <ajc@uncensored.citadel.org>
        * Initial CVS import
+
index b10635097f042969e3013197aaa87d5b0e7d19f2..e62655e1e72f5cc82703b6e9759bf6a1d810e701 100644 (file)
@@ -452,7 +452,8 @@ void CtdlRegisterServiceHook(int tcp_port,
                return;
        }
        else {
-               newfcn->msock = ig_tcp_server(tcp_port, config.c_maxsessions);
+               newfcn->msock = ig_tcp_server(NULL, tcp_port,
+                                       config.c_maxsessions);
                snprintf(message, sizeof message, "TCP port %d: ", tcp_port);
        }
 
index 7d21eb0b24a17d6f9cfc97c1a159762e960fe9d4..1b89cb4d82a688a924bb5436fd122166320142a1 100644 (file)
@@ -107,12 +107,12 @@ int syslog_facility = (-1);
  * log data sent through this function.  BE CAREFUL!
  */
 void lprintf(enum LogLevel loglevel, const char *format, ...) {   
-        va_list arg_ptr;
+       va_list arg_ptr;
        char buf[SIZ];
  
-        va_start(arg_ptr, format);   
-        vsnprintf(buf, sizeof(buf), format, arg_ptr);   
-        va_end(arg_ptr);   
+       va_start(arg_ptr, format);   
+       vsnprintf(buf, sizeof(buf), format, arg_ptr);   
+       va_end(arg_ptr);   
 
        if (syslog_facility >= 0) {
                if (loglevel <= verbosity) {
@@ -275,7 +275,7 @@ void end_critical_section(int which_one)
  * a TCP port.  The server shuts down if the bind fails.
  *
  */
-int ig_tcp_server(int port_number, int queue_len)
+int ig_tcp_server(char *ip_addr, int port_number, int queue_len)
 {
        struct sockaddr_in sin;
        int s, i;
@@ -286,8 +286,17 @@ int ig_tcp_server(int port_number, int queue_len)
 
        memset(&sin, 0, sizeof(sin));
        sin.sin_family = AF_INET;
-       sin.sin_addr.s_addr = INADDR_ANY;
        sin.sin_port = htons((u_short)port_number);
+       if (ip_addr == NULL) {
+               sin.sin_addr.s_addr = INADDR_ANY;
+       }
+       else {
+               sin.sin_addr.s_addr = inet_addr(ip_addr);
+       }
+                                                                               
+       if (sin.sin_addr.s_addr == INADDR_NONE) {
+               sin.sin_addr.s_addr = INADDR_ANY;
+       }
 
        s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
 
@@ -448,7 +457,7 @@ DONE:       ++num_sessions;
 
 /*
  * buffer_output() ... tell client_write to buffer all output until
- *                     instructed to dump it all out later
+ *                  instructed to dump it all out later
  */
 void buffer_output(void) {
        if (CC->buffering == 0) {
@@ -529,15 +538,15 @@ void client_write(char *buf, int nbytes)
 
 /*
  * cprintf()  ...   Send formatted printable data to the client.   It is
- *                  implemented in terms of client_write() but remains in
- *                  sysdep.c in case we port to somewhere without va_args...
+ *               implemented in terms of client_write() but remains in
+ *               sysdep.c in case we port to somewhere without va_args...
  */
 void cprintf(const char *format, ...) {   
-        va_list arg_ptr;   
-        char buf[SIZ];   
+       va_list arg_ptr;   
+       char buf[SIZ];   
    
-        va_start(arg_ptr, format);   
-        if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
+       va_start(arg_ptr, format);   
+       if (vsnprintf(buf, sizeof buf, format, arg_ptr) == -1)
                buf[sizeof buf - 2] = '\n';
        client_write(buf, strlen(buf)); 
        va_end(arg_ptr);
index 008031e4a3b094e7e33b1997a99e8bbbefeab711..d58124e12e317bf2a50e622578b6620cf210f5c8 100644 (file)
@@ -44,7 +44,7 @@ void cprintf (const char *format, ...);
 void init_sysdep (void);
 void begin_critical_section (int which_one);
 void end_critical_section (int which_one);
-int ig_tcp_server (int port_number, int queue_len);
+int ig_tcp_server (char *ip_addr, int port_number, int queue_len);
 int ig_uds_server(char *sockpath, int queue_len);
 INLINE struct CitContext *MyContext (void);
 struct CitContext *CreateNewContext (void);