142 struct sockaddr_in serv_addr;
143 struct hostent *srv = NULL;
144 struct hostent *default_srv = NULL;
150 sockfd = socket (AF_INET, SOCK_DGRAM, IPPROTO_UDP);
156 for (i = 0; i < hnums; ++i) {
157 srv = gethostbyname (hnames[i]);
166 if (default_srv == NULL) {
168 goto ret_close_sockfd;
174 memset (&serv_addr, 0,
sizeof (serv_addr));
175 serv_addr.sin_family = AF_INET;
176 memcpy ((uint8_t *) & serv_addr.sin_addr.s_addr,
177 (uint8_t *) srv->h_addr_list[0], (
size_t) srv->h_length);
178 serv_addr.sin_port = htons (port);
180 ret = connect (sockfd, (
struct sockaddr *) &serv_addr,
sizeof (serv_addr));
183 goto ret_close_sockfd;
193 memset (&packet, 0,
sizeof (packet));
199 n = write (sockfd, &packet,
sizeof (packet));
202 goto ret_close_sockfd;
206 n = read (sockfd, &packet,
sizeof (packet));
209 goto ret_close_sockfd;
229 goto ret_close_sockfd;
237 ret += (int64_t) frac;