Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdlib.h>
- #include <stdio.h>
- #include <sys/socket.h>
- #include <sys/types.h>
- #include <netinet/in.h>
- #include <unistd.h>
- #include <string.h>
- #include <netdb.h>
- int main(int argc,char **argv)
- {
- int MAXSOCK = 99999;
- int error;
- int nsock;
- int s[MAXSOCK];
- int porty = atoi(argv[1]);
- const char *cause = NULL;
- struct addrinfo hints, *res, *res0;
- memset(&hints, 0, sizeof(hints));
- hints.ai_family = AF_INET;
- hints.ai_socktype= SOCK_STREAM;
- error = getaddrinfo(NULL, argv[1], &hints, &res0);
- if (error)
- {
- errx(1, "%s", gai_strerror(error)); /* NOTREACHED */
- }
- nsock = 0;
- for (res = res0; res && nsock < MAXSOCK; res = res->ai_next)
- {
- s[nsock] = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
- if (s[nsock] < 0)
- {
- cause = "socket";
- continue;
- }
- if (bind(s[nsock], res->ai_addr, res->ai_addrlen) < 0)
- {
- cause = "bind";
- close(s[nsock]);
- continue;
- }
- (void) listen(s[nsock], 5);
- nsock++;
- }
- if (nsock == 0)
- {
- err(1, "%s", cause);/* NOTREACHED */
- }
- freeaddrinfo(res0);
- return 0;;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement