/**
* Create a tcp socket to the specified address
+ * \param[in] to ip and family
+ * \param[in] tolen length of to
+ * \param[in] timeout timeout for the socket
+ * \return a socket descriptor
*/
int ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout);
+/**
+ * Create a udp socket to the specified address
+ * \param[in] to ip and family
+ * \param[in] timeout timeout for the socket
+ * \return a socket descriptor
+ */
+int ldns_udp_connect(const struct sockaddr_storage *to, struct timeval timeout);
+
/**
* send a query via tcp to a server. Don;t want for the answer
*
return LDNS_STATUS_OK;
}
+int
+ldns_udp_connect(const struct sockaddr_storage *to, struct timeval timeout)
+{
+ int sockfd;
+
+ if ((sockfd = socket((int)((struct sockaddr*)to)->sa_family, SOCK_DGRAM, IPPROTO_UDP))
+ == -1) {
+ return 0;
+ }
+ if (setsockopt(sockfd, SOL_SOCKET, SO_RCVTIMEO, &timeout,
+ (socklen_t) sizeof(timeout))) {
+ perror("setsockopt");
+ close(sockfd);
+ return 0;
+ }
+ return sockfd;
+}
+
int
ldns_tcp_connect(const struct sockaddr_storage *to, socklen_t tolen, struct timeval timeout)
{
perror("could not bind socket");
return 0;
}
-
return sockfd;
}
return answer;
}
+