2 * libvdeplug - A library to connect to a VDE Switch.
3 * dynamic loading version (requires libdl).
5 * Copyright (C) 2006,2007 Renzo Davoli, University of Bologna
7 * This library is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as published by
9 * the Free Software Foundation version 2.1 of the License, or (at
10 * your option) any later version.
12 * This library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this library; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
22 /* Use this include file when you need to write an application that can
23 * benefit from vde when available.
24 * Linking libvdeplug to your programs you force your application users
25 * to have the library installed (otherway the dynamic linker complies
26 * and the program does not start).
30 * define a struct vdepluglib variable;
32 * struct vdepluglib vdeplug;
34 * test the availability of the library and load it:
36 * libvdeplug_dynopen(vdeplug);
37 * if vdeplug.dl_handle is not NULL the library is ready otherwise it is
38 * not available in the target system.
40 * if libvdeplug does exist the library function can be called
42 * libvde.vde_open(....)
43 * libvde.vde_read(....)
44 * libvde.vde_open(....)
45 * libvde.vde_recv(....)
46 * libvde.vde_send(....)
47 * libvde.vde_datafd(....)
48 * libvde.vde_ctlfd(....)
49 * libvde.vde_close(....)
50 * libvdeplug_dynclose(vdeplug) can be used to deallocate the dynamic library
52 *************************************************/
56 #include <sys/types.h>
58 #define LIBVDEPLUG_INTERFACE_VERSION 1
62 typedef struct vdeconn VDECONN
;
64 /* Open a VDE connection.
66 * port: connect to a specific port of the switch (0=any)
67 * group: change the ownership of the communication port to a specific group
69 * mode: set communication port mode (if 0 standard socket mode applies)
71 struct vde_open_args
{
78 * vde_switch: switch id (path)
79 * descr: description (it will appear in the port description on the switch)
81 #define vde_open(vde_switch,descr,open_args) \
82 vde_open_real((vde_switch),(descr),LIBVDEPLUG_INTERFACE_VERSION,(open_args))
86 VDECONN
* (*vde_open_real
)(const char *vde_switch
,char *descr
,int interface_version
, struct vde_open_args
*open_args
);
87 size_t (* vde_recv
)(VDECONN
*conn
,char *buf
,size_t len
,int flags
);
88 size_t (* vde_send
)(VDECONN
*conn
,const char *buf
,size_t len
,int flags
);
89 int (* vde_datafd
)(VDECONN
*conn
);
90 int (* vde_ctlfd
)(VDECONN
*conn
);
91 int (* vde_close
)(VDECONN
*conn
);
94 typedef VDECONN
* (* VDE_OPEN_REAL_T
)(const char *vde_switch
,char *descr
,int interface_version
, struct vde_open_args
*open_args
);
95 typedef size_t (* VDE_RECV_T
)(VDECONN
*conn
,char *buf
,size_t len
,int flags
);
96 typedef size_t (* VDE_SEND_T
)(VDECONN
*conn
,const char *buf
,size_t len
,int flags
);
97 typedef int (* VDE_INT_FUN
)(VDECONN
*conn
);
98 #define libvdeplug_dynopen(x) ({ \
99 (x).dl_handle=dlopen("libvdeplug.so",RTLD_NOW); \
100 if ((x).dl_handle) { \
101 (x).vde_open_real=(VDE_OPEN_REAL_T) dlsym((x).dl_handle,"vde_open_real"); \
102 (x).vde_recv=(VDE_RECV_T) dlsym((x).dl_handle,"vde_recv"); \
103 (x).vde_send=(VDE_SEND_T) dlsym((x).dl_handle,"vde_send"); \
104 (x).vde_datafd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_datafd"); \
105 (x).vde_ctlfd=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_ctlfd"); \
106 (x).vde_close=(VDE_INT_FUN) dlsym((x).dl_handle,"vde_close"); \
108 (x).vde_open_real=NULL; \
109 (x).vde_send= NULL; \
110 (x).vde_recv= NULL; \
111 (x).vde_datafd= (x).vde_ctlfd= (x).vde_close= NULL; \
115 #define libvdeplug_dynclose(x) ({ \
116 dlclose((x).dl_handle); \