1 /*
2  * %CopyrightBegin%
3  *
4  * Copyright Ericsson AB 2001-2020. All Rights Reserved.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  *     http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  *
18  * %CopyrightEnd%
19  */
20 /*
21 * Purpose: Connect to any node at any host. (EI version)
22 */
23 
24 /* FIXME far to many includes here... */
25 
26 /* some send() functions use buffer on heap for "small" messages */
27 /* messages larger than this require call to malloc() */
28 
29 #ifndef _EI_CONNECT_H
30 #define _EI_CONNECT_H
31 
32 #include <stdlib.h>
33 #include <sys/types.h>
34 #include <fcntl.h>
35 
36 #ifdef __WIN32__
37 #include <winsock2.h>
38 #include <windows.h>
39 #include <winbase.h>
40 
41 #else /* some unix */
42 #include <unistd.h>
43 #include <sys/types.h>
44 #include <sys/times.h>
45 
46 #if TIME_WITH_SYS_TIME
47 # include <sys/time.h>
48 # include <time.h>
49 #else
50 # if HAVE_SYS_TIME_H
51 #  include <sys/time.h>
52 # else
53 #  include <time.h>
54 # endif
55 #endif
56 
57 #include <sys/socket.h>
58 #include <netinet/in.h>
59 #include <netinet/tcp.h>
60 #include <arpa/inet.h>
61 #include <netdb.h>
62 #include <sys/utsname.h>  /* for gen_challenge (NEED FIX?) */
63 #endif
64 
65 /* FIXME remove duplicate defintions */
66 
67 #define DEFBUF_SIZ 100
68 
69 /* rpc_from() uses a buffer this size */
70 #ifndef MAX_RECEIVE_BUF
71 # define MAX_RECEIVE_BUF 32*1024
72 #endif
73 
74 /* Distribution capability flags */
75 typedef EI_ULONGLONG DistFlags;
76 
77 #define DFLAG_PUBLISHED                   1
78 #define DFLAG_ATOM_CACHE                  2
79 #define DFLAG_EXTENDED_REFERENCES         4
80 #define DFLAG_DIST_MONITOR                8
81 #define DFLAG_FUN_TAGS                 0x10
82 #define DFLAG_NEW_FUN_TAGS             0x80
83 #define DFLAG_EXTENDED_PIDS_PORTS     0x100
84 #define DFLAG_EXPORT_PTR_TAG          0x200
85 #define DFLAG_BIT_BINARIES            0x400
86 #define DFLAG_NEW_FLOATS              0x800
87 #define DFLAG_SMALL_ATOM_TAGS        0x4000
88 #define DFLAG_UTF8_ATOMS            0x10000
89 #define DFLAG_MAP_TAG               0x20000
90 #define DFLAG_BIG_CREATION          0x40000
91 #define DFLAG_HANDSHAKE_23        0x1000000
92 #define DFLAG_UNLINK_ID           0x2000000
93 #define DFLAG_RESERVED           0xfc000000
94 #define DFLAG_NAME_ME            ((DistFlags)0x2 << 32)
95 #define DFLAG_V4_NC              (((DistFlags)0x4) << 32)
96 
97 /* Control message tags not exposed to user... */
98 #define ERL_UNLINK_ID                   35
99 #define ERL_UNLINK_ID_ACK               36
100 
101 
102 ei_cnode   *ei_fd_to_cnode(int fd);
103 int         ei_distversion(int fd);
104 const char* ei_getfdcookie(int fd);
105 short       ei_thiscreation(const ei_cnode* ec);
106 const char *ei_thiscookie(const ei_cnode* ec);
107 
108 int ei_do_receive_msg(int fd, int staticbuffer_p,
109 		      erlang_msg* msg, ei_x_buff* x, unsigned ms);
110 
111 #endif /* _EI_CONNECT_H */
112