- #include <sys/types.h>
- #include <sys/socket.h>
- #include <netinet/in.h>
- #include <netdb.h>
- #include <stdio.h>
- #include <signal.h>
- #include <sys/time.h>
- #include <fcntl.h>
- #include <sys/times.h>
- #include <stdlib.h>
- #include <memory.h>
- /* 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
- {0xfe ,0x80 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00 ,0x00,
- 0x02 ,0x14 ,0x4f ,0xff ,0xfe ,0x80, 0xdb, 0x46},
- };
- struct in6_addr wcaddr = IN6ADDR_ANY_INIT;
- char buf[256];
- 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);
- // bcopy(&wcaddr, &saddr.sin6_addr, 16);
- // inet_pton(AF_INET6, "fe80::214:4fff:fe80:db46" , &saddr.sin6_addr);
- inet_pton(AF_INET6, "fec0::20c:29ff:fecf:5d69" , &saddr.sin6_addr);
- // inet_pton(AF_INET6, "::1" , &saddr.sin6_addr);
- // inet_pton(AF_INET6, "::0" , &saddr.sin6_addr);
- s = socket(PF_INET6, SOCK_STREAM, 0);
- if (s < 0)
- {
- perror("socket");
- exit(1);
- }
- rc = bind(s, (struct sockaddr *)&saddr, sizeof(saddr));
- if (rc < 0)
- {
- perror("bind");
- exit(1);
- }
- rc = listen(s, 4);
- if (rc < 0)
- {
- perror("listen");
- exit(1);
- }
- m = accept(s, (struct sockaddr *)&raddr, &addrlen);
- if (m < 0)
- {
- perror("accept");
- exit(1);
- }
- rc = read(m, buf, sizeof(buf));
- while (rc > 0)
- {
- write(1, buf, rc);
- rc = read(m, buf, sizeof(buf));
- }
- if (rc < 0)
- {
- perror("read");
- exit(1);
- }
- }
Raw Paste