source: trunk/packages/xen-3.1/xen-3.1/tools/vnet/vnetd/connection.h @ 34

Last change on this file since 34 was 34, checked in by hartmans, 17 years ago

Add xen and xen-common

File size: 2.6 KB
Line 
1/*
2 * Copyright (C) 2003 - 2004 Mike Wray <mike.wray@hp.com>.
3 *
4 * This library is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as
6 * published by the Free Software Foundation; either version 2.1 of the
7 * License, or  (at your option) any later version. This library is
8 * distributed in the  hope that it will be useful, but WITHOUT ANY
9 * WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE.
11 * See the GNU Lesser General Public License for more details.
12 *
13 * You should have received a copy of the GNU Lesser General Public License
14 * along with this library; if not, write to the Free Software Foundation,
15 * Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307 USA
16 */
17#ifndef _VNET_CONNECTION_H_
18#define _VNET_CONNECTION_H_
19
20#include <netinet/in.h>
21
22#include "iostream.h"
23#include "select.h"
24
25/** A connection.
26 * The underlying transport is a socket.
27 * Contains in and out streams using the socket.
28 */
29typedef struct Conn {
30    struct sockaddr_in addr;
31    int sock;
32    int type;
33    int mode; // select mode
34    IOStream *in;
35    IOStream *out;
36    int (*fn)(struct Conn *conn, int mode);
37    void *data;
38} Conn;
39
40typedef struct ConnList {
41    Conn *conn;
42    struct ConnList *next;
43} ConnList;
44
45extern ConnList * ConnList_add(ConnList *l, Conn *conn);
46extern ConnList * ConnList_del(ConnList *l, Conn *conn);
47extern void ConnList_close(ConnList *l);
48extern void ConnList_select(ConnList *l, SelectSet *set);
49extern ConnList * ConnList_handle(ConnList *l, SelectSet *set);
50   
51extern Conn * Conn_new(int (*fn)(struct Conn *conn, int mode), void *data);
52extern int Conn_init(Conn *conn, int sock, int type, int mode, struct sockaddr_in addr);
53extern int Conn_connect(Conn *conn, int type, struct in_addr ipaddr, uint16_t port);
54extern void Conn_select(Conn *conn, SelectSet *set);
55extern int Conn_handle(Conn *conn, SelectSet *set);
56extern void Conn_close(Conn *conn);
57extern int Conn_socket(int socktype, uint32_t saddr, uint32_t port, int flags, Conn **val);
58
59/** Socket flags. */
60enum {
61    VSOCK_REUSE     =  1,
62    VSOCK_BIND      =  2,
63    VSOCK_CONNECT   =  4,
64    VSOCK_BROADCAST =  8,
65    VSOCK_MULTICAST = 16,
66 };
67
68extern int create_socket(int socktype, uint32_t saddr, uint32_t port, int flags, int *sock);
69extern int setsock_reuse(int sock, int val);
70extern int setsock_broadcast(int sock, int val);
71extern int setsock_multicast(int sock, uint32_t iaddr, uint32_t maddr);
72extern int setsock_multicast_ttl(int sock, uint8_t ttl);
73extern int setsock_pktinfo(int sock, int val);
74extern char * socket_flags(int flags);
75
76#endif /* ! _VNET_CONNECTION_H_ */
Note: See TracBrowser for help on using the repository browser.