Clarification: Accept Connection Code

John E. Malmberg wb8tyw at qsl.net
Sat Oct 5 02:37:12 GMT 2002


> "Michael D. Ober" <MDO at wakeassoc.company> wrote
> 
> Clarification:
> 
> I know how to create a listener and accept a connection.  What I don't know
> how to do is to pass the "client" socket to a new process.
> 

It works differently on OpenVMS than it does on UNIX.

On OpenVMS, you register the process with the TCPIP service dispatcher.

When a new request comes in for the socket, the TCPIP service dispatcher 
creates a new process, and binds the connection to a special port.

The application needs to bind a socket to that port.

In SAMBA 2.0.6, the location the client port is stored in is a Global 
variable.

The routine [samba_vms.source.smbd]vms_server.c is used as the main() 
routine, and does the bind of the socket.

It contains code to detect if the process is running interactive to 
allow you to debug the program easier.

A compile time #define is used to change the symbol name of main() in 
the original server.c routine so that no code edits are needed to the 
original UNIX code.

Below is the code that I used to do a preliminary port of SAMBA 2.2.x
to accomplish the same results.

-John
wb8tyw at qsl.network
Personal Opinion Only


/* File: VMS_SERVER.C
**
** This file replaces the main() routine in the SERVER.C module
** in SAMBA.
**
** It is needed for the SMBD server.
**
**   In UNIX, when called from inetd, stdin is already the server
**   socket.
**   In VMS (UCX), we must create a socket with the pseudo address
**   family 127. So we get the "Client" fd here instead of the dup(0) in
**   open_sockets_inetd. This is the only way to determine if cad from
**   inetd (which is called "auxiliary server" in UCX).
**
**   For Multinet (and probably others) the call must be the first call
**   before using any C RTL I/O function (according to previous SAMBA
**   for OpenVMS documentation).
**
** 04-Nov-2000  J. Malmberg
** 24-May-2001  J. Malmberg     Updated for SAMBA 2.2.0
******************************************************************************/

#include "includes.h"

#ifdef TCPIP$C_AUXS
#define TCPSRV TCPIP$C_AUXS
#else
#ifdef UCX$C_UCXS
#define TCPSRV TCPIP$C_AUXS
#else
#define TCPSRV 127
#endif
#endif

  /* System Service Definitions */
/*----------------------------*/
#include <ssdef.h>
#include <jpidef.h>

unsigned long LIB$GETJPI
        (const long * item_code,
         unsigned long * process_id,
         const struct dsc$descriptor_s * process_name,
         void * resultant_value,
         struct dsc$descriptor_s * resultant_string,
         unsigned short * resultant_length);

unsigned long LIB$SIGNAL(unsigned long call_stat);

int smbd_main(int argc, char *argv[]);

static int vms_is_socket = 0;

static int vms_server_fd = -1;

int vms_client_socket(int dummy)
{
     return vms_server_fd;
}


BOOL vms_is_a_socket(int fd)
{
     return vms_is_socket;
}


int main(int argc, char *argv[])
{

int ret_stat;
unsigned long call_stat;
const long item = JPI$_MODE;
unsigned long pid;
unsigned short res_len;
struct dsc$descriptor_s mode_desc;
char mode[64];

      /* Find out first if we are running Interactive */
     /*----------------------------------------------*/
     pid = 0;
     mode_desc.dsc$a_pointer = mode;
     mode_desc.dsc$w_length = 63;
     mode_desc.dsc$b_class = DSC$K_CLASS_S;
     mode_desc.dsc$b_dtype = DSC$K_DTYPE_T;
     call_stat = LIB$GETJPI(&item, &pid, 0, 0, &mode_desc, &res_len);

     if ((call_stat & SS$_NORMAL) == SS$_NORMAL)
     {
          /* If we are network or other then assume auxilliary server */
         /*----------------------------------------------------------*/
         if ((mode[0] != 'B') && (mode[0] != 'I'))
         {
             vms_server_fd = socket(TCPSRV, 0, 0);
             printf("Server fd = %d\n", vms_server_fd);
             vms_is_socket = 1;
         }
         else
         {
             vms_is_socket = 0;
         }

          /* Invoke the main routine */
         /*-------------------------*/
         ret_stat = smbd_main(argc, argv);
     }
     else
     {
         LIB$SIGNAL(call_stat);
     }
     return ret_stat;
}

-- 

Please all:
When replying to posts, please do not quote the entire previous message. 
    Trim as much as possible.  All posts are archived and can be 
retrieved if needed.

http://lists.samba.org/listinfo/samba-vms






More information about the samba-vms mailing list