static int destroy_dns_connection | ( | struct dns_connection * | conn | ) | [static] |
参照先 dns_connection::s.
参照元 dns_tcp_open()・dns_udp_open().
00032 { 00033 return close(conn->s); 00034 }
static DNS_ERROR dns_tcp_open | ( | const char * | nameserver, | |
TALLOC_CTX * | mem_ctx, | |||
struct dns_connection ** | result | |||
) | [static] |
参照先 destroy_dns_connection()・dns_connection::hType・result・dns_connection::s.
00042 { 00043 uint32_t ulAddress; 00044 struct hostent *pHost; 00045 struct sockaddr_in s_in; 00046 struct dns_connection *conn; 00047 int res; 00048 00049 if (!(conn = talloc(mem_ctx, struct dns_connection))) { 00050 return ERROR_DNS_NO_MEMORY; 00051 } 00052 00053 if ( (ulAddress = inet_addr( nameserver )) == INADDR_NONE ) { 00054 if ( (pHost = gethostbyname( nameserver )) == NULL ) { 00055 TALLOC_FREE(conn); 00056 return ERROR_DNS_INVALID_NAME_SERVER; 00057 } 00058 memcpy( &ulAddress, pHost->h_addr, pHost->h_length ); 00059 } 00060 00061 conn->s = socket( PF_INET, SOCK_STREAM, 0 ); 00062 if (conn->s == -1) { 00063 TALLOC_FREE(conn); 00064 return ERROR_DNS_CONNECTION_FAILED; 00065 } 00066 00067 talloc_set_destructor(conn, destroy_dns_connection); 00068 00069 s_in.sin_family = AF_INET; 00070 s_in.sin_addr.s_addr = ulAddress; 00071 s_in.sin_port = htons( DNS_TCP_PORT ); 00072 00073 res = connect(conn->s, (struct sockaddr*)&s_in, sizeof( s_in )); 00074 if (res == -1) { 00075 TALLOC_FREE(conn); 00076 return ERROR_DNS_CONNECTION_FAILED; 00077 } 00078 00079 conn->hType = DNS_TCP; 00080 00081 *result = conn; 00082 return ERROR_DNS_SUCCESS; 00083 }
static DNS_ERROR dns_udp_open | ( | const char * | nameserver, | |
TALLOC_CTX * | mem_ctx, | |||
struct dns_connection ** | result | |||
) | [static] |
参照先 destroy_dns_connection()・dns_connection::hType・dns_connection::RecvAddr・result・dns_connection::s.
00091 { 00092 unsigned long ulAddress; 00093 struct hostent *pHost; 00094 struct sockaddr_in RecvAddr; 00095 struct dns_connection *conn; 00096 00097 if (!(conn = talloc(NULL, struct dns_connection))) { 00098 return ERROR_DNS_NO_MEMORY; 00099 } 00100 00101 if ( (ulAddress = inet_addr( nameserver )) == INADDR_NONE ) { 00102 if ( (pHost = gethostbyname( nameserver )) == NULL ) { 00103 TALLOC_FREE(conn); 00104 return ERROR_DNS_INVALID_NAME_SERVER; 00105 } 00106 memcpy( &ulAddress, pHost->h_addr, pHost->h_length ); 00107 } 00108 00109 /* Create a socket for sending data */ 00110 00111 conn->s = socket( AF_INET, SOCK_DGRAM, IPPROTO_UDP ); 00112 if (conn->s == -1) { 00113 TALLOC_FREE(conn); 00114 return ERROR_DNS_CONNECTION_FAILED; 00115 } 00116 00117 talloc_set_destructor(conn, destroy_dns_connection); 00118 00119 /* Set up the RecvAddr structure with the IP address of 00120 the receiver (in this example case "123.456.789.1") 00121 and the specified port number. */ 00122 00123 RecvAddr.sin_family = AF_INET; 00124 RecvAddr.sin_port = htons( DNS_UDP_PORT ); 00125 RecvAddr.sin_addr.s_addr = ulAddress; 00126 00127 conn->hType = DNS_UDP; 00128 memcpy( &conn->RecvAddr, &RecvAddr, sizeof( struct sockaddr_in ) ); 00129 00130 *result = conn; 00131 return ERROR_DNS_SUCCESS; 00132 }
DNS_ERROR dns_open_connection | ( | const char * | nameserver, | |
int32 | dwType, | |||
TALLOC_CTX * | mem_ctx, | |||
struct dns_connection ** | conn | |||
) |
参照先 dns_tcp_open()・dns_udp_open().
参照元 dns_negotiate_sec_ctx()・do_gethostbyname()・DoDNSUpdate().
00140 { 00141 switch ( dwType ) { 00142 case DNS_TCP: 00143 return dns_tcp_open( nameserver, mem_ctx, conn ); 00144 case DNS_UDP: 00145 return dns_udp_open( nameserver, mem_ctx, conn ); 00146 } 00147 00148 return ERROR_DNS_INVALID_PARAMETER; 00149 }
static DNS_ERROR write_all | ( | int | fd, | |
uint8 * | data, | |||
size_t | len | |||
) | [static] |
参照先 total.
参照元 dns_send_tcp().
00152 { 00153 size_t total = 0; 00154 00155 while (total < len) { 00156 00157 ssize_t ret = write(fd, data + total, len - total); 00158 00159 if (ret <= 0) { 00160 /* 00161 * EOF or error 00162 */ 00163 return ERROR_DNS_SOCKET_ERROR; 00164 } 00165 00166 total += ret; 00167 } 00168 00169 return ERROR_DNS_SUCCESS; 00170 }
static DNS_ERROR dns_send_tcp | ( | struct dns_connection * | conn, | |
const struct dns_buffer * | buf | |||
) | [static] |
参照先 buf・err・len・dns_connection::s・write_all().
参照元 dns_send().
00174 { 00175 uint16 len = htons(buf->offset); 00176 DNS_ERROR err; 00177 00178 err = write_all(conn->s, (uint8 *)&len, sizeof(len)); 00179 if (!ERR_DNS_IS_OK(err)) return err; 00180 00181 return write_all(conn->s, buf->data, buf->offset); 00182 }
static DNS_ERROR dns_send_udp | ( | struct dns_connection * | conn, | |
const struct dns_buffer * | buf | |||
) | [static] |
参照先 buf・dns_connection::RecvAddr・dns_connection::s.
参照元 dns_send().
00186 { 00187 ssize_t ret; 00188 00189 ret = sendto(conn->s, buf->data, buf->offset, 0, 00190 (struct sockaddr *)&conn->RecvAddr, 00191 sizeof(conn->RecvAddr)); 00192 00193 if (ret != buf->offset) { 00194 return ERROR_DNS_SOCKET_ERROR; 00195 } 00196 00197 return ERROR_DNS_SUCCESS; 00198 }
DNS_ERROR dns_send | ( | struct dns_connection * | conn, | |
const struct dns_buffer * | buf | |||
) |
参照先 buf・dns_send_tcp()・dns_send_udp()・dns_connection::hType.
参照元 dns_negotiate_gss_ctx_int()・dns_transaction().
00201 { 00202 if (conn->hType == DNS_TCP) { 00203 return dns_send_tcp(conn, buf); 00204 } 00205 00206 if (conn->hType == DNS_UDP) { 00207 return dns_send_udp(conn, buf); 00208 } 00209 00210 return ERROR_DNS_INVALID_PARAMETER; 00211 }
static DNS_ERROR read_all | ( | int | fd, | |
uint8 * | data, | |||
size_t | len | |||
) | [static] |
参照先 total.
参照元 dns_receive_tcp().
00214 { 00215 size_t total = 0; 00216 fd_set rfds; 00217 struct timeval tv; 00218 00219 while (total < len) { 00220 ssize_t ret; 00221 int fd_ready; 00222 00223 FD_ZERO( &rfds ); 00224 FD_SET( fd, &rfds ); 00225 00226 /* 10 second timeout */ 00227 tv.tv_sec = 10; 00228 tv.tv_usec = 0; 00229 00230 fd_ready = select( fd+1, &rfds, NULL, NULL, &tv ); 00231 if ( fd_ready == 0 ) { 00232 /* read timeout */ 00233 return ERROR_DNS_SOCKET_ERROR; 00234 } 00235 00236 ret = read(fd, data + total, len - total); 00237 if (ret <= 0) { 00238 /* EOF or error */ 00239 return ERROR_DNS_SOCKET_ERROR; 00240 } 00241 00242 total += ret; 00243 } 00244 00245 return ERROR_DNS_SUCCESS; 00246 }
static DNS_ERROR dns_receive_tcp | ( | TALLOC_CTX * | mem_ctx, | |
struct dns_connection * | conn, | |||
struct dns_buffer ** | presult | |||
) | [static] |
参照先 buf・err・len・read_all()・dns_connection::s.
参照元 dns_receive().
00251 { 00252 struct dns_buffer *buf; 00253 DNS_ERROR err; 00254 uint16 len; 00255 00256 if (!(buf = TALLOC_ZERO_P(mem_ctx, struct dns_buffer))) { 00257 return ERROR_DNS_NO_MEMORY; 00258 } 00259 00260 err = read_all(conn->s, (uint8 *)&len, sizeof(len)); 00261 if (!ERR_DNS_IS_OK(err)) { 00262 return err; 00263 } 00264 00265 buf->size = ntohs(len); 00266 00267 if (buf->size) { 00268 if (!(buf->data = TALLOC_ARRAY(buf, uint8, buf->size))) { 00269 TALLOC_FREE(buf); 00270 return ERROR_DNS_NO_MEMORY; 00271 } 00272 } else { 00273 buf->data = NULL; 00274 } 00275 00276 err = read_all(conn->s, buf->data, buf->size); 00277 if (!ERR_DNS_IS_OK(err)) { 00278 TALLOC_FREE(buf); 00279 return err; 00280 } 00281 00282 *presult = buf; 00283 return ERROR_DNS_SUCCESS; 00284 }
static DNS_ERROR dns_receive_udp | ( | TALLOC_CTX * | mem_ctx, | |
struct dns_connection * | conn, | |||
struct dns_buffer ** | presult | |||
) | [static] |
参照先 buf・dns_connection::s.
参照元 dns_receive().
00289 { 00290 struct dns_buffer *buf; 00291 ssize_t received; 00292 00293 if (!(buf = TALLOC_ZERO_P(mem_ctx, struct dns_buffer))) { 00294 return ERROR_DNS_NO_MEMORY; 00295 } 00296 00297 /* 00298 * UDP based DNS can only be 512 bytes 00299 */ 00300 00301 if (!(buf->data = TALLOC_ARRAY(buf, uint8, 512))) { 00302 TALLOC_FREE(buf); 00303 return ERROR_DNS_NO_MEMORY; 00304 } 00305 00306 received = recv(conn->s, (void *)buf->data, 512, 0); 00307 00308 if (received == -1) { 00309 TALLOC_FREE(buf); 00310 return ERROR_DNS_SOCKET_ERROR; 00311 } 00312 00313 if (received > 512) { 00314 TALLOC_FREE(buf); 00315 return ERROR_DNS_BAD_RESPONSE; 00316 } 00317 00318 buf->size = received; 00319 buf->offset = 0; 00320 00321 *presult = buf; 00322 return ERROR_DNS_SUCCESS; 00323 }
DNS_ERROR dns_receive | ( | TALLOC_CTX * | mem_ctx, | |
struct dns_connection * | conn, | |||
struct dns_buffer ** | presult | |||
) |
参照先 dns_receive_tcp()・dns_receive_udp()・dns_connection::hType.
参照元 dns_negotiate_gss_ctx_int()・dns_transaction().
00327 { 00328 if (conn->hType == DNS_TCP) { 00329 return dns_receive_tcp(mem_ctx, conn, presult); 00330 } 00331 00332 if (conn->hType == DNS_UDP) { 00333 return dns_receive_udp(mem_ctx, conn, presult); 00334 } 00335 00336 return ERROR_DNS_INVALID_PARAMETER; 00337 }
DNS_ERROR dns_transaction | ( | TALLOC_CTX * | mem_ctx, | |
struct dns_connection * | conn, | |||
const struct dns_request * | req, | |||
struct dns_request ** | resp | |||
) |
参照先 buf・dns_marshall_request()・dns_receive()・dns_send()・dns_unmarshall_request()・err・error.
参照元 dns_update_transaction()・do_gethostbyname().
00342 { 00343 struct dns_buffer *buf = NULL; 00344 DNS_ERROR err; 00345 00346 err = dns_marshall_request(conn, req, &buf); 00347 if (!ERR_DNS_IS_OK(err)) goto error; 00348 00349 err = dns_send(conn, buf); 00350 if (!ERR_DNS_IS_OK(err)) goto error; 00351 TALLOC_FREE(buf); 00352 00353 err = dns_receive(mem_ctx, conn, &buf); 00354 if (!ERR_DNS_IS_OK(err)) goto error; 00355 00356 err = dns_unmarshall_request(mem_ctx, buf, resp); 00357 00358 error: 00359 TALLOC_FREE(buf); 00360 return err; 00361 }
DNS_ERROR dns_update_transaction | ( | TALLOC_CTX * | mem_ctx, | |
struct dns_connection * | conn, | |||
struct dns_update_request * | up_req, | |||
struct dns_update_request ** | up_resp | |||
) |
参照先 dns_request2update()・dns_transaction()・dns_update2request()・err.
参照元 DoDNSUpdate().
00367 { 00368 struct dns_request *resp; 00369 DNS_ERROR err; 00370 00371 err = dns_transaction(mem_ctx, conn, dns_update2request(up_req), 00372 &resp); 00373 00374 if (!ERR_DNS_IS_OK(err)) return err; 00375 00376 *up_resp = dns_request2update(resp); 00377 return ERROR_DNS_SUCCESS; 00378 }