~linuxjedi/drizzle/trunk-bug-743902

« back to all changes in this revision

Viewing changes to libdrizzle/conn_uds.c

  • Committer: Monty Taylor
  • Date: 2010-08-20 15:05:54 UTC
  • mfrom: (1720.1.7 build)
  • Revision ID: mordred@inaugust.com-20100820150554-fuwf8zs8qpzhpx6y
Added libdrizzle to the tree.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
8
 * the COPYING file in this directory for full text.
 
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
}