hi, 

i'm using a uclinux on h8 arch. i'm running 2.4.x
kernel with sctp module, developed by openss7.

i'm trying to send a file through a sctp socket. it
seems
to work, but at the end i'm getting an abort chunk
from the client. there is no proper shutdown. the
client just send abort. the server prints an error: 
accept: Software caused connection abort.
the client/server buffers are i.e 256. the last sent
data chunk is i.e 6. i'm having non-block mode.  
 
i have attached client and server code and a
capture. 

could somebody give me any clue how to fix this
problem?
  
greetings
magda
        

--

With your feet on the air and your head on the ground 
Try this trick and spin it, yeah 
Your head will collapse if there's nothing in it 
And you'll ask yourself 

Where is my mind?
Where is my mind?
Where is my mind?


      Lesen Sie Ihre E-Mails auf dem Handy.
www.yahoo.de/go
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <signal.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>
#include <sys/uio.h>
#include <sys/sysinfo.h>
int nodelay =1;
#define HOST_BUF_LEN 256
char buf[HOST_BUF_LEN];
int init_server(int port){
	struct sockaddr_in addr;
        int sd;                                        
	
	addr.sin_family = PF_INET;
	addr.sin_addr.s_addr = INADDR_ANY;
	addr.sin_port = htons(port);
	if( (sd=socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0 ) {
		perror("socket failed\n");
		return(-1);
		
	}
	
	if( bind( sd, (struct sockaddr *)&addr,sizeof(addr) ) == -1 ) {
		perror("bind");
		goto errout;
       		exit(1);
	}
	else printf("binded\n");
	if (listen(sd, 1)==-1) {
		printf("not listening...\n");
       	        goto errout;
	}
       	else printf("listening...\n");
	return sd;
	errout:
		close(sd);
		return(-1);
}
void serve(int listener){
	fd_set master;  // master file descriptor list
        fd_set read_fds; //temp file descriptor list for select()
	//struct sockaddr_in myaddr;     //server address
	struct sockaddr_in remoteaddr; //client address
	int fdmax;      //  maximum file descriptor number
	//int listener;//     listening socket descriptor
	int newfd;     //   newly accept()ed socket descriptor
	char buf[HOST_BUF_LEN];   // buffer for client data
	int nbytes;
	int addrlen;
	int i ;
	FD_ZERO(&master); //   clear the master and temp sets
	FD_ZERO(&read_fds);
	FD_SET(listener, &master);
	//keep track of the biggest file descriptor
	fdmax = listener; //so far, it's this one
	//main loop
	for(;;) {
		read_fds = master; //copy it
		if (select(fdmax+1, &read_fds, NULL, NULL, NULL) == -1) {
			perror("select");
			exit(1);
		}

		//run through the existing connections looking for data to read
		for(i = 0; i <= fdmax; i++) {
			
			if (FD_ISSET(i, &read_fds)) { //we got one!!
				if (i == listener) {
					//handle new connections
					addrlen = sizeof remoteaddr;
					if ((newfd = accept(listener, (struct sockaddr *)&remoteaddr, &addrlen)) == -1) { 
						perror("accept");
					} else {
						if (fcntl(i, F_SETFL, O_NONBLOCK) < 0) {
							perror("fcntl");
						}
						if (setsockopt(i, SOL_SCTP, SCTP_NODELAY, &nodelay, sizeof(nodelay)) < 0) {
							perror("setsockopt");
						}
						FD_SET(newfd, &master); //add to master set
						if (newfd > fdmax) {    //keep track of the maximum
							fdmax = newfd;
						}
					}
				} else {
					//handle data from a client
					
					if ((nbytes = recv(i, buf, sizeof buf, MSG_DONTWAIT )) <= 0) {
						//got error or connection closed by client
						if (nbytes == 0) {
							//connection closed
							printf("selectserver: socket %d hung up\n", i);
						} else {
							perror("recv");
						}
						close(i); //bye!
						FD_CLR(i, &master); //remove from master set
					} else {
						
						fwrite(buf,nbytes,1,stdout);
					}
				} 
			}
		}
	}
}
int main(int argc, char *argv[]){
	serve(init_server(atoi(argv[1])));

	return 1;
}
#include <stdio.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <asm/ioctls.h>
#include <linux/sockios.h>
#include <netinet/in.h>
#include <netinet/sctp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/poll.h>
#include <sys/time.h>
#include <signal.h>
#include <getopt.h>
#include <stdlib.h>
#include <string.h>

int nodelay = 1;
#define HOST_BUF_LEN 256
int init_client(int port, char *ip) {
	int sd;       
	static struct sockaddr_in addr ;
	addr.sin_family = AF_INET;
	addr.sin_port = htons(port);
	addr.sin_addr.s_addr = inet_addr(ip);
	if ((sd = socket(PF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) < 0) {
		perror("socket");
	}
               
        if(connect(sd,(struct sockaddr *)&addr,sizeof(addr)) < 0) {
        	perror("connect");
        	return(-1);
        }
        if (fcntl(sd, F_SETFL, O_NONBLOCK) < 0) {
        	perror("fcntl");
        	goto errout;
        }
        if (setsockopt(sd, SOL_SCTP, SCTP_NODELAY, &nodelay, sizeof(nodelay)) < 0) {
        	perror("setsockopt");
        	goto errout;
        }
	return sd;
	errout:
		close(sd);
		return(-1);
}
void print_param(int sd) {
	char buf[HOST_BUF_LEN];
	int read_b;
        while((read_b = fread(buf, 1, sizeof(buf), stdin))){
	       if ((send(sd, buf, read_b, 0)) == -1) {
			perror("send");
		}
	       
        }
        perror("");
	
	close (sd);
}
int usage(int argc){
	if(argc != 3) {
                printf ("usage: client dest_ip\n");
                return (-1);
        }
	return 1;
}
int main(int argc,char *argv[]) {
	if(usage(argc) > 0 ){
		int sock;
		if ((sock = init_client(atoi(argv[1]), argv[2])))	print_param(sock) ;
	}	
	return 1;
}

Attachment: capture
Description: pat1879605220

_______________________________________________
uClinux-dev mailing list
[email protected]
http://mailman.uclinux.org/mailman/listinfo/uclinux-dev
This message was resent by [email protected]
To unsubscribe see:
http://mailman.uclinux.org/mailman/options/uclinux-dev

Reply via email to