1 /*
2  * linc-protocol.h: This file is part of the linc library.
3  *
4  * Authors:
5  *    Elliot Lee     (sopwith@redhat.com)
6  *    Michael Meeks  (michael@ximian.com)
7  *    Mark McLouglin (mark@skynet.ie) & others
8  *
9  * Copyright 2001, Red Hat, Inc., Ximian, Inc.,
10  *                 Sun Microsystems, Inc.
11  */
12 #ifndef _LINK_PROTOCOL_H_
13 #define _LINK_PROTOCOL_H_
14 
15 #include <glib.h>
16 
17 G_BEGIN_DECLS
18 
19 #include <linc/linc-types.h>
20 #include <sys/types.h>
21 
22 #ifdef G_OS_WIN32
23 #  include <winsock2.h>
24 #  undef interface		/* #defined as struct! */
25 #else
26 #  include <sys/socket.h>
27 #  include <netdb.h>
28 #endif
29 
30 /* socklen_t seems rather un-portable */
31 typedef unsigned int LinkSockLen;
32 
33 typedef enum {
34 	LINK_PROTOCOL_SECURE     = 1<<0,
35 	LINK_PROTOCOL_NEEDS_BIND = 1<<1
36 } LinkProtocolFlags;
37 
38 typedef void (*LinkProtocolSetupFunc)       (int                     fd,
39 					     LinkConnectionOptions   cnx_flags);
40 typedef void (*LinkProtocolDestroyFunc)     (int                     fd,
41 					     const char             *host_info,
42 					     const char             *serv_info);
43 typedef struct sockaddr *(*LinkProtocolGetSockAddrFunc) (const LinkProtocolInfo *proto,
44 							 const char             *hostname,
45 							 const char             *service,
46 							 LinkSockLen            *saddr_len);
47 
48 typedef gboolean (*LinkProtocolGetSockInfoFunc) (const LinkProtocolInfo *proto,
49 						 const struct sockaddr  *sockaddr,
50 						 gchar                 **hostname,
51 						 gchar                 **service);
52 
53 typedef void (*LinkProtocolPostCreateFunc) (int fd,
54 					    struct sockaddr *sockaddr);
55 
56 typedef gboolean (*LinkProtocolIsLocal)         (const LinkProtocolInfo *proto,
57 						 const struct sockaddr  *sockaddr,
58 						 LinkSockLen             saddr_len);
59 
60 struct _LinkProtocolInfo {
61 	const char                 *name;
62 	int                         family;
63 	int                         addr_len;
64 	int                         stream_proto_num;
65 	LinkProtocolFlags           flags;
66 
67 	LinkProtocolSetupFunc       setup;
68 	LinkProtocolDestroyFunc     destroy;
69 	LinkProtocolGetSockAddrFunc get_sockaddr;
70 	LinkProtocolGetSockInfoFunc get_sockinfo;
71 	LinkProtocolIsLocal         is_local;
72 	LinkProtocolPostCreateFunc  post_create;
73 	/* This structure is private and may be extended in future */
74 	gpointer                    dummy[7];
75 };
76 
77 typedef enum {
78 	LINK_NET_ID_IS_LOCAL,
79 	LINK_NET_ID_IS_SHORT_HOSTNAME,
80 	LINK_NET_ID_IS_FQDN,
81 	LINK_NET_ID_IS_IPADDR,
82 	LINK_NET_ID_IS_CUSTOM
83 } LinkNetIdType;
84 
85 
86 LinkProtocolInfo * link_protocol_find     (const char *name);
87 LinkProtocolInfo * link_protocol_find_num (const int   family);
88 LinkProtocolInfo * link_protocol_all      (void);
89 char                    *link_get_tmpdir        (void);
90 void                     link_set_tmpdir        (const char *dir);
91 void                     link_use_local_hostname (LinkNetIdType use);
92 void                     link_set_local_hostname (const char *host_id);
93 const char*              link_get_local_hostname (void);
94 
95 G_END_DECLS
96 
97 #endif /* _LINK_PROTOCOL_H_ */
98