1
/* Copyright 2000-2005 The Apache Software Foundation or its licensors, as
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
17
#include "apr_arch_networkio.h"
18
#include "apr_network_io.h"
19
#include "apr_general.h"
21
#include "apr_strings.h"
24
#include <sys/socket.h>
25
#include <netinet/tcp.h>
26
#include <netinet/in.h>
29
#include <sys/so_ioctl.h>
32
APR_DECLARE(apr_status_t) apr_socket_timeout_set(apr_socket_t *sock,
33
apr_interval_time_t t)
40
APR_DECLARE(apr_status_t) apr_socket_opt_set(apr_socket_t *sock,
41
apr_int32_t opt, apr_int32_t on)
51
if (opt & APR_SO_KEEPALIVE) {
52
if (setsockopt(sock->socketdes, SOL_SOCKET, SO_KEEPALIVE, (void *)&one, sizeof(int)) == -1) {
53
return APR_OS2_STATUS(sock_errno());
56
if (opt & APR_SO_DEBUG) {
57
if (setsockopt(sock->socketdes, SOL_SOCKET, SO_DEBUG, (void *)&one, sizeof(int)) == -1) {
58
return APR_OS2_STATUS(sock_errno());
61
if (opt & APR_SO_REUSEADDR) {
62
if (setsockopt(sock->socketdes, SOL_SOCKET, SO_REUSEADDR, (void *)&one, sizeof(int)) == -1) {
63
return APR_OS2_STATUS(sock_errno());
66
if (opt & APR_SO_SNDBUF) {
67
if (setsockopt(sock->socketdes, SOL_SOCKET, SO_SNDBUF, (void *)&on, sizeof(int)) == -1) {
68
return APR_OS2_STATUS(sock_errno());
71
if (opt & APR_SO_NONBLOCK) {
72
if (ioctl(sock->socketdes, FIONBIO, (caddr_t)&one, sizeof(one)) == -1) {
73
return APR_OS2_STATUS(sock_errno());
78
if (opt & APR_SO_LINGER) {
80
li.l_linger = APR_MAX_SECS_TO_LINGER;
81
if (setsockopt(sock->socketdes, SOL_SOCKET, SO_LINGER, (char *) &li, sizeof(struct linger)) == -1) {
82
return APR_OS2_STATUS(sock_errno());
85
if (opt & APR_TCP_NODELAY) {
86
if (setsockopt(sock->socketdes, IPPROTO_TCP, TCP_NODELAY, (void *)&on, sizeof(int)) == -1) {
87
return APR_OS2_STATUS(sock_errno());
94
APR_DECLARE(apr_status_t) apr_socket_timeout_get(apr_socket_t *sock,
95
apr_interval_time_t *t)
102
APR_DECLARE(apr_status_t) apr_socket_opt_get(apr_socket_t *sock,
103
apr_int32_t opt, apr_int32_t *on)
113
APR_DECLARE(apr_status_t) apr_socket_atmark(apr_socket_t *sock, int *atmark)
117
if (ioctl(sock->socketdes, SIOCATMARK, (void*)&oobmark, sizeof(oobmark)) < 0) {
118
return APR_OS2_STATUS(sock_errno());
121
*atmark = (oobmark != 0);
127
APR_DECLARE(apr_status_t) apr_gethostname(char *buf, apr_int32_t len,
130
if (gethostname(buf, len) == -1) {
132
return APR_OS2_STATUS(sock_errno());
134
else if (!memchr(buf, '\0', len)) { /* buffer too small */
136
return APR_ENAMETOOLONG;