120
125
if (dsi->socket < 0)
123
if ((pid = fork()) == 0) { /* child */
124
static const struct itimerval timer = {{0, 0}, {DSI_TCPTIMEOUT, 0}};
128
getitimer(ITIMER_PROF, &itimer);
129
if (0 == (pid = fork()) ) { /* child */
130
static struct itimerval timer = {{0, 0}, {DSI_TCPTIMEOUT, 0}};
125
131
struct sigaction newact, oldact;
126
132
u_int8_t block[DSI_BLOCKSIZ];
135
141
newact.sa_flags = 0;
136
142
sigemptyset(&oldact.sa_mask);
137
143
oldact.sa_flags = 0;
144
setitimer(ITIMER_PROF, &itimer, NULL);
138
146
if ((sigaction(SIGALRM, &newact, &oldact) < 0) ||
139
147
(setitimer(ITIMER_REAL, &timer, NULL) < 0)) {
140
148
LOG(log_error, logtype_default, "dsi_tcp_open: %s", strerror(errno));
144
152
/* read in commands. this is similar to dsi_receive except
191
198
LOG(log_error, logtype_default, "dsi_tcp_open: stream_read: %s", strerror(errno));
203
/* stop timer and restore signal handler */
204
memset(&timer, 0, sizeof(timer));
205
setitimer(ITIMER_REAL, &timer, NULL);
197
206
sigaction(SIGALRM, &oldact, NULL);
199
208
LOG(log_info, logtype_default,"ASIP session:%u(%d) from %s:%u(%d)",
246
255
#ifdef SO_REUSEADDR
248
257
setsockopt(dsi->serversock, SOL_SOCKET, SO_REUSEADDR, &port, sizeof(port));
249
#endif /* SO_REUSEADDR */
251
260
#ifdef USE_TCP_NODELAY
253
263
#define SOL_TCP IPPROTO_TCP
254
#endif /* ! SOL_TCP */
256
267
setsockopt(dsi->serversock, SOL_TCP, TCP_NODELAY, &port, sizeof(port));
257
268
#endif /* USE_TCP_NODELAY */
279
/* Point protocol specific functions to tcp versions */
280
dsi->proto_open = dsi_tcp_open;
281
dsi->proto_close = dsi_tcp_close;
268
283
/* get real address for GetStatus. we'll go through the list of
269
284
* interfaces if necessary. */
271
if ((host = gethostbyname(hostname))) /* we can resolve the name */
272
dsi->server.sin_addr.s_addr = ((struct in_addr *) host->h_addr)->s_addr;
287
/* address is a parameter, use it 'as is' */
291
if (!(host = gethostbyname(hostname)) ) { /* we can't resolve the name */
293
LOG(log_info, logtype_default, "dsi_tcp: cannot resolve hostname '%s'", hostname);
295
/* give up we have nothing to advertise */
300
if (((struct in_addr *) host->h_addr)->s_addr != 0x100007F) { /* FIXME ugly check */
301
dsi->server.sin_addr.s_addr = ((struct in_addr *) host->h_addr)->s_addr;
304
LOG(log_info, logtype_default, "dsi_tcp: hostname '%s' resolves to loopback address", hostname);
274
307
char **start, **list;
275
308
struct ifreq ifr;
277
310
/* get it from the interface list */
278
311
start = list = getifacelist();
279
312
while (list && *list) {
280
strncpy(ifr.ifr_name, *list, sizeof(ifr.ifr_name));
313
strlcpy(ifr.ifr_name, *list, sizeof(ifr.ifr_name));
283
316
#ifndef IFF_SLAVE
284
317
#define IFF_SLAVE 0
285
#endif /* ! IFF_SLAVE */
286
if (ioctl(dsi->serversock, SIOCGIFFLAGS, &ifr) < 0)
289
if (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_SLAVE))
292
if ((ifr.ifr_flags & IFF_UP) == 0)
295
if (ioctl(dsi->serversock, SIOCGIFADDR, &ifr) < 0)
320
if (ioctl(dsi->serversock, SIOCGIFFLAGS, &ifr) < 0)
323
if (ifr.ifr_flags & (IFF_LOOPBACK | IFF_POINTOPOINT | IFF_SLAVE))
326
if (!(ifr.ifr_flags & (IFF_UP | IFF_RUNNING)) )
329
if (ioctl(dsi->serversock, SIOCGIFADDR, &ifr) < 0)
298
dsi->server.sin_addr.s_addr =
299
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
300
LOG(log_info, logtype_default, "dsi_tcp: Can't resolve hostname (%s).\n"
301
"%s on interface %s will be used instead.", hostname,
332
dsi->server.sin_addr.s_addr =
333
((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr;
334
LOG(log_info, logtype_default, "dsi_tcp: '%s' on interface '%s' will be used instead.",
302
335
inet_ntoa(dsi->server.sin_addr), ifr.ifr_name);
306
LOG(log_info, logtype_default, "dsi_tcp (Chooser will not select afp/tcp)\n\
307
Check to make sure %s is in /etc/hosts and the correct domain is in\n\
338
LOG(log_info, logtype_default, "dsi_tcp (Chooser will not select afp/tcp) \
339
Check to make sure %s is in /etc/hosts and the correct domain is in \
308
340
/etc/resolv.conf: %s", hostname, strerror(errno));
312
freeifacelist(start);
344
freeifacelist(start);
316
/* everything's set up. now point protocol specific functions to
318
dsi->proto_open = dsi_tcp_open;
319
dsi->proto_close = dsi_tcp_close;