- From: "Javier Acuña" <javier.acuna AT sixbell.cl>
- To: <discussion AT sctp.de>
- Subject: [SCTP-Discussion] Problem on ext_select
- Date: Fri Feb 17 04:22:31 2006
- List-id: SCTP Discussions <discussion.sctp.de>
Hi, it's me again. I'm attaching the source code that created the problem I
mentioned in the previous message.
I'm not sure if it would be helpful, since it's only the part that deals with
sctp, not the full source code, but at least it should show how I called the
ext_... functions.
Other details: Both instances of sctp running on the same Debian machine.
Kernel 2.6.15-1-686.
socketapi version 1.7.0
sctplib version 1.0.4
Best Regards
Javier Acuña
________________________________________________________________
Mensaje enviado desde el Servicio Webmail del Dominio sixbell.cl
_____________________________
La informacion contenida en esta transmision es confidencial, y no puede ser
usada por otras personas que su(s) destinatario(s). El uso no autorizado de
la informacion contenida en esta transmision puede ser sancionado. Si ha
recibido esta transmision por error, por favor destruyala y notifique al
remitente telefonicamente, con cobro revertido o via e-mail.
The information contained in this transmission is privileged, and may not be
used by any person other than its addressee(s). Unauthorized use of the
information contained in this transmission may be punished by law. If
received in error, please destroy and notify the sender by calling collect or
by e-mail.
_____________________________#include <sctp.h>
#include <ext_socket.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <string.h>
#include <stdio.h>
#include <errno.h>
extern FILE *tpLogFile;
assoc_ctx_t assoc_table[MAX_ASSOC];
fd_set readfds;
/***************************************************************************
** This function return's assoc id after creating context.
****************************************************************************/
int make_assoc(int fid,int tid){
int idx = fid*MAX_REMOTE_EP + tid;
if (0 == assoc_table[idx].e_state) {
assoc_table[idx].e_state = 1;
assoc_table[idx].from = fid;
assoc_table[idx].to = tid;
FD_SET(from[fid].sockid, &readfds);
/* fprintf(stderr,"\t FD_SETTING socket = %d \n\n", from[fid].sockid );
fflush(stderr);*/
return idx;
}
return -1;
}
/***************************************************************************
** Create a local endpoint
****************************************************************************/
int make_lep(sctp_addr_t addr){
int idx;
struct sockaddr_in *paddr;
for (idx = 0; idx < MAX_LOCAL_EP; idx++) {
if (0 == from[idx].e_state) {
paddr = (struct sockaddr_in*)&from[idx].addr;
paddr->sin_family = AF_INET;
paddr->sin_port = htons(addr.port);//htons(7);
paddr->sin_addr.s_addr = addr.ipaddr;//INADDR_ANY;
/* paddr->sin_port = htons(addr.port);
paddr->sin_addr.s_addr = addr.ipaddr;*/
from[idx].e_state = 1;
#ifdef ONE_TO_ONE
int res = ext_socket(AF_INET, SOCK_STREAM, IPPROTO_SCTP); /* SCTP
*/
perror("\t\t ext_socket()");
if (res < 0 ){
fprintf(stderr ,"%s %d, ext_socket ERROR, res = %d \n",
__FILE__,__LINE__, res );
perror ("ext_socket");
fflush( stderr );
} else{
from[idx].sockid = res;
}
#endif
#ifdef ONE_TO_N
int res = ext_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP); /*
SCTP */
/* fprintf(stderr ,"\t\t \t %s %d res = %d \n", __FILE__,__LINE__,
res );
fflush( stderr );*/
perror("\t\t ext_socket()");
if (res < 0 ){
fprintf(stderr ,"%s %d, ext_socket ERROR, res = %d \n",
__FILE__,__LINE__, res );
perror ("ext_socket");
fflush( stderr );
} else{
from[idx].sockid = res;
}
#endif
res = ext_bind( from[idx].sockid, (struct
sockaddr*)&from[idx].addr, sizeof(struct sockaddr) );/* SCTP */
perror("\t\t ext_bind()");
if (-1 == res) {
fprintf(tpLogFile,"ERRNO:%d\n", errno);
fflush( tpLogFile);
perror("E_bind_Fail");
return -1;
}
return idx;
}
}
return -1;
}
/***************************************************************************
** Create a remote endpoint
****************************************************************************/
int make_rep(sctp_addr_t addr){
int idx;
struct sockaddr_in *paddr;
for (idx = 0; idx < MAX_REMOTE_EP; idx++) {
if (0 == to[idx].e_state) {
paddr = (struct sockaddr_in*)&to[idx].addr;
paddr->sin_family = AF_INET;
paddr->sin_port = htons(addr.port);//htons(7);
paddr->sin_addr.s_addr = addr.ipaddr;
// paddr->sin_addr.s_addr = INADDR_ANY;
/* paddr->sin_port = htons(addr.port);
paddr->sin_addr.s_addr = addr.ipaddr;*/
to[idx].e_state = 1;
return idx;
}
}
return -1;
}
/***************************************************************************
** Initialise transport data structures.
****************************************************************************/
int init_transport(){
int idx;
/* fprintf(stderr,"\t \t FD_ZEROING \n\n");
fflush(stderr);*/
FD_ZERO(&readfds);
/* fprintf(stderr,"\t \t FD_ZEROING \n\n");
fflush(stderr);*/
for (idx = 0; idx < MAX_LOCAL_EP; idx++)
memset((void *)&from[idx], 0, sizeof(ep_addr_t));
for (idx = 0; idx < MAX_REMOTE_EP; idx++)
memset((void *)&to[idx], 0, sizeof(struct sockaddr));
for (idx = 0; idx < MAX_ASSOC; idx++)
assoc_table[idx].e_state = 0;
/* create thread to receive messages
pthread_create(&recv_thr, NULL, waitfor_message, NULL); */
return 0;
}
/***************************************************************************
** Used by M3UA to send messages on the specified assoc/stream combination.
****************************************************************************/
m3_s32 m3ua_sendmsg(m3_u32 assoc_id, m3_u32 stream_id, m3_u32 msglen, m3_u8
*pmsg){
int ret;
int tid = assoc_table[assoc_id].to;
int fid = assoc_table[assoc_id].from;
fprintf(tpLogFile,"%s:%d SEND!! FID =%d, TID = %d, assoc_id =
%d\n",__FUNCTION__, __LINE__, fid, tid, assoc_id);
fflush( tpLogFile);
// perror("\t\tpre ext_sendto");
//#ifdef __M3UA_PRINT_OUTGOING_MESSAGE__
int m_idx, byte;
fprintf(tpLogFile,"\n<------ Outgoing Message ------>\n");
fprintf(tpLogFile,"\n Number of Bytes in Message = %d\n", msglen);
fprintf(tpLogFile,"%s:%d FID =%d, TID = %d\n",__FUNCTION__, __LINE__,
fid, tid);
fflush( tpLogFile);
for (m_idx = 0; m_idx < msglen; ) {
byte = pmsg[m_idx++];
fprintf(tpLogFile,"%02x ", byte);
fflush( tpLogFile);
if (0 == m_idx%4) {
fprintf(tpLogFile,"\n");
fflush( tpLogFile);
}
}
//#endif
fprintf(stderr,"\t\t SENDTO socket = %d \n\n", from[fid].sockid );
fflush(stderr);
/* perror("\t\tpre ext_sendto");*/
ret = ext_sendto(from[fid].sockid, pmsg, msglen, 0, (struct
sockaddr*)&to[tid].addr, sizeof(struct sockaddr));/*SCTP */
// perror("\t\tpost ext_sendto");
if (-1 == ret) {
fprintf(tpLogFile,"ERRNO:%d\n", errno);
fflush( tpLogFile);
perror("E_sendto_Fail");
perror("E_sendto_Fail");
perror("E_sendto_Fail"); return -1;
// exit(1);
}
return 0;
}
/***************************************************************************
** Receive messages
****************************************************************************/
void* m3uaWaitForMessage(void *not_used)
{
int ret;
struct timeval timeout;
int idx;
fd_set rfds;
m3ua_mgmt_ntfy_t ntfy;
m3ua_user_ntfy_t u_ntfy;
unsigned char msg[1024];
unsigned int msglen = 0;
fprintf(tpLogFile,"%s %d\n", __FUNCTION__,__LINE__ );
fflush( tpLogFile);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
/* while(1) {
* removed, since the loop now is done in encaps.c */
fprintf(tpLogFile,"%s %d \n", __FUNCTION__,__LINE__);
fflush(tpLogFile);
if (0 == timeout.tv_sec && 0 == timeout.tv_usec) {
fprintf(tpLogFile,"%s %d \n", __FUNCTION__,__LINE__);
fflush( tpLogFile);
timeout.tv_sec = 1;
timeout.tv_usec = 0;
}
rfds = readfds;
/* fprintf(stderr,"\t FD_SETSIZE = %d \n\n", FD_SETSIZE);
fprintf(stderr,"\t FD_ISSET(1023) = %d \n\n", FD_ISSET(1023, &rfds));
fprintf(stderr,"\t FD_ISSET(1025) = %d \n\n", FD_ISSET(1025, &rfds));
fflush(stderr);*/
ret = ext_select(FD_SETSIZE, &rfds, NULL, NULL, &timeout); /*SCTP*/
// perror("\t\tselect()");
if (0 == ret) {
fprintf(tpLogFile,"%s %d \n", __FUNCTION__,__LINE__);
fflush( tpLogFile);
timeout.tv_sec = 0;
timeout.tv_usec = 0;
m3timer_ckexpiry(NULL);
// um3_timer_ckexpiry(NULL);
}
else if (0 < ret) {
for (idx = 0; idx < MAX_LOCAL_EP; idx++)
if (1 == from[idx].e_state && FD_ISSET(from[idx].sockid,
&rfds)){
fprintf(tpLogFile,"%s %d \n", __FUNCTION__,__LINE__);
fflush( tpLogFile);
get_message(idx, from[idx].sockid, msg, &msglen);
}
}
else {
fprintf(tpLogFile,"ERRNO:%d\n", errno);
fflush( tpLogFile);
perror("E_select_Fail");
exit(1);
}
while (-1 != m3ua_mgmt_ntfy(&ntfy)) {
fprintf(tpLogFile,"%s %d\n", __FILE__,__LINE__ );
fflush( tpLogFile);
processMgmtNtfy(&ntfy);
}
while (-1 != m3ua_user_ntfy(&u_ntfy)) {
fprintf(tpLogFile,"%s %d\n", __FILE__,__LINE__ );
fflush( tpLogFile);
processUserNtfy(&u_ntfy);
}
//}
return NULL;
}
/***************************************************************************
** read message from socket and pass it to M3UA
****************************************************************************/
int get_message(int fid,int sockid,unsigned char msg[1024],unsigned int
*pmsglen){
int idx;
int tid;
struct sockaddr_in addr;
int from_len = sizeof(struct sockaddr);
memset(&addr, 0, sizeof(struct sockaddr));
*pmsglen = ext_recvfrom(sockid, msg, 1024, 0, (struct sockaddr*)&addr,
&from_len); /* SCTP */
fprintf(tpLogFile,"%s %d,GET!! *pmsglen = %d, fid=%d \n",
__FILE__,__LINE__, *pmsglen, fid);
fflush( tpLogFile);
fprintf(stderr,"%s %d,GET!! *pmsglen = %d, fid=%d \n", __FILE__,__LINE__,
*pmsglen, fid);
fflush(stderr );
if (0 < *pmsglen) {
/* search for association for which data is received */
for (idx = 0; idx < MAX_REMOTE_EP; idx++) {
if (1 == assoc_table[fid*MAX_REMOTE_EP + idx].e_state) {
tid = assoc_table[fid*MAX_REMOTE_EP + idx].to;
if (to[tid].addr.sin_family == addr.sin_family &&
to[tid].addr.sin_port == addr.sin_port &&
to[tid].addr.sin_addr.s_addr == addr.sin_addr.s_addr) {
fprintf(tpLogFile,"%s %d, calling m3ua_recvmsg \n",
__FILE__,__LINE__ );
fflush( tpLogFile);
fprintf(stderr ,"%s %d, calling m3ua_recvmsg \n",
__FILE__,__LINE__ );
fflush( stderr );
m3ua_recvmsg(idx, 0, *pmsglen, msg);
}
}
}
}
return 0;
}
Archive powered by MHonArc 2.6.19+.