static char *get_addr_string(const struct sockaddr_storage *ss, size_t sslen) {
  static char buffer[PEER_STR_LEN];

#if HAVE_SYS_UN_H
  if (ss->ss_family == AF_UNIX) {
    sprintf(buffer, "%s", get_unixsock_path(ss));
    return buffer;
  }
#endif

  sprintf(buffer, "%s:%d", inet_ntop_ez(ss, sslen), get_port(ss));
  return buffer;
}
Exemplo n.º 2
0
/* Get the peer/host address string.
 * In case we have support for UNIX domain sockets, function returns
 * string containing path to UNIX socket if the address family is AF_UNIX,
 * otherwise it returns string containing "<address>:<port>". */
char *get_peeraddr_string(const msiod *iod)
{
  static char buffer[PEER_STR_LEN];

#if HAVE_SYS_UN_H
  if (iod->peer.ss_family == AF_UNIX) {
    sprintf(buffer, "%s", get_unixsock_path(&iod->peer));
    return buffer;
  }
#endif

  sprintf(buffer, "%s:%d", inet_ntop_ez(&iod->peer, iod->peerlen), nsi_peerport((msiod *) iod));
  return buffer;
}
Exemplo n.º 3
0
/* Request a UNIX domain sockets connection to the same system (by path to socket).
 * This function connects to the socket of type SOCK_DGRAM.  ss should be a
 * sockaddr_storage, sockaddr_un as appropriate (just like what you would pass to
 * connect).  sslen should be the sizeof the structure you are passing in. */
nsock_event_id nsock_connect_unixsock_datagram(nsock_pool nsp, nsock_iod nsiod, nsock_ev_handler handler,
                                               void *userdata, struct sockaddr *saddr, size_t sslen) {
  struct niod *nsi = (struct niod *)nsiod;
  struct npool *ms = (struct npool *)nsp;
  struct nevent *nse;
  struct sockaddr_storage *ss = (struct sockaddr_storage *)saddr;

  assert(nsi->state == NSIOD_STATE_INITIAL || nsi->state == NSIOD_STATE_UNKNOWN);

  nse = event_new(ms, NSE_TYPE_CONNECT, nsi, -1, handler, userdata);
  assert(nse);

  nsock_log_info("UNIX domain socket (DGRAM) connection requested to %s (IOD #%li) EID %li",
                 get_unixsock_path(ss), nsi->id, nse->id);

  nsock_connect_internal(ms, nse, SOCK_DGRAM, 0, ss, sslen, 0);
  nsock_pool_add_event(ms, nse);

  return nse->id;
}