debuggers.hg

view tools/vnet/vnetd/connection.h @ 0:7d21f7218375

Exact replica of unstable on 051908 + README-this
author Mukesh Rathor
date Mon May 19 15:34:57 2008 -0700 (2008-05-19)
parents
children
line source
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_
20 #include <netinet/in.h>
22 #include "iostream.h"
23 #include "select.h"
25 /** A connection.
26 * The underlying transport is a socket.
27 * Contains in and out streams using the socket.
28 */
29 typedef 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;
40 typedef struct ConnList {
41 Conn *conn;
42 struct ConnList *next;
43 } ConnList;
45 extern ConnList * ConnList_add(ConnList *l, Conn *conn);
46 extern ConnList * ConnList_del(ConnList *l, Conn *conn);
47 extern void ConnList_close(ConnList *l);
48 extern void ConnList_select(ConnList *l, SelectSet *set);
49 extern ConnList * ConnList_handle(ConnList *l, SelectSet *set);
51 extern Conn * Conn_new(int (*fn)(struct Conn *conn, int mode), void *data);
52 extern int Conn_init(Conn *conn, int sock, int type, int mode, struct sockaddr_in addr);
53 extern int Conn_connect(Conn *conn, int type, struct in_addr ipaddr, uint16_t port);
54 extern void Conn_select(Conn *conn, SelectSet *set);
55 extern int Conn_handle(Conn *conn, SelectSet *set);
56 extern void Conn_close(Conn *conn);
57 extern int Conn_socket(int socktype, uint32_t saddr, uint32_t port, int flags, Conn **val);
59 /** Socket flags. */
60 enum {
61 VSOCK_REUSE = 1,
62 VSOCK_BIND = 2,
63 VSOCK_CONNECT = 4,
64 VSOCK_BROADCAST = 8,
65 VSOCK_MULTICAST = 16,
66 };
68 extern int create_socket(int socktype, uint32_t saddr, uint32_t port, int flags, int *sock);
69 extern int setsock_reuse(int sock, int val);
70 extern int setsock_broadcast(int sock, int val);
71 extern int setsock_multicast(int sock, uint32_t iaddr, uint32_t maddr);
72 extern int setsock_multicast_ttl(int sock, uint8_t ttl);
73 extern int setsock_pktinfo(int sock, int val);
74 extern char * socket_flags(int flags);
76 #endif /* ! _VNET_CONNECTION_H_ */