#include #include #include #include #include #include #include #include #include #include #include /* IPv6 AF_INET6 sockets: struct sockaddr_in6 { u_int16_t sin6_family; // address family, AF_INET6 u_int16_t sin6_port; // port number, Network Byte Order u_int32_t sin6_flowinfo; // IPv6 flow information struct in6_addr sin6_addr; // IPv6 address u_int32_t sin6_scope_id; // Scope ID }; struct in6_addr { unsigned char s6_addr[16]; // load with inet_pton() }; */ struct sockaddr_in6 saddr = { sin6_family: AF_INET6, }; struct sockaddr_in6 raddr = { sin6_family: AF_INET6, }; struct in6_addr myaddr = { // fe80:0000:0000:0000:0000:0214:4fff:fe80:db46 {0xfe ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00, 0x02 ,0x14 ,0x4f ,0xff ,0xfe ,0x80, 0xdb, 0x46}, }; char buf[256]; char buf2[16]; int main( int argc, char **argv) { int s; int m; int rc; int addrlen = sizeof(raddr); saddr.sin6_port = htons(3334); // saddr.sin6_flowinfo = htonl(1); // saddr.sin6_scope_id = htonl(2); bcopy(&myaddr, &saddr.sin6_addr, 16); // inet_pton(AF_INET6, "fe80::214:4fff:fe80:db46" , &saddr.sin6_addr); // inet_pton(AF_INET6, "fe80::214:4fff:fe80:db47" , &saddr.sin6_addr); inet_pton(AF_INET6, "fec0::20c:29ff:fecf:5d69" , &saddr.sin6_addr); // inet_pton(AF_INET6, "::1" , &saddr.sin6_addr); s = socket(PF_INET6, SOCK_STREAM, 0); if (s < 0) { perror("socket"); exit(1); } #if 0 rc = setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, "eth0", 8); if (rc < 0) { perror("sockopt"); exit(1); } rc = getsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, buf2, &addrlen); if (rc < 0) { perror("sockopt"); exit(1); } #endif printf("Back from sockopt \n"); saddr.sin6_scope_id = htonl(1); rc = connect(s, (struct sockaddr *)&saddr, sizeof(saddr)); if (rc < 0) { perror("connect"); exit(1); } rc = read(0, buf, sizeof(buf)); while (rc > 0) { write(s, buf, rc); rc = read(0, buf, sizeof(buf)); } }