コード例 #1
0
int TCPSocket::Recvfrom(TCPSocketAddress& addr, 
						TCPBuffer& data, int flags /* = 0 */) throw (TCPException)
{
	int bytes;
	data.Prepare();
	sockaddr_in address = addr;
	bytes = Recvfrom(address,data.Pointer(),data.Size(),flags);
	addr = address;
	data.Update(bytes);
	return bytes;
}
コード例 #2
0
ファイル: udpserver.c プロジェクト: hu010354/kaizer
void dg_echo(int fd,struct sockaddr_in *pcliaddr,socklen_t socklen)
{
	socklen_t len;
	char line[MAXLINE];
	for(;;)
	{
		len = socklen;
		n = Recvfrom(fd,line,MAXLINE,0,pcliaddr,&len);
		Sendto(fd,line,strlen(line),0,pcliaddr,len);
	}
}
コード例 #3
0
ファイル: dg_echo1.c プロジェクト: eaglelzy/unp
void 
dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen) {
	int 	n;
	socklen_t len;
	char 	msg[MAXLINE];
	for ( ; ; ) {
		len = clilen;
		n = Recvfrom(sockfd, msg, MAXLINE, 0, pcliaddr, &len);
		Sendto(sockfd, msg, n, 0, pcliaddr, len);
	}
}
コード例 #4
0
ファイル: server.c プロジェクト: fs302/FileServer
// 等待握手
int WaitShakeHands(char *message, FILE **fp)
{
    printf("Waiting request ...\n");
    Packet fnpack;
    Recvfrom(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, &clen);
    bzero(message, FILE_NAME_MAX_SIZE+1);
    strncpy(message, fnpack.data, fnpack.dataLength>FILE_NAME_MAX_SIZE?FILE_NAME_MAX_SIZE:fnpack.dataLength);
    // dataID==-1 表示下载请求
    if (fnpack.dataID == -1)
    {
        printf("Request File name: %s\n",message);
        *fp = fopen(message, "rb");
        if (NULL == *fp)
        {
            printf("File:\t %s is not found.\n",message);
            fnpack.dataID = -5;
            fnpack.dataLength = 0;
            strncpy(fnpack.data, NULL, 0);
            Sendto(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, clen);
            return -5;
        }
        printf("File:\t %s Open.\n",message);
        fnpack.dataID = -1;
        fnpack.dataLength = 0;
        strncpy(fnpack.data, NULL, 0);
        Sendto(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, clen);
        return 1;
    }// dataID == -2 表示显示目录请求
    else if( fnpack.dataID == -2)
    {
        Sendto(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, clen);
        return 2;
    }// dataID == -3 表示上传请求
    else if( fnpack.dataID == -3)
    {
        // 先验证md5,若存在同md5文件,则启动秒传
        if (check_md5(message)==1) 
        {
            fnpack.dataID = -5;
            fnpack.dataLength = 0;
            strncpy(fnpack.data, NULL, 0);
            Sendto(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, clen);
            return -5;
        }
        else{
            fnpack.dataID = 0; // Wait for packet 0
            fnpack.dataLength = 0;
            fnpack.flag = -1;
            strncpy(fnpack.data,NULL, 0);
            Sendto(server_socket, (char *)&fnpack, sizeof(Packet), 0, (struct sockaddr *)&client_addr, clen);
            return 3;
        }
    }
}
コード例 #5
0
void send_msg(int sockfd, char *msg, const SA *pservaddr, socklen_t servlen)
{
	int	n;
	char	recvline[MAXLINE + 1];
	char *sendline = "hello";
	Sendto(sockfd, msg, strlen(msg), 0, pservaddr, servlen);

	n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);

	recvline[n] = 0;	/* null terminate */
	printf("%s\n", recvline);
}
コード例 #6
0
void exer02_dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
{
    int n;
    socklen_t len;
    char mesg[MAXLINE];

    for (;;) {
        len = clilen;
        n = Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
        Sendto(sockfd, mesg, n, 0, pcliaddr, clilen); /* use clilen instead of len */
    }
}
コード例 #7
0
int isExistsFile(char *fp_filename) {
	char	recvline[MAXLINE];
	struct sockaddr_in	cliaddr;
	socklen_t	cliaddrlen = sizeof(cliaddr);

	Sendto(sockfd2serverfp, fp_filename, strlen(fp_filename), 0, (SA *) &servaddrfp, sizeof(servaddrfp));

	// recv quick reply from POX with timeout
	// struct timeval tv;
	// tv.tv_sec = 2;
	// tv.tv_usec = 0;
	// setsockopt(sockfd4pox, SOL_SOCKET, SO_RCVTIMEO, &tv, sizeof(tv));
	memset(recvline, 0, sizeof(recvline));
	if(sdn_switch){
		Recvfrom(sockfd4pox, recvline, MAXLINE, 0,  (SA *) &cliaddr, &cliaddrlen);
		// printf("=============%s\n", recvline);
	}

	if(strcmp(recvline, "new_file") == 0){ // Bloom filter ,Quick decision
		printf("**File new, so start transfer(POX).**\n");
		return 0;
	}else if(strcmp(recvline, "duplicated") == 0){// cache hit, Quick decision
		printf("**File duplicated, so transfer complete(POX)..**\n");
		return 1;
	}else{// go to server , wait for the reply from server
		memset(recvline, 0, sizeof(recvline));
		if (Recvfrom(sockfd2serverfp, recvline, MAXLINE, 0,  (SA *) &cliaddr, &cliaddrlen)==0)
			err_quit("client: server terminated prematurely");
		 printf("=============%s\n", recvline);
		if(strcmp(recvline, "duplicated") == 0){
			printf("**File duplicated, so transfer complete..**\n");
			return 1;
		}else{
			printf("**File new, so start transfer..**\n");
			return 0;
		}
	}

	return -1; // cannot get here
}
コード例 #8
0
ファイル: server.c プロジェクト: fs302/FileServer
int main(int argc, char *argv[])
{
    initConnection();
    for(;;)
    {
        char message[BUFFER_SIZE];
        FILE *fp = NULL;
        int req_num = 0;
        req_num = WaitShakeHands(message, &fp);
        // req_num 对应请求的dataID:1表示下载,2表示显示目录,3表示上传。若req_num<0,则无须后续传输。
        if ( req_num==1 )
        {
            Packet req;
            Recvfrom(server_socket, (char *)&req, sizeof(Packet),0, (struct sockaddr *)&client_addr, &clen);
            if ( req.dataID == 0 && req.flag ==-1)
                Transfer(server_socket, client_addr,&fp);
        }
        else if (req_num == 2)
        {
            Packet req;
            Recvfrom(server_socket, (char *)&req, sizeof(Packet),0, (struct sockaddr *)&client_addr, &clen);
            if ( req.dataID == 0 && req.flag ==-1)
                Show_dir(server_socket, client_addr);
        }
        else if (req_num == 3)
        {
            char file_name[BUFFER_SIZE],md5sum[33]={'\0'};
            int filesize;
            sscanf(message,"%s\t%d\t%s",file_name,&filesize,md5sum);
            fp = fopen(file_name, "wb");
            if (NULL == fp){
                printf("File:\t %s can not open to write.\n",file_name);exit(1);}
            printf("Begin Recvfile.\n");
            FileReceive(server_socket, client_addr,&fp);
            fclose(fp);
        }
        printf("Finished.\n");
    }
    return 0;
}
コード例 #9
0
ファイル: app.c プロジェクト: homfos/app
void dg_echo(int sockfd, struct sockaddr *pcliaddr, socklen_t clilen)
{
	char buf[100];
	int	n;

	for ( ; ; )
	{
		n = Recvfrom(sockfd, buf, 100, 0, pcliaddr, &clilen);

		Sendto(sockfd, buf, n, 0, pcliaddr, clilen);
	}
	
}
コード例 #10
0
void  sigio_dg_cli(FILE *fp, int sockfd, SA *pservaddr, socklen_t servlen)
{
    int n;
    char sendline[MAXLINE], recvline[MAXLINE+1];

    while (Fgets(sendline, MAXLINE, fp) != NULL) {
        Sendto(sockfd, sendline, strlen(sendline), 0,
                pservaddr, servlen);
        n = Recvfrom(sockfd, recvline, MAXLINE, 0, NULL, NULL);
        recvline[n] = 0; /* null terminate */
        Fputs(recvline, stdout);
    }
}
コード例 #11
0
int 
main(int argc, char **argv) 
{ 
	int sockfd; 
	ssize_t n; 
	char buff[MAXLINE]; 
	time_t ticks; 
	socklen_t len; 
	struct sockaddr_storage cliaddr; 
	struct addrinfo hints, *res;
	int on = 1;
	
	if (argc == 2) 
		sockfd = Udp_server(NULL, argv[1], NULL); 
	else if (argc == 3) {
		bzero(&hints, sizeof(struct addrinfo));
		hints.ai_flags = AI_PASSIVE;
		hints.ai_family = AF_UNSPEC;
		hints.ai_socktype = SOCK_DGRAM;

		if ( ( n = getaddrinfo(argv[1], argv[2], &hints, &res)) != 0)
			err_quit("udp_server error for %s, %s: %s",
				 argv[1], argv[2], gai_strerror(n));
	
		do {
			sockfd = socket(res->ai_family, res->ai_socktype,
					res->ai_protocol);
			if (sockfd < 0)
				continue; /* error - try next one */
			Setsockopt(sockfd, SOL_SOCKET, SO_REUSEADDR,
				   &on, sizeof(on));
			if (bind(sockfd, res->ai_addr, res->ai_addrlen) == 0)
				break; /* success */
			Close(sockfd);
		} while ( (res = res->ai_next) != NULL);

		if (res == NULL)
			err_sys("udp_server error");
	} else 
		err_quit("usage: daytimeudpsrv [ <host> ] <service or port>"); 
 
	for ( ; ; ) { 
		len = sizeof(cliaddr); 
		n = Recvfrom(sockfd, buff, MAXLINE, 0, (SA *)&cliaddr, &len); 
		printf("datagram from %s\n", Sock_ntop((SA *)&cliaddr, len)); 
 
		ticks = time(NULL); 
		snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks)); 
		Sendto(sockfd, buff, strlen(buff), 0, (SA *)&cliaddr, len); 
	} 
} 
コード例 #12
0
ファイル: dg_cli03.c プロジェクト: crazy-canux/cAPI
void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen)
{
    int n, maxfdp1;
	const int on = 1;
	char sendline[MAXLINE], recvline[MAXLINE+1];
	fd_set rset;
	socklen_t len;
	struct sockaddr *preply_addr;

	preply_addr = (struct sockaddr *)Malloc(servlen);

	Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));

	Pipe(pipefd);
	maxfdp1 = max(sockfd, pipefd[0]) + 1;
	FD_ZERO(&rset);

	Signal(SIGALRM, recvfrom_alarm);

	while (Fgets(sendline, MAXLINE, fp) != NULL)
	{
		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);
		
		alarm(5);
		for ( ; ; )
		{
			FD_SET(sockfd, &rset);
			FD_SET(pipefd[0], &rset);
			if ((n = select(maxfdp1, &rset, NULL, NULL, NULL)) < 0)
			{
				if (errno = EINTR)
					continue;
				else
					err_sys("select error");
			}
			if (FD_ISSET(sockfd, &rset))
			{
				len = servlen;
				n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);
				recvline[n] = 0;
				printf("from %s: %s", (char *)Sock_ntop_host(preply_addr, len), recvline);
			}
			if (FD_ISSET(pipefd[0], &rset))
			{
				Read(pipefd[0], &n, 1); /* time out */
				break;
			}
		}
	}
	free(preply_addr);
}
コード例 #13
0
//struct incoming_msg_info 
void msg_recv(rsockfd)
{
 
 struct incoming_msg_info rincoming_msg;
	struct sockaddr_un	cliaddr;
	socklen_t	clilen=sizeof(cliaddr);
 
 int n=Recvfrom(rsockfd, recvbuff, MAXLINE, 0, (SA *) &cliaddr, &clilen);
    printf("\n %d bytes received !Sender's addr is %s Msg is %s",n,cliaddr.sun_path,recvbuff);
    
    
//    return (rincoming_msg);
    
}
コード例 #14
0
ファイル: dg_cli01.c プロジェクト: crazy-canux/cAPI
void dg_cli(FILE *fp, int sockfd, const SA *pservaddr, socklen_t servlen)
{
	int n;
	const int on = 1;
	char sendline[MAXLINE], recvline[MAXLINE + 1];
	fd_set rset;
	sigset_t sigset_alrm, sigset_empty;
	socklen_t len;
	struct sockaddr *preply_addr;

	preply_addr = (struct sockaddr *)Malloc(servlen);

	Setsockopt(sockfd, SOL_SOCKET, SO_BROADCAST, &on, sizeof(on));

	FD_ZERO(&rset);

	Sigemptyset(&sigset_empty);
	sigemptyset(&sigset_alrm);
	Sigaddset(&sigset_alrm, SIGALRM);

	Signal(SIGALRM, recvfrom_alarm);

	while (Fgets(sendline, MAXLINE, fp) != NULL)
	{
		Sendto(sockfd, sendline, strlen(sendline), 0, pservaddr, servlen);

		Sigprocmask(SIG_BLOCK, &sigset_alrm, NULL);
		alarm(5);
		for ( ; ; )
		{
			FD_SET(sockfd, &rset);
			n = pselect(sockfd+1, &rset, NULL, NULL, NULL, &sigset_empty);
			if (n < 0)
			{
				if (errno = EINTR)
					break;
				else
					err_sys("pselect error");
			}
			else if (n != 1)
				err_sys("pselect error: returned %d", n);

			len = servlen;
			n = Recvfrom(sockfd, recvline, MAXLINE, 0, preply_addr, &len);
			recvline[n] = 0; //null terminate
			printf("from %s: %s", (char *)Sock_ntop_host(preply_addr, len), recvline);
		}
	}
	free(preply_addr);
}
コード例 #15
0
ファイル: udpserv01.c プロジェクト: 4179e1/misc
void dg_echo (int sockfd, struct sockaddr *cliaddr, socklen_t clilen)
{
	int n;
	socklen_t len;
	char mesg[MAXLINE];

	for (;;)
	{
		len = clilen;
		n = Recvfrom (sockfd, mesg, MAXLINE, 0, cliaddr, &len);

		Sendto (sockfd, mesg, n, 0, cliaddr, len);
	}
}
コード例 #16
0
ファイル: dgecholoop1.c プロジェクト: algebra1415011/unp
void dg_echo2(int sockfd, SA *pcliaddr, socklen_t clilen)
{
  socklen_t len;
  char mesg[MAXLINE];

  Signal(SIGINT, recvfrom_int);

  for ( ; ; ) {
    len = clilen;
    Recvfrom(sockfd, mesg, MAXLINE, 0 , pcliaddr, &len);

    count++;
  }
}
コード例 #17
0
ファイル: udpservloop1.c プロジェクト: lixiangbest/c
void dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen){
	int n;
	socklen_t len;
	char mesg[MAXLINE];
	Signal(SIGINT, recvfrom_int);

	n = 220 * 1024;
	Setsockopt(sockfd, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n));

	for(;;){
		len = clilen;
		Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
		count++;
	}
}
コード例 #18
0
ファイル: wrap_socket.c プロジェクト: crazy-canux/cAPI
int recvfrom_timeout_alrm(int sockfd, void *buff, size_t nbytes, int flags, struct sockaddr *from, socklen_t *addrlen, int nsec)
{
	int n;
	Sigfunc *sigfunc;

	sigfunc = Signal(SIGALRM, recvfrom_alrm);
	if (alarm(nsec) != 0)
		err_sys("recvfrom_timeout_alarm: alarm was already set");
 
    n = Recvfrom(sockfd, buff, nbytes, flags, from, addrlen);
    return (n);

	alarm(0);
	Signal(SIGALRM, sigfunc);
}
コード例 #19
0
ファイル: dgclimax.c プロジェクト: lpswj/UNP
void dg_cli(FILE *fp,int sockfd,const SA *pservaddr,socklen_t servlen)
{
	int size;
	char sendline[MAXLINE],recvline[MAXLINE + 1];
	ssize_t n;

	size = 70000;
	Setsockopt(sockfd,SOL_SOCKET,SO_SNDBUF,&size,sizeof(size));
	Setsockopt(sockfd,SOL_SOCKET,SO_RCVBUF,&size,sizeof(size));

	Sendto(sockfd,sendline,MAXLINE,0,pservaddr,servlen);

	n = Recvfrom(sockfd,recvline,MAXLINE,0,NULL,NULL);

	printf("received %d bytes\n",n);
}
コード例 #20
0
ファイル: dg_echo.c プロジェクト: ellison/Network-Programming
void
dg_echo(int sockfd, SA *pcliaddr, socklen_t clilen)
{
	int			n;
	socklen_t	len;
	char		mesg[MAXLINE];

	

	for ( ; ; ) {
		len = clilen;
		Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
		printf("%s",mesg);
	
	}
}
コード例 #21
0
ファイル: wrap_socket.c プロジェクト: crazy-canux/cAPI
/* set timeout for recvfrom() use select() */
int recvfrom_timeout_select(int sockfd, void *buff, size_t nbytes, int flags, struct sockaddr *from, socklen_t *addrlen, int nsec)
{
	int n;
	fd_set rset;
	struct timeval tv;

	FD_ZERO(&rset);
	FD_SET(sockfd, &rset);

	tv.tv_sec = nsec;
	tv.tv_usec = 0;

	Select(sockfd+1, &rset, NULL, NULL, &tv);
	n = Recvfrom(sockfd, buff, nbytes, flags, from, addrlen);

	return (n);
}
コード例 #22
0
ファイル: recv_udp.c プロジェクト: estriz27/myRepo
int main(int argc, char *argv[])
{
  int socket_fd, cc, fsize;
  
	struct sockaddr_in  s_in, from;

	struct { 
		char head; 
		u_long  body; 
		char tail;
	} msg;

  // This creates a socket and assigns is to socket_fd
  socket_fd = socket (AF_INET, SOCK_DGRAM, 0);

  // Writes zeros to s_in for s_in length
  bzero((char *) &s_in, sizeof(s_in));

  // Assigns a protocal to the socket. AF_INET refers to addresses from the internet, specifically IP addresses
  s_in.sin_family = (short)AF_INET;

  // INADDR_ANY is the IPv4 wildcard address. It is usefor for applications that bind Internet domain sockets on mulihomed hosts
  s_in.sin_addr.s_addr = htonl(INADDR_ANY);

  // htons converts MYPORT between host and network byte order
  s_in.sin_port = htons((u_short) MYPORT);

  printsin( &s_in, "RECV_UDP", "Local socket is:"); 
  fflush(stdout);

  // bind assigns a name to an unnamed address. It assigns socket_fd to the socket address
  bind(socket_fd, (struct sockaddr *)&s_in, sizeof(s_in));

  for(;;) {
		fsize = sizeof(from);
    cc = Recvfrom(socket_fd, &msg, sizeof(msg), 0, (struct sockaddr *) &from, &fsize);
    printsin( &from, "recv_udp: ", "Packet from:");

    // Converts between host and network byte order so msg.body can be printed
    printf("Got data ::%c%ld%c\n", msg.head, (long) ntohl(msg.body),
    msg.tail); 
    fflush(stdout);
  }
  
  return 0;
}
コード例 #23
0
ファイル: app.c プロジェクト: homfos/app
void dg_cli(FILE *fp, int sockfd, const struct sockaddr * servaddr, socklen_t servlen)
{
	int	n;
	char	sendbuf[100],	recvbuf[100];

	while (fgets(sendbuf, 100, fp) != NULL)
	{

		Sendto(sockfd, sendbuf, strlen(sendbuf), 0,servaddr, servlen);
		n = Recvfrom(sockfd, recvbuf, 100, 0, NULL, NULL);

		if (fputs(recvbuf, stdout) == EOF)
		{
			err_quit("fputs error");
		}
	}
}
コード例 #24
0
int
main(int argc, char **argv)
{
	int			sockfd;
	ssize_t			n;
	char			buff[MAXLINE];
	time_t			ticks;
	socklen_t		len;
	struct sockaddr_storage	cliaddr;

	if ( argc == 2)
		sockfd = Udp_server( NULL, argv[1], NULL);
	else if ( argc == 3)
		sockfd = Udp_server( argv[1], argv[2], NULL);
	else
		err_quit( "usage: daytimeudpsrv [ <host> ] <service or port>");

	for ( ; ; ) {
            
		len = sizeof(cliaddr);
                /* since socket is unconnected we use Recvfrom and Sendto,
                 * not Read, Write */
		n = Recvfrom(sockfd, buff, MAXLINE, 0, (SA *)&cliaddr, &len);
		printf( "datagram from %s\n", Sock_ntop((SA *)&cliaddr, len));

                /* response */
                time_t rawTime;
                time( &rawTime);
                struct tm * timeInfo;
                timeInfo = localtime( &rawTime);
                strftime( buff, MAXLINE, "cf16 daytime service on port 13. "
                        "The time on this server now is: %A, %B %d, %G %T %p-%Z\n",
                        timeInfo);
    
		//ticks = time(NULL);
		//snprintf(buff, sizeof(buff), "%.24s\r\n", ctime(&ticks));
		Sendto( sockfd, buff, strlen(buff), 0, (SA *)&cliaddr, len);
               /* At this moment we don't know if peer is reachable or not
                * If it is not reachable sendto return Success but Recvfrom
                * will block forever (it doesn't see an ICMP "destination
                * unreachable" packet coming back from peer because socket
                * is unconnected)
                */
	}
}
コード例 #25
0
ファイル: server.cpp プロジェクト: Dronevery/MultiwaySwitch
void *ForwardUDP(void *v) {
    fd_set inputs;
    char buff[BUFFLENGTH];
    while (1) {
        FD_ZERO(&inputs);
        FD_SET(Socket[1], &inputs);
        int result = select(FD_SETSIZE, &inputs, NULL, NULL, NULL);  //wait until some messages arrive
        if (result <= 0)continue;
        if (FD_ISSET(Socket[1], &inputs)) {
            int msglen = Recvfrom(1, &buff[1]);
            printf("!>>Get UDP from local port<<!\n");
            buff[0] = '0' + totalLinkNum;
            //printf("%s\n", buff);
            int LinkNow_t = currLinkNow;
            SendToClient(LinkNow_t, buff, msglen + 1);
        }
    }
}
コード例 #26
0
ファイル: udpserv04.c プロジェクト: kingfree/haut
void mydg_echo(int sockfd, SA* myaddr, socklen_t salen)
{
    int n;
    char mesg[MAXLINE];
    socklen_t len;
    struct sockaddr* cli;

    cli = Malloc(salen);

    for (;;) {
        len = salen;
        n = Recvfrom(sockfd, mesg, MAXLINE, 0, cli, &len);
        printf("child %d, datagram from %s", getpid(), Sock_ntop(cli, len));
        printf(", to %s\n", Sock_ntop(myaddr, salen));

        Sendto(sockfd, mesg, n, 0, cli, len);
    }
}
コード例 #27
0
ファイル: server.c プロジェクト: macrobit/FTP
ssize_t recv_from(int sockfd, struct datagram* ptr_gram,
             const struct sockaddr_in *dest_addr, socklen_t* addrlen) {
    char buf[MAXLINE];
    int recv_flag;
    char* payload;

    Recvfrom(sockfd, ptr_gram->buf, BUFFER_SIZE, 0, (SA*)dest_addr, addrlen);

    get_header(ptr_gram, &recv_flag, 0, 0, 0);
    get_str(ptr_gram, buf, MAXLINE);

    if ((recv_flag & ACK) && !(recv_flag & SYN)) {
        payload = get_payload_ptr(ptr_gram);
        sprintf(buf+strlen(buf), " winsize: %d", *(int*)payload);
    }

    printf("Receive from client[%s:%d] %s\n", inet_ntoa(dest_addr->sin_addr), ntohs(dest_addr->sin_port), buf);
}
コード例 #28
0
void adv_mydg_echo(int sockfd, SA *pcliaddr, socklen_t clilen,
        SA *myaddr)
{
    int n;
    char mesg[MAXLINE];
    socklen_t len;

    for (;;) {
        len = clilen;
        n = Recvfrom(sockfd, mesg, MAXLINE, 0, pcliaddr, &len);
        printf("child %d, datagram from %s",
                getpid(), Sock_ntop(pcliaddr, len));
        printf(", to %s\n", Sock_ntop(myaddr, clilen));

        Sendto(sockfd, mesg, n, 0, pcliaddr, len);
    }

}
コード例 #29
0
ファイル: recv.c プロジェクト: jiayuehua/unpv13e
void
recv_all(int recvfd, socklen_t salen)
{
  int         n;
  char        line[MAXLINE+1];
  socklen_t     len;
  struct sockaddr   *safrom;

  safrom = Malloc(salen);

  for ( ; ; ) {
    len = salen;
    n = Recvfrom(recvfd, line, MAXLINE, 0, safrom, &len);

    line[n] = 0;  /* null terminate */
    printf("from %s: %s", Sock_ntop(safrom, len), line);
  }
}
コード例 #30
0
ファイル: utility.c プロジェクト: ipssshh/ODR
void msg_recv(int sockfd, char *data, char *sourceIP, int *sourcePort)
{
        pckData aPacket;
        socklen_t pckLen, servAddrLen;
        struct sockaddr_un servAddr;

        servAddrLen=sizeof(servAddr);
        pckLen=sizeof(aPacket);
        Recvfrom(sockfd, &aPacket, pckLen, 0,  (struct sockaddr*)&servAddr, &servAddrLen);
        printf("\nrecved pcket \n ");
        memcpy(data,aPacket.data,strlen(aPacket.data));
        data[strlen(data)]='\0';
        memcpy(sourceIP,aPacket.canonicalIP,strlen(aPacket.canonicalIP));
        sourceIP[strlen(sourceIP)]='\0';
        *sourcePort=aPacket.port;

        //printf("\nMessage from server:%s, %s",data,aPacket.data);

}