+static int
+newSock(const char *host, const char *port)
+{
+ struct addrinfo hints;
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_family = AF_UNSPEC;
+ hints.ai_socktype = SOCK_DGRAM;
+ struct addrinfo *res = NULL;
+ int rc = getaddrinfo(host, port, &hints, &res);
+ if (rc != 0)
+ err(EXIT_FAILURE, "getaddrinfo: %s\n", gai_strerror(rc));
+ int sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+ if (sock == -1)
+ err(EXIT_FAILURE, "socket()");
+ if (bind(sock, res->ai_addr, res->ai_addrlen) != 0)
+ err(EXIT_FAILURE, "bind()");
+ rc = fcntl(sock, F_GETFL, 0);
+ if (rc < 0)
+ err(EXIT_FAILURE, "F_GETFL");
+ rc = fcntl(sock, F_SETFL, (rc | O_NONBLOCK));
+ if (rc < 0)
+ err(EXIT_FAILURE, "F_SETFL");
+ freeaddrinfo(res);
+ return sock;
+}
+
+static void
+rlimited(int res)
+{
+ struct rlimit r;
+ r.rlim_cur = 0;
+ r.rlim_max = 0;
+ if (setrlimit(res, &r) == -1) {
+ err(EXIT_FAILURE, "can not setrlimit()");
+ }
+}
+