Apache-AuthenNTLM

 view release on metacpan or  search on metacpan

smb/smbval/session.c  view on Meta::CPAN

       and a new IP address in DEST_IP                            */

    if ((errno = RFCNB_Session_Req(con, 
				   Called_Name,
   				   Calling_Name,
				   &redirect, &Dest_IP, &port)) < 0) {

      /* No need to modify RFCNB_errno as it was done by RFCNB_Session.. */

      return(NULL);

      }

    if (redirect) {

      /* We have to close the connection, and then try again */

      (con -> redirects)++;

      RFCNB_Close(con -> fd);  /* Close it */

      }
    }

  return(con);

}

/* We send a packet to the other end ... for the moment, we treat the 
   data as a series of pointers to blocks of data ... we should check the
   length ... */

int RFCNB_Send(struct RFCNB_Con *Con_Handle, struct RFCNB_Pkt *udata, int Length)

{ struct RFCNB_Pkt *pkt; char *hdr;
  int len;

  /* Plug in the header and send the data */

  pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len);

  if (pkt == NULL) {

    RFCNB_errno = RFCNBE_NoSpace;
    RFCNB_saved_errno = errno;
    return(RFCNBE_Bad);

  }

  pkt -> next = udata;   /* The user data we want to send */

  hdr = pkt -> data;

  /* Following crap is for portability across multiple UNIX machines */

  *(hdr + RFCNB_Pkt_Type_Offset)  = RFCNB_SESSION_MESSAGE;
  RFCNB_Put_Pkt_Len(hdr, Length);

#ifdef RFCNB_DEBUG

  fprintf(stderr, "Sending packet: ");
  
#endif

  if ((len = RFCNB_Put_Pkt(Con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) {

    /* No need to change RFCNB_errno as it was done by put_pkt ...     */

    return(RFCNBE_Bad);   /* Should be able to write that lot ... */
    
  }

  /* Now we have sent that lot, let's get rid of the RFCNB Header and return */

  pkt -> next = NULL;

  RFCNB_Free_Pkt(pkt);

  return(len);

}

/* We pick up a message from the internet ... We have to worry about 
   non-message packets ...                                           */

int RFCNB_Recv(void *con_Handle, struct RFCNB_Pkt *Data, int Length)

{ struct RFCNB_Pkt *pkt;
/*  struct RFCNB_Hdr *hdr; */
  int ret_len;

  if (con_Handle == NULL){

    RFCNB_errno = RFCNBE_BadHandle;
    RFCNB_saved_errno = errno;
    return(RFCNBE_Bad);

  }

  /* Now get a packet from below. We allocate a header first */

  /* Plug in the header and send the data */

  pkt = RFCNB_Alloc_Pkt(RFCNB_Pkt_Hdr_Len);

  if (pkt == NULL) {

    RFCNB_errno = RFCNBE_NoSpace;
    RFCNB_saved_errno = errno;
    return(RFCNBE_Bad);

  }

  pkt -> next = Data;  /* Plug in the data portion */

  if ((ret_len = RFCNB_Get_Pkt(con_Handle, pkt, Length + RFCNB_Pkt_Hdr_Len)) < 0) {

#ifdef RFCNB_DEBUG
    fprintf(stderr, "Bad packet return in RFCNB_Recv... \n");
#endif

    return(RFCNBE_Bad);

  }

  /* We should check that we go a message and not a keep alive */

  pkt -> next = NULL;

  RFCNB_Free_Pkt(pkt);

  return(ret_len);

}

/* We just disconnect from the other end, as there is nothing in the RFCNB */
/* protocol that specifies any exchange as far as I can see                */

int RFCNB_Hangup(struct RFCNB_Con *con_Handle)

{
  struct redirect_addr *redir_addr,*next;

  if (con_Handle != NULL) {
    RFCNB_Close(con_Handle -> fd);  /* Could this fail? */
    if (con_Handle -> redirect_list != NULL)
    {
	do { 
		redir_addr = con_Handle->redirect_list;
		next = redir_addr->next;
		free(redir_addr);
	} while(next!=NULL);
	}
    free(con_Handle);
  }

  return 0;


}

/* Set TCP_NODELAY on the socket                                          */

int RFCNB_Set_Sock_NoDelay(struct RFCNB_Con *con_Handle, BOOL yn)

{

  return(setsockopt(con_Handle -> fd, IPPROTO_TCP, TCP_NODELAY, 
		    (char *)&yn, sizeof(yn)));

}


/* Listen for a connection on a port???, when                             */
/* the connection comes in, we return with the connection                 */

void *RFCNB_Listen()

{



( run in 2.890 seconds using v1.01-cache-2.11-cpan-99c4e6809bf )