- From: "P J" <przemekj AT simplusnet.pl>
- To: <discussion AT sctp.de>
- Subject: [SCTP-Discussion] echo client problem - ERROR: SocketAddress::createSocketAddress(sockaddr) - Unknown address family 1023!
- Date: Tue Feb 11 18:27:01 2003
- List-id: SCTP Discussions <discussion.sctp.de>
I have running echo server on port 7 on localhost. It works ok with
sctpterminal, on many streams.
I have written client, which will connect on given stream to this server,
send data and receive it back (echoed by the server), but when i execute it,
it displays error messages:
ERROR: SocketAddress::createSocketAddress(sockaddr) - Unknown address family
1023!
sendmsg: Cannot assign requested address
What is wrong with my code?
Please help.
Przemek.
here is the code (it is also attached as a file to this message):
---code starts---
#include <stdio.h> /* for printf() and fprintf() */
#include <sys/socket.h> /* for socket(), connect(), send(), and recv() */
#include <arpa/inet.h> /* for sockaddr_in and inet_addr() */
#include <stdlib.h> /* for atoi() */
#include <string.h> /* for memset() */
#include <unistd.h> /* for close() */
#include <sys/types.h>
#include <sys/time.h>
#include <ext_socket.h>
#include <net/route.h>
#include <net/if.h>
#include <netinet/in.h>
#include <sctp.h>
#define BUFLEN 100
static void
echo(int fd, int socketModeUDP)
{
// int sock; /* Socket descriptor */
struct sockaddr_in echoServAddr;/* Echo server address */
ssize_t nr;
struct sctp_sndrcvinfo *sinfo; // sri
struct msghdr msg[1];
struct cmsghdr *cmsg;
char cbuf[sizeof (*cmsg) + sizeof (*sinfo)];
char *testbuf; // buf
size_t buflen;
struct iovec iov[1];
size_t cmsglen = sizeof (*cmsg) + sizeof (*sinfo);
char servIP[100];
char echoString[100];
unsigned short echoServPort = 7; /* Echo server port */
strcpy(servIP,"127.0.0.1"); /* server IP address (dotted quad) */
strcpy(echoString,"string to echo"); /* string to echo */
// sin->sin_family = AF_INET;
// sin->sin_port = htons(7);
// sin->sin_addr.s_addr = INADDR_ANY;
/* Allocate the initial data buffer */
buflen = BUFLEN;
if (!(testbuf = malloc(BUFLEN))) {
fprintf(stderr, "out of memory\n");
exit(1);
}
memset(testbuf, 0, sizeof(*testbuf));
memset(&echoServAddr, 0, sizeof(echoServAddr));
echoServAddr.sin_family = AF_INET; /* Internet address family */
/* Server IP address */
echoServAddr.sin_addr.s_addr = inet_addr(servIP);
echoServAddr.sin_port = htons(echoServPort); /* Server port */
/* Set up the msghdr structure */
memset(msg, 0, sizeof (*msg));
msg->msg_name=&fd; /* ptr to socket address structure */
msg->msg_namelen=sizeof(fd);
msg->msg_control = cbuf;
msg->msg_controllen = cmsglen;
msg->msg_flags = 0;
cmsg = (struct cmsghdr *)cbuf;
sinfo = (struct sctp_sndrcvinfo *)(cmsg + 1);
cmsg->cmsg_len = sizeof(struct cmsghdr) + sizeof(struct
sctp_sndrcvinfo);
cmsg->cmsg_level = IPPROTO_SCTP;
cmsg->cmsg_type = SCTP_INITMSG;
sinfo->sinfo_assoc_id = 0;
sinfo->sinfo_stream = 0; /* streamNumber */
sinfo->sinfo_flags = 0;
sinfo->sinfo_ppid = 0; /* ppid */
sinfo->sinfo_context = (uint32_t)NULL;
sinfo->sinfo_timetolive = (unsigned int)-1;
{
sinfo->sinfo_stream=0; // stream nr
sprintf(testbuf,"DATA SENT FROM CLIENT sdfgsdgsdfgsdfgsdfgsdgsdf");
nr=sizeof(testbuf);
iov->iov_base = testbuf;
iov->iov_len = nr;
msg->msg_iov = iov;
msg->msg_iovlen = 1;
msg->msg_flags = 0;
msg->msg_iov->iov_len = sizeof(testbuf);
if (ext_sendmsg(fd, msg, 0) < 0) {
perror("sendmsg");
exit(1);
}
if(socketModeUDP == 0)
ext_close(fd);
}
int main()
{
struct sctp_initmsg *sim;
int fd;
struct sockaddr_in sin[1];
if ((fd = ext_socket(AF_INET, SOCK_SEQPACKET, IPPROTO_SCTP)) == -1) {
perror("socket");
exit(1);
}
/* streams init */
sim->sinit_num_ostreams = 2;
sim->sinit_max_instreams = 2;
sim->sinit_max_attempts = 0; // default
sim->sinit_max_init_timeo = 0;// default
if ( ext_setsockopt(fd, IPPROTO_SCTP, SCTP_INITMSG, sim,
sizeof(*sim))<0 ) {
perror("setsockopt");
}
memset(&sin, 0, sizeof(sin));
sin->sin_family = AF_INET;
sin->sin_port = htons(7);
sin->sin_addr.s_addr = inet_addr("127.0.0.1");
if ( ext_bind(fd,(struct sockaddr *)sin,sizeof(*sin)) <0 ) {
perror("bind");
};
/* send data */
while(1){
echo(fd,1);
}
}
---code ends---
Attachment:
echo_stream_client.c
Description: Binary data
- [SCTP-Discussion] echo client problem - ERROR: SocketAddress::createSocketAddress(sockaddr) - Unknown address family 1023!, P J, 02/11/2003
Archive powered by MHonArc 2.6.19+.