connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments


 
Thread Tools Search this Thread
Top Forums UNIX for Advanced & Expert Users connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments
# 1  
Old 02-26-2009
connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi,
I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime.
To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for bind() (FYI: if i give loopback address ::1 client connect to server and exchange message with server, but if i give ipv6 address like ./ipv6client fe80::21d:9ff:fe17:5d0e client programs comes out with Invalid Arguments problem).
What might be the problem with this SCTP transport. Same Programs if i use with TCP transport works fine. Am i missing any setsocketoptions.
Server Program:
#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <stdarg.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/sctp.h>

void panic(char* msg, ...)
{ va_list ap;
va_start(ap, msg);
vprintf(msg, ap);
va_end(ap);
abort();
}
int main(int count, char *strings[])
{ int sd, portnum;
struct sockaddr_in6 addr;
if ( count == 2 )
portnum = atoi(strings[1]);
else
portnum = 9999;
bzero(&addr, sizeof(addr));
if ( (sd = socket(AF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0 )
panic("socket");
addr.sin6_family = AF_INET6;
addr.sin6_port = htons(portnum);
if ( inet_pton(AF_INET6, "0::0", &addr.sin6_addr) == 0 )
panic("inet_pton");
struct linger linger;
/* Set linger on, to 0 time */
linger.l_onoff = 1;
linger.l_linger = 0;
setsockopt(sd, SOL_SOCKET, SO_LINGER,
(char *)&linger, sizeof(struct linger));
int dummy = 1;
/* Set reuseaddr socket option */
setsockopt(sd, SOL_SOCKET, SO_REUSEADDR,
(void *)&dummy, sizeof(int));
if ( bind(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0 )
panic("bind6");
if ( listen(sd, 15) != 0 )
panic("listen6");
while (1)
{ int sent, size=sizeof(addr);
int client;
char line[100];
client = accept(sd, (struct sockaddr*)&addr, &size);
fprintf(stderr, "Connected: %s port=%d\n",
inet_ntop(AF_INET6, &addr.sin6_addr, line, sizeof(line)),
addr.sin6_port);
do
{
sent = send(client, line, recv(client, line, sizeof(line), 0), 0);
fprintf(stderr, "server=%s", line);
}
while ( sent > 0 && strcmp(line, "bye\n") != 0 );
close(client);
}
}

Client Program:
#include <stdio.h>
#include <errno.h>
#include <resolv.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <stdarg.h>
#include <unistd.h>
#include <netdb.h>
#include <netinet/sctp.h>
#include <sys/uio.h>
void panic(char* msg, ...)
{ va_list ap;
va_start(ap, msg);
vprintf(msg, ap);
va_end(ap);
abort();
}
int main(int count, char *strings[])
{ int sd, portnum, ret, sz;
struct sockaddr_in6 addr;
char line[100];
struct in6_addr ipv6_local;
sctp_assoc_t id;
struct sctp_initmsg init;
if ( count == 3 )
portnum = atoi(strings[2]);
else
portnum = 9999;
bzero(&addr, sizeof(addr));
if ( (sd = socket(PF_INET6, SOCK_STREAM, IPPROTO_SCTP)) < 0 )
panic("socket");
addr.sin6_family = AF_INET6;
addr.sin6_port = (int)htons(portnum);
if ( inet_pton(AF_INET6, strings[1], &addr.sin6_addr) == 0 )
panic("inet_aton");
setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, "eth0\0", 5);
if (connect(sd, (struct sockaddr*)&addr, sizeof(addr)) != 0)
{
perror("?\n");
panic("connect6");
}
do
{
fgets(line, sizeof(line), stdin);
send(sd, line, strlen(line)+1, 0);
recv(sd, line, sizeof(line), 0);
printf("client=%s", line);
}
while ( strcmp(line, "bye\n") != 0 );
close(sd);
}
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

D-Bus: Failed to connect to socket

I'm trying a new distro called KaliBang. After the install I noticed this error is having problems letting multiple applications I have work: (nm-applet:3674): GConf-WARNING **: Client failed to connect to the D-BUS daemon: Did not receive a reply. Possible causes include: the remote... (2 Replies)
Discussion started by: Azrael
2 Replies

2. Programming

Looping connect call for a non blocking socket

will there be any unexpected results on looping connect call for a non blocking socket to determine the connection based on error code. I am getting connection unsuccessful intermittently and so wondering whether is the timeout 500 millisec not sufficient or looping connect cause any unexpected. ... (7 Replies)
Discussion started by: satish@123
7 Replies

3. UNIX for Dummies Questions & Answers

Cannot connect to socket

solaris client report "cannot to socket(code 25)" while trying to backup on veritas netbackup 6.5.5 server (1 Reply)
Discussion started by: EUGINIAM
1 Replies

4. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

5. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

6. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

7. Programming

connect() socket API

Is there any relation between the connect() socket API and the TCP's Transmission Control Block. Also how does connect detect that a socket is in use i.e., EADDRINUSE (1 Reply)
Discussion started by: sunaina
1 Replies

8. Programming

which socket should socket option on be set

Hi all, On the server side, one socket is used for listening, the others are used for communicating with the client. My question is: if i want to set option for socket, which socket should be set on? If either can be set, what's the different? Again, what's the different if set option... (1 Reply)
Discussion started by: blademan100
1 Replies

9. Programming

connect() function in C++ socket programming

Hello All, I have a problem using connect(...) function in C++. I am using SSH from my windows system to connect it to linux server. The program works fine if I run it directly in Linux machine but I need it to run through windows machine. The function returns -1 and so my program terminates. ... (3 Replies)
Discussion started by: smdhd3
3 Replies

10. Programming

Socket Problem

Hi all, I have developed server/client application (using C) and tested it on the same machine .. but when I deploy them on different machines I get connection timeout. Well .. server machine and client machine exists on different network segments, so there is a linux firewall box to route... (3 Replies)
Discussion started by: Agent007
3 Replies
Login or Register to Ask a Question