Received: from PACIFIC-CARRIER-ANNEX.MIT.EDU by po7.MIT.EDU (5.61/4.7) id AA05862; Wed, 29 Nov 95 22:59:12 EST
Received: from einstein.technet.sg by MIT.EDU with SMTP
	id AA21250; Wed, 29 Nov 95 22:58:09 EST
Received: from stcs.com.sg (mailhost.scs.com.sg [192.245.59.187]) by einstein.technet.sg (8.6.11/8.6.9) with SMTP id LAA00606 for <proven@mit.edu>; Thu, 30 Nov 1995 11:59:00 +0800
Received: from champagne.stcs.com.sg by stcs.com.sg (5.0/SMI-SVR4)
	id AA14523; Thu, 30 Nov 95 11:56:34 SST
Received: from gin.scs.com by champagne.stcs.com.sg (4.1/SMI-4.1)
	id AA01912; Thu, 30 Nov 95 12:07:56 SST
Date: Thu, 30 Nov 95 12:07:56 SST
From: koo@stcs.com.sg (Koo Chuj How)
Message-Id: <9511300407.AA01912@champagne.stcs.com.sg>
To: proven@MIT.EDU
Subject: pthreads recvfrom
Content-Length: 1680


Hi,
	I'm learning multithreaded programming and I'm using
your pthread library (version 1.6).  When I use the recvfrom
that comes with the library,  I'm able to read incomming messages,
however,  the 5th argument of recvfrom (struct sockaddr*) is
never updated and the 6th argument int* is changed to zero.

	Below is my code,  could you tell me if I've done
something wrong or if this is a recvfrom bug.  I'm using
gcc (2.6.3) on Sunos 4.1.3.  Thanks.
#include <pthread.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <stdio.h>
#include <netinet/in.h>
#include <arpa/inet.h>

#define SERV_PORT 8899

void ReaderThread()
{
int sockfd;
struct sockaddr_in reader;
int n;
char buf[1024];
struct sockaddr from;
int fromlen = sizeof(struct sockaddr);

	if( (sockfd = socket(AF_INET,SOCK_DGRAM,0)) < 0){
		printf( "socket error\n" );
		exit(1);
	}
	memset((char*)&reader,0, sizeof(struct sockaddr_in));
	reader.sin_family = AF_INET;
	reader.sin_port = htons(SERV_PORT);
	reader.sin_addr.s_addr = htonl(INADDR_ANY);
	if(bind(sockfd,(struct sockaddr*)&reader,sizeof(reader)) < 0){
		printf("bind error\n");
		perror("can't bind");
		exit(1);
	}

	for(;;){
		fromlen = sizeof(struct sockaddr);
		printf( "before recvfrom fromlen == %d\n", fromlen );
		n = recvfrom(sockfd,buf,1024,0,&from,&fromlen);
		if(n < 0){
			printf("recvfrom error\n");
			exit(1);
		}
		printf( "fromlen == %d\n", fromlen );
	}
}

main()
{
int n;
pthread_t tid;
	if ( n = pthread_create( &tid, NULL, ReaderThread, NULL ) ){
		printf( "pthread_create returns %d\n", n );
		exit(1);
	}

	if(pthread_join( tid, NULL )){
		printf( "pthread_join error\n" );
		exit(1);
	}
}

Koo, Chuj How  
koo@stcs.com.sg
