abort at the end of data transfer
- From: Magda Muskala <magdafrog@xxxxxxxx>
- Date: Fri, 21 Mar 2008 10:05:22 -0700 (PDT)
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
---------------------------------------------
server
------------------------------------------
#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;
}
----------------------------------------
client
---------------------------------------
#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;
}
------------------------------------------------
capture
-------------------------------------------
No. Time Source Destination
Protocol Info
14885 11200.199016 192.168.1.119 192.168.1.233
SCTP INIT
Frame 14885 (84 bytes on wire, 84 bytes captured)
Linux cooked capture
Internet Protocol, Src Addr: 192.168.1.119 (192.168.1.119), Dst Addr:
192.168.1.233 (192.168.1.233)
Stream Control Transmission Protocol, Src Port: 1031 (1031), Dst Port:
10000 (10000)
Source port: 1031
Destination port: 10000
Verification tag: 0x00000000
Checksum: 0x709a9cc2 (correct CRC32C)
INIT chunk (Outbound streams: 1, inbound streams: 33)
Chunk type: INIT (1)
0... .... = Bit: Stop processing of the packet
.0.. .... = Bit: Do not report
Chunk flags: 0x00
Chunk length: 34
Initiate tag: 0xf31ad461
Advertised receiver window credit (a_rwnd): 65535
Number of outbound streams: 1
Number of inbound streams: 33
Initial TSN: 1641290483
IPv4 address parameter (Address: 192.168.1.119)
Supported address types parameter (Supported types: IPv4)
Chunk padding: 0000
No. Time Source Destination
Protocol Info
14886 11200.285549 192.168.1.233 192.168.1.119
SCTP INIT_ACK
Frame 14886 (156 bytes on wire, 156 bytes captured)
Linux cooked capture
Internet Protocol, Src Addr: 192.168.1.233 (192.168.1.233), Dst Addr:
192.168.1.119 (192.168.1.119)
Stream Control Transmission Protocol, Src Port: 10000 (10000), Dst
Port: 1031 (1031)
Source port: 10000
Destination port: 1031
Verification tag: 0xf31ad461
Checksum: 0x95255afd (correct CRC32C)
INIT_ACK chunk (Outbound streams: 33, inbound streams: 33)
Chunk type: INIT_ACK (2)
0... .... = Bit: Stop processing of the packet
.0.. .... = Bit: Do not report
Chunk flags: 0x00
Chunk length: 108
Initiate tag: 0x65a4fdfd
Advertised receiver window credit (a_rwnd): 32767
Number of outbound streams: 33
Number of inbound streams: 33
Initial TSN: 1705311741
IPv4 address parameter (Address: 192.168.1.233)
State cookie parameter (Cookie length: 76 bytes)
No. Time Source Destination
Protocol Info
14887 11200.286732 192.168.1.119 192.168.1.233
SCTP COOKIE_ECHO
Frame 14887 (128 bytes on wire, 128 bytes captured)
Linux cooked capture
Internet Protocol, Src Addr: 192.168.1.119 (192.168.1.119), Dst Addr:
192.168.1.233 (192.168.1.233)
Stream Control Transmission Protocol, Src Port: 1031 (1031), Dst Port:
10000 (10000)
Source port: 1031
Destination port: 10000
Verification tag: 0x65a4fdfd
Checksum: 0x42ac8772 (correct CRC32C)
COOKIE_ECHO chunk (Cookie length: 76 bytes)
Chunk type: COOKIE_ECHO (10)
0... .... = Bit: Stop processing of the packet
.0.. .... = Bit: Do not report
Chunk flags: 0x00
Chunk length: 80
Cookie: 0001B1830000177065A4FDFDC0A80177C0A801E904072710...
No. Time Source Destination
Protocol Info
14888 11200.809261 192.168.1.233 192.168.1.119
SCTP COOKIE_ACK SACK
Frame 14888 (68 bytes on wire, 68 bytes captured)
Linux cooked capture
Internet Protocol, Src Addr: 192.168.1.233 (192.168.1.233), Dst Addr:
192.168.1.119 (192.168.1.119)
Stream Control Transmission Protocol, Src Port: 10000 (10000), Dst
Port: 1031 (1031)
Source port: 10000
Destination port: 1031
Verification tag: 0xf31ad461
Checksum: 0xb5c67036 (correct CRC32C)
COOKIE_ACK chunk
Chunk type: COOKIE_ACK (11)
0... .... = Bit: Stop processing of the packet
.0.. .... = Bit: Do not report
Chunk flags: 0x00
Chunk length: 4
SACK chunk (Cumulative TSN: 1641290482, a_rwnd: 32767, gaps: 0,
duplicate TSNs: 0)
Chunk type: SACK (3)
0... .... = Bit: Stop processing of the packet
.0.. .... = Bit: Do not report
Chunk flags: 0x00
Chunk length: 16
Cumulative TSN ACK: 1641290482
Advertised receiver window credit (a_rwnd): 32767
Number of gap acknowldgement blocks : 0
Number of duplicated TSNs: 0
No. Time Source Destination
Protocol Info
....
.
- Prev by Date: Re: IRDA to Serial on handheld
- Next by Date: Re: ATmega169 Puzzle
- Previous by thread: adult singles dating taylorsville georgia adult sex dating in albin mississippi adult sex dating in reedsport oregon
- Next by thread: MSPGCC memory mapping problem
- Index(es):
Relevant Pages
|
|