Example #1
0
File: serwer.c Project: batas2/UMK
void serwer_work(int sd)
{

	sprintf(line, "%d", (int)time(NULL));
	if(t_snd(sd, line, SIZE_BUF, 0) < 0)
		error("serwer->serwer_work->t_snd", sd);

}
Example #2
0
/*
 ****************************************************************
 *	Transmite um segmento compactado			*
 ****************************************************************
 */
void
send_seg (char c, COLFILE *fp)
{
	if (t_snd (tcp_fd, snd_rcv_buf, sizeof (snd_rcv_buf), 0) < 0)
		error (NOSTR);

	fp->i_ptr = fp->i_base;

	*fp->i_ptr++ = c;

}	/* end send_seg */
Example #3
0
/*
 ****************************************************************
 *	Escrita na Conexão					*
 ****************************************************************
 */
int
tcp_write (int fd, void *buf, int size)
{
	if (size <= 0)
	{
		t_push (fd);
		return (0);
	}

	return (t_snd (fd, buf, size, T_PUSH));

}	/* end tcp_write */
Example #4
0
int
main(int argc, char **argv)
{
	int		tfd;

	if (argc != 3)
		err_quit("usage: test01 <hostname/IPaddress> <service/port#>");

	tfd = Tcp_connect(argv[1], argv[2]);

	t_snd(tfd, "", 1, T_EXPEDITED);

	exit(0);
}
Example #5
0
/*
 ****************************************************************
 *	Copia um arquivo para o cliente				*
 ****************************************************************
 */
void
copy_to (const char *file_nm)
{
	off_t		n;
	int		fd = -1;
	STAT		s;
#ifdef	LITTLE_ENDIAN
	STAT		big_s;
#endif	LITTLE_ENDIAN
	char		*rmsg;

	/*
	 *	Obtém o estado do arquivo
	 */
	if (lstat (file_nm, &s) < 0)
	{
		t_snd_msg (-1, strerror (errno));
		return;
	}

	if (S_ISREG (s.st_mode) && (fd = inopen (s.st_dev, s.st_ino)) < 0)
	{
		t_snd_msg (-1, strerror (errno));
		return;
	}

	/*
	 *	Transmite o nome e estado do arquivo
	 */
	t_snd_msg_no_push (0, NOSTR);

#ifdef	LITTLE_ENDIAN
	stat_endian_cv (&big_s, &s);

	if (t_snd (tcp_fd, &big_s, sizeof (STAT), T_PUSH) < 0)
		error (NOSTR);
#else
	if (t_snd (tcp_fd, &s, sizeof (STAT), T_PUSH) < 0)
		error (NOSTR);
#endif	LITTLE_ENDIAN

	/*
	 *	Se for um elo simbólico, envia também o conteúdo
	 */
	if (S_ISLNK (s.st_mode))
	{
		char		*local_symlink_nm;

		n = s.st_size + 1; local_symlink_nm  = alloca (n);

		if (readlink (file_nm, local_symlink_nm, n) < 0)
			error ("$*Não consegui obter o conteúdo do elo \"%s\"", file_nm);

		if (t_snd (tcp_fd, local_symlink_nm, n, 0) < 0)
			error (NOSTR);

		t_push (tcp_fd);
	}

	/*
	 *	Espera confirmação de criação do arquivo na estação remota
	 */
	if (t_rcv_msg (&rmsg) < 0)
	{
		if (fd > 0)
			close (fd);
		return;
	}

	/*
	 *	Se não for regular, não precisa de enviar o conteúdo
	 */
	if (!S_ISREG (s.st_mode))
		return;

	/*
	 *	Transmite os segmentos
	 */
	if (Cflag && s.st_size >= MIN_COMPRESS_SZ)
	{
		reduce (fd, snd_rcv_buf);
	}
	else
	{
		for
		(	/* vazio */;
			(n = read (fd, snd_rcv_buf, BLSZ)) > 0;
			/* vazio */
		)
		{
			if (t_snd (tcp_fd, snd_rcv_buf, n, 0) < 0)
				error (NOSTR);

		}	/* loop pelo segmentos */
	
		if (n < 0)
			error ("$*Erro de leitura do arquivo \"%s\"", file_nm);
	}

	t_push (tcp_fd);

	close (fd);

}	/* end file_copy */
Example #6
0
/*
 * Read the contents of the endbuffer,  write each record to the
 * transport endpoint (to the server process), then read a ACKs back from
 * the transport endpoint and print it on the standard output.
 */
