Skip to content

Instantly share code, notes, and snippets.

@jcmvbkbc
Last active Mar 31, 2018
Embed
What would you like to do?
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/socket.h>
#include <sys/types.h>
#include <unistd.h>
int main()
{
int s, s1;
int rc;
struct sockaddr_in6 sa = {
.sin6_family = AF_INET6,
.sin6_port = 0x1234,
};
struct sockaddr_in6 sa1 = { 0 };
socklen_t sz;
ssize_t rsz;
char buf[1024];
s = socket(AF_INET6, SOCK_STREAM, 0);
if (s < 0) {
perror("socket");
abort();
}
rc = bind(s, (void *)&sa, sizeof(sa));
if (rc < 0) {
perror("bind");
abort();
}
rc = listen(s, 5);
if (rc < 0) {
perror("listen");
abort();
}
sz = sizeof(sa1);
s1 = accept(s, (void *)&sa1, &sz);
if (s1 < 0) {
perror("accept");
abort();
}
for (;;) {
rsz = read(s1, buf, sizeof(buf));
if (rsz < 0) {
perror("read");
abort();
} else if (rsz == 0) {
break;
}
write(STDOUT_FILENO, buf, rsz);
}
return 0;
}
ipv6: ipv6.c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment