From: Wei Y. <yj...@cn...> - 2009-02-27 08:37:09
|
chandru.bs chandru rote: > Hi, > > Below is the sample ipv6 server and client programs with SCTP socket > type. When i run these server and client, i do see following on > tshark trace (server is running on fe80::21d:9ff:fe17:5d0e and client > on fe80::213:d3ff:fee7:f511) and i could not able to communication on > this socket. Please guide me though this. > > Also let me know in client program is there a way to avoid > setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, "eth0\0", 5); > This is IPv6 issue. If you want to used IPv6 link local address, your *MUST* special the out device. Use IPv6 global address to aviod use setsockopt(SO_BINDTODEVICE). Regards > 3.953989 fe80::213:d3ff:fee7:f511 -> fe80::21d:9ff:fe17:5d0e SCTP INIT > 3.954051 fe80::21d:9ff:fe17:5d0e -> fe80::213:d3ff:fee7:f511 ICMPv6 > Unreachable (Administratively prohibited) > 15.953438 fe80::213:d3ff:fee7:f511 -> fe80::21d:9ff:fe17:5d0e SCTP INIT > 15.953504 fe80::21d:9ff:fe17:5d0e -> fe80::213:d3ff:fee7:f511 ICMPv6 > Unreachable (Administratively prohibited) > 39.975292 fe80::213:d3ff:fee7:f511 -> fe80::21d:9ff:fe17:5d0e SCTP INIT > .. > > Run server: ./serverexetuable > Running Client: ./clientexecutable <server ipv6 address> > > 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, len; > struct sockaddr_in6 addr; > int idleTime = 20; > > if ( count == 2 ) > portnum = atoi(strings[1]); > else > portnum = 9990; > 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); > addr.sin6_scope_id = 2; > > 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 ) > > if ( sctp_bindx(sd, (struct sockaddr*)&addr, 1, SCTP_BINDX_ADD_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, len, 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 = 9990; > > 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); > addr.sin6_scope_id = 2; > > 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); > } > > Thanks, > Chandru > > ------------------------------------------------------------------------------ > Open Source Business Conference (OSBC), March 24-25, 2009, San Francisco, CA > -OSBC tackles the biggest issue in open source: Open Sourcing the Enterprise > -Strategies to boost innovation and cut costs with open source participation > -Receive a $600 discount off the registration fee with the source code: SFAD > http://p.sf.net/sfu/XcvMzF8H > _______________________________________________ > Lksctp-developers mailing list > Lks...@li... > https://lists.sourceforge.net/lists/listinfo/lksctp-developers > > > > |