2 * Copyright (c) 2011-2012 The DragonFly Project. All rights reserved.
4 * This code is derived from software contributed to The DragonFly Project
5 * by Matthew Dillon <dillon@dragonflybsd.org>
6 * by Venkatesh Srinivas <vsrinivas@dragonflybsd.org>
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in
16 * the documentation and/or other materials provided with the
18 * 3. Neither the name of The DragonFly Project nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific, prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
25 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
26 * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
27 * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
28 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
29 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
30 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
32 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 #include "dmsg_local.h"
39 * Allocation wrappers give us shims for possible future use
42 dmsg_alloc(size_t bytes)
59 dmsg_uuid_to_str(uuid_t *uuid, char **strp)
66 uuid_to_string(uuid, strp, &status);
71 dmsg_peer_type_to_str(uint8_t type)
76 case DMSG_PEER_ROUTER:
80 case DMSG_PEER_HAMMER2:
82 case DMSG_PEER_CLIENT:
90 dmsg_connect(const char *hostname)
92 struct sockaddr_in lsin;
98 * Acquire socket and set options
100 if ((fd = socket(AF_INET, SOCK_STREAM, 0)) < 0) {
101 dm_printf(1, "cmd_debug: socket(): %s\n",
106 setsockopt(fd, IPPROTO_TCP, TCP_NODELAY, &opt, sizeof opt);
109 * Connect to the target
111 bzero(&lsin, sizeof(lsin));
112 lsin.sin_family = AF_INET;
113 lsin.sin_addr.s_addr = 0;
114 lsin.sin_port = htons(DMSG_LISTEN_PORT);
117 hen = gethostbyname2(hostname, AF_INET);
119 if (inet_pton(AF_INET, hostname, &lsin.sin_addr) != 1) {
120 dm_printf(3, "Cannot resolve %s\n", hostname);
124 bcopy(hen->h_addr, &lsin.sin_addr, hen->h_length);
127 if (connect(fd, (struct sockaddr *)&lsin, sizeof(lsin)) < 0) {
129 if (DMsgDebugOpt > 2) {
130 dm_printf(3, "debug: Connect failed: %s\n",