Last active
March 31, 2018 15:01
-
-
Save jcmvbkbc/28fe886a63573d44e528a4e251b79e1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
ipv6: ipv6.c |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment