vntsd.c (4d39be2b45b5ac811d28452e6eb629ac64aebfc4) vntsd.c (bd8f0338e0109a8df4e34499bdf42e592c77eeda)
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
1/*
2 * CDDL HEADER START
3 *
4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
7 *
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE

--- 6 unchanged lines hidden (view full) ---

15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
18 *
19 * CDDL HEADER END
20 */
21
22/*
23 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
23 * Copyright 2007 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29/*
30 * VNTSD main
31 *

--- 19 unchanged lines hidden (view full) ---

51#include <netinet/in.h>
52#include <thread.h>
53#include <signal.h>
54#include <fcntl.h>
55#include <ctype.h>
56#include <libintl.h>
57#include <locale.h>
58#include <syslog.h>
24 * Use is subject to license terms.
25 */
26
27#pragma ident "%Z%%M% %I% %E% SMI"
28
29/*
30 * VNTSD main
31 *

--- 19 unchanged lines hidden (view full) ---

51#include <netinet/in.h>
52#include <thread.h>
53#include <signal.h>
54#include <fcntl.h>
55#include <ctype.h>
56#include <libintl.h>
57#include <locale.h>
58#include <syslog.h>
59#include <sys/socket.h>
60#include <netdb.h>
59#include "vntsd.h"
60#include "chars.h"
61
62#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
63#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */
64#endif
65
66/* global variables */
67
68#ifdef DEBUG
69int vntsddbg = 0x8;
70#endif
71
72#define MINUTE 60
73
61#include "vntsd.h"
62#include "chars.h"
63
64#if !defined(TEXT_DOMAIN) /* Should be defined by cc -D */
65#define TEXT_DOMAIN "SYS_TEST" /* Use this only if it weren't. */
66#endif
67
68/* global variables */
69
70#ifdef DEBUG
71int vntsddbg = 0x8;
72#endif
73
74#define MINUTE 60
75
76#define VNTSD_INVALID_LISTEN_ADDR ((in_addr_t)-1)
77
74static vntsd_t *vntsdp;
75
76
77static void vntsd_exit(void);
78/* Signal handler for SIGINT, SIGKILL and SIGHUP */
79static void
80exit_sig_handler(int sig)
81{

--- 172 unchanged lines hidden (view full) ---

254static void
255vntsd_help(void)
256{
257
258 (void) fprintf(stderr, gettext("Usage: vntsd -i <VCC device instance> "
259 "[-p <listen address>] [-t <timeout in minutes>]\n"));
260}
261
78static vntsd_t *vntsdp;
79
80
81static void vntsd_exit(void);
82/* Signal handler for SIGINT, SIGKILL and SIGHUP */
83static void
84exit_sig_handler(int sig)
85{

--- 172 unchanged lines hidden (view full) ---

258static void
259vntsd_help(void)
260{
261
262 (void) fprintf(stderr, gettext("Usage: vntsd -i <VCC device instance> "
263 "[-p <listen address>] [-t <timeout in minutes>]\n"));
264}
265
266/*
267 * get_listen_ip_addr()
268 * check for a valid control domain ip address in format of xxx.xxx.xxx.xxx.
269 * if ip address is valid and is assigned to this host, return ip address
270 * or else return VNTSD_INVALID_LISTEN_ADDR.
271 */
272static in_addr_t
273get_listen_ip_addr(char *listen_addr)
274{
275 char host_name[MAXPATHLEN];
276 in_addr_t addr;
277 struct addrinfo hints;
278 struct addrinfo *res, *infop;
279 int err;
280 struct sockaddr_in *sa;
262
281
282 if (gethostname(host_name, MAXPATHLEN) != 0) {
283 syslog(LOG_ERR, "Can not get host name!");
284 return (VNTSD_INVALID_LISTEN_ADDR);
285 }
286
287 if ((int)(addr = inet_addr(listen_addr)) == -1)
288 /* bad IP address format */
289 return (VNTSD_INVALID_LISTEN_ADDR);
290
291 bzero(&hints, sizeof (hints));
292 hints.ai_family = PF_INET;
293 hints.ai_socktype = SOCK_STREAM;
294
295 err = getaddrinfo(host_name, NULL, &hints, &res);
296 if (err != 0) {
297 syslog(LOG_ERR, "getaddrinfo failed: %s", gai_strerror(err));
298 return (VNTSD_INVALID_LISTEN_ADDR);
299 }
300
301 infop = res;
302 while (infop != NULL) {
303 /* LINTED E_BAD_PTR_CAST_ALIGN */
304 sa = (struct sockaddr_in *)infop->ai_addr;
305 if (sa->sin_addr.s_addr == addr) {
306 /* ip address found */
307 freeaddrinfo(res);
308 return (addr);
309 }
310 infop = infop->ai_next;
311 }
312
313 /* ip address not found */
314 freeaddrinfo(res);
315 return (VNTSD_INVALID_LISTEN_ADDR);
316}
317
263#ifdef DEBUG
264#define DEBUG_OPTIONS "d"
265#else
266#define DEBUG_OPTIONS ""
267#endif
268
269int
270main(int argc, char ** argv)

--- 64 unchanged lines hidden (view full) ---

335 }
336
337 if (listen_addr == NULL || strcmp(listen_addr, "localhost") == 0) {
338 /* by default listen on loopback interface */
339 vntsdp->ip_addr.s_addr = htonl(INADDR_LOOPBACK);
340 } else if (strcmp(listen_addr, "any") == 0) {
341 vntsdp->ip_addr.s_addr = htonl(INADDR_ANY);
342 } else {
318#ifdef DEBUG
319#define DEBUG_OPTIONS "d"
320#else
321#define DEBUG_OPTIONS ""
322#endif
323
324int
325main(int argc, char ** argv)

--- 64 unchanged lines hidden (view full) ---

390 }
391
392 if (listen_addr == NULL || strcmp(listen_addr, "localhost") == 0) {
393 /* by default listen on loopback interface */
394 vntsdp->ip_addr.s_addr = htonl(INADDR_LOOPBACK);
395 } else if (strcmp(listen_addr, "any") == 0) {
396 vntsdp->ip_addr.s_addr = htonl(INADDR_ANY);
397 } else {
343 vntsdp->ip_addr.s_addr = inet_addr(listen_addr);
344 if (vntsdp->ip_addr.s_addr == (in_addr_t)(-1)) {
345 (void) fprintf(stderr,
346 gettext("Invalid listen address '%s'\n"),
398 vntsdp->ip_addr.s_addr = get_listen_ip_addr(listen_addr);
399 if (vntsdp->ip_addr.s_addr == VNTSD_INVALID_LISTEN_ADDR) {
400 syslog(LOG_ERR,
401 "Invalid listen address '%s'\n",
347 listen_addr);
402 listen_addr);
348 exit(1);
403 exit(2);
349 }
350 }
351
352 D3(stderr, "options = %llx, instance = %s, listen = %s\n",
353 vntsdp->options, vntsdp->devinst,
354 listen_addr ? listen_addr : "<null>");
355
356 /* open VCC driver control port */

--- 225 unchanged lines hidden ---
404 }
405 }
406
407 D3(stderr, "options = %llx, instance = %s, listen = %s\n",
408 vntsdp->options, vntsdp->devinst,
409 listen_addr ? listen_addr : "<null>");
410
411 /* open VCC driver control port */

--- 225 unchanged lines hidden ---