~drizzle-trunk/drizzle/development

1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
1
/*
2
 * Drizzle Client & Protocol Library
3
 *
4
 * Copyright (C) 2008 Eric Day (eday@oddments.org)
5
 * All rights reserved.
6
 *
7
 * Use and distribution licensed under the BSD license.  See
1799.2.3 by Monty Taylor
Reference root BSD copying file.
8
 * the COPYING.BSD file in the root source directory for full text.
1712.1.1 by Monty Taylor
Merged libdrizzle directly into tree.
9
 */
10
11
/**
12
 * @file
13
 * @brief Connection Definitions for Unix Domain Sockets
14
 */
15
16
#include "common.h"
17
18
const char *drizzle_con_uds(const drizzle_con_st *con)
19
{
20
  if (con->socket_type == DRIZZLE_CON_SOCKET_UDS)
21
  {
22
    if (con->socket.uds.sockaddr.sun_path[0] != 0)
23
      return con->socket.uds.sockaddr.sun_path;
24
25
    if (con->options & DRIZZLE_CON_MYSQL)
26
      return DRIZZLE_DEFAULT_UDS_MYSQL;
27
28
    return DRIZZLE_DEFAULT_UDS;
29
  }
30
31
  return NULL;
32
}
33
34
void drizzle_con_set_uds(drizzle_con_st *con, const char *uds)
35
{
36
  drizzle_con_reset_addrinfo(con);
37
38
  con->socket_type= DRIZZLE_CON_SOCKET_UDS;
39
40
  if (uds == NULL)
41
    uds= "";
42
43
  con->socket.uds.sockaddr.sun_family= AF_UNIX;
44
  strncpy(con->socket.uds.sockaddr.sun_path, uds,
45
          sizeof(con->socket.uds.sockaddr.sun_path));
46
  con->socket.uds.sockaddr.sun_path[sizeof(con->socket.uds.sockaddr.sun_path) - 1]= 0;
47
48
  con->socket.uds.addrinfo.ai_family= AF_UNIX;
49
  con->socket.uds.addrinfo.ai_socktype= SOCK_STREAM;
50
  con->socket.uds.addrinfo.ai_protocol= 0;
51
  con->socket.uds.addrinfo.ai_addrlen= sizeof(struct sockaddr_un);
52
  con->socket.uds.addrinfo.ai_addr= (struct sockaddr *)&(con->socket.uds.sockaddr);
53
}