void
process_client_service(int tfd, struct t_call *callptr,
                        char *recbuffer, int length)
{
    static SEQNO_dt current_seqnum, last_seqnum;
    int n, total_msg; 
    int flags;
    struct gs_record_hdr hdr;
    char sendBuffer[4096];

    int total_l, l, hl;
    l = length;
    hl = sizeof(struct gs_record_hdr);
    total_l = l + hl;

    /* make socket connection to server */
	if (t_connect(tfd, callptr, (struct t_call *) 0) < 0)
    {
        printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
		printf("!!! WORNING:Client can't connect to server...          !!!\n");
        printf("!!!  Is the server running? or                         !!!\n");
        printf("!!!  Is the server host and port specified for client? !!!\n"); 
        printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        return;
    }
    else
    {
       printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
       printf("!!! Client: Connecting to server... !!!\n");
       printf("!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
       if(t_rcv(tfd, (char*)&last_seqnum, sizeof(SEQNO_dt), &flags) >  0)
       {
          /* now ACKs completed.*/
          current_seqnum = htonl(last_seqnum);
          current_seqnum++;
          printf( "**ACK: connected to server and rcvd seq nums %d\n",
                 last_seqnum);
       }
       else
       {
           printf( "**ACK: server DID NOT sent back seq nums %d to %d\n",
                 last_seqnum, current_seqnum);
       }
    }

    total_msg = 0;
    for(int i=0; i< MaxNumSend; i++)
    {
       /* build header with the seqno and size, and data buffer */
       current_seqnum = htonl(last_seqnum)+1;
       hdr.length =  htons(l);
       hdr.sequence_no = htonl(current_seqnum);
       memcpy(sendBuffer, &hdr, hl);
       memcpy(sendBuffer+hl, recbuffer, l);

       /* assume the connection is on, or we can check it if we want 
          using t_look(fd) */
       if( n = t_snd( tfd, sendBuffer, total_l, NULL) != total_l)
       {
          printf( "t_snd fails:  record length is %d, but was sent %d\n", length, n);
       }
       else
       {
          printf( " ##Client sent data %d bytes for seqno = %d\n",
                   length, hdr.sequence_no);

          if(t_rcv(tfd, (char*)&last_seqnum, sizeof(SEQNO_dt), &flags) >  0)
          {
             /* now ACKs completed.*/
             printf( "**ACK: Server processed data SUCCESSFULLY for seqno = %d\n",
                                                  last_seqnum);
             total_msg++;
          }
          else
          {
              continue;
          }
       } /* end if for send */
    } /* end for-loop*/
   
    printf("************************************************\n");
    printf("*  Result: # of msg sent and processed = %d\n", total_msg);
    printf("************************************************\n"); 
}
Example #7
0
int
nlsrequest(int fd, char *svc_code)
{
	int	len, err, flags;
	char 	buf[256];
	char	*p;
	int	ret;
	extern  int t_errno;

	t_errno = 0;		/* indicates a 'name' problem	*/
	buf[0] = 0;

	/*
	 * Validate service code
	 */

	if (!svc_code || !strlen(svc_code) ||
	    (strlen(svc_code) >= (size_t)SVC_CODE_SZ)) {
		if (_nlslog) {
			fprintf(stderr,
			    "nlsrequest: invalid service code format\n");
		}
		return (-1);
	}

	/*
	 * send protocol message requesting the service
	 */

	len = sprintf(buf, nls_v2_msg, svc_code) + 1; /* inc trailing null */

	if (t_snd(fd, buf, len, 0) < len) {
		if (_nlslog)
			t_error("t_snd of listener request message failed");
		return (-1);
	}

	p = _nlsbuf;
	len = 0;

	do {
		if (++len > sizeof (_nlsbuf)) {
			if (_nlslog) {
				fprintf(stderr,
				    "nlsrequest: _nlsbuf not large enough\n");
			}
			return (-1);
		}
		if (t_rcv(fd, p, sizeof (char), &flags) != sizeof (char)) {
			if (_nlslog) {
				t_error("t_rcv of listener response msg "
				    "failed");
			}
			return (-1);
		}

	} while (*p++ != '\0');


	if ((p = strtok(_nlsbuf, ":")) == NULL)
		goto parsefail;

	/*
	 * We ignore the version number here as we do not have any use for it.
	 * Previous versions of the code looked at it by calling atoi() on it,
	 * which did not mutate the actual string and did not use it.
	 */

	if ((p = strtok(NULL, ":")) ==  NULL)
		goto parsefail;
	ret = atoi(p);
	_nlsrmsg = p + strlen(p) + 1;
	if (ret && _nlslog)
		fprintf(stderr, "%s\n", _nlsrmsg); /* debug only */
	return (ret);

parsefail:
	if (_nlslog) {
		fprintf(stderr,
		    "nlsrequest: failed parse of response message\n");
	}
	return (-1);
}