~ubuntu-branches/ubuntu/hoary/eflite/hoary

« back to all changes in this revision

Viewing changes to soccon.c

  • Committer: Bazaar Package Importer
  • Author(s): Mario Lang
  • Date: 2004-02-25 13:55:10 UTC
  • Revision ID: james.westby@ubuntu.com-20040225135510-hei3t1pv7rywewhn
Tags: upstream-0.3.8
ImportĀ upstreamĀ versionĀ 0.3.8

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* soccon.c - function to open a connection to a socket
 
2
 * $Id: soccon.c,v 1.2 2002/03/06 02:25:18 mgorse Exp $
 
3
 */
 
4
 
 
5
#include <stdio.h>
 
6
#include <sys/types.h>
 
7
#include <sys/socket.h>
 
8
#include <sys/un.h>
 
9
#include <unistd.h>
 
10
 
 
11
int sockconnect(const char *fname)
 
12
{
 
13
  struct sockaddr_un addr;
 
14
  int sock;
 
15
 
 
16
  if (!fname) return -1;
 
17
  sock = socket(AF_UNIX, SOCK_STREAM, 0);
 
18
  if (sock == -1)
 
19
  {
 
20
    perror("socket");
 
21
    return -1;
 
22
  }
 
23
  addr.sun_family = AF_UNIX;
 
24
  strncpy(addr.sun_path, fname, sizeof(addr.sun_path));
 
25
  if (connect(sock, (struct sockaddr *)&addr, sizeof(addr)) == -1)
 
26
  {
 
27
    close(sock);
 
28
    return -1;
 
29
  }
 
30
  return sock;
 
31
}