summaryrefslogtreecommitdiff
path: root/comm/UnixAddress.cc
blob: 5b62647da08db25c21499e50ab9a5f24617aa150 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*
 *	Ivy League
 *
 *	Unix Addresses
 *
 *	Copyright 1990-2000
 *	Laboratoire de Recherche en Informatique (LRI)
 *	Centre d'Etudes de la Navigation Aerienne (CENA)
 *
 *	original code by Michel Beaudouin-Lafon,
 *	modified by Stephane Chatty and Stephane Sire
 *
 *	$Id$
 *
 */

#include "UnixAddress.h"
#include "error.h"

#include <stdio.h>

//	constructors for Unix addresses
//	a Unix domain address is just a filename
//	-> some problems: check for access, when to unlink it ?
//	to do : generate name from a template (for uniqueness)
//

/*?nodoc?*/
IvlUnixAddress :: IvlUnixAddress ()
: IvlAddress ()
{
}

/*?
Create a Unix domain address associated to file \var{filename}.
The file is not unlinked when the address is destroyed;
it should be unlinked by the application whenever the last socket using this address is closed.
?*/
IvlUnixAddress :: IvlUnixAddress (const char* filename)
: IvlAddress ()
{
	Addr.sun_family = AF_UNIX;
	strcpy (Addr.sun_path, filename);
	Valid = true;
	// should check access to file ???
	// unlink if already there ?
}

/*?nodoc?*/
IvlUnixAddress :: ~IvlUnixAddress ()
{
	// how to unlink the file ??
}

/*?nodoc?*/
int
IvlUnixAddress :: Family ()
{
	return AF_UNIX;
}

/*?nodoc?*/
int
IvlUnixAddress :: Length ()
{
	if (Valid)
		return (Addr.sun_path + strlen (Addr.sun_path)) - (char*) &Addr;
	return 0;
}

/*?nodoc?*/
SockAddr*
IvlUnixAddress :: GetSockAddr ()
{
	return (SockAddr*) &Addr;
}

/*?nodoc?*/
char*
IvlUnixAddress :: StrRepr (char* buf)
{
	sprintf (buf, "%s", Addr.sun_path);
	return buf;
}