1 | /* |
---|
2 | * shared_socket.h - Shared mnemonics used by the socket related syscalls. |
---|
3 | * |
---|
4 | * Author Alain Greiner (2016,2017,2018,2019,2020) |
---|
5 | * |
---|
6 | * Copyright (c) UPMC Sorbonne Universites |
---|
7 | * |
---|
8 | * This file is part of ALMOS-MKH. |
---|
9 | * |
---|
10 | * ALMOS-MKH is free software; you can redistribute it and/or modify it |
---|
11 | * under the terms of the GNU General Public License as published by |
---|
12 | * the Free Software Foundation; version 2.0 of the License. |
---|
13 | * |
---|
14 | * ALMOS-MKH is distributed in the hope that it will be useful, but |
---|
15 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
---|
17 | * General Public License for more details. |
---|
18 | * |
---|
19 | * You should have received a copy of the GNU General Public License |
---|
20 | * along with ALMOS-MKH; if not, write to the Free Software Foundation, |
---|
21 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
---|
22 | */ |
---|
23 | |
---|
24 | #ifndef _SHARED_SOCKET_H_ |
---|
25 | #define _SHARED_SOCKET_H_ |
---|
26 | |
---|
27 | /******************************************************************************************* |
---|
28 | * This defines the mnemonics for the domains (protocol families). |
---|
29 | ******************************************************************************************/ |
---|
30 | |
---|
31 | #define AF_LOCAL 1 |
---|
32 | #define AF_INET 2 |
---|
33 | |
---|
34 | /******************************************************************************************* |
---|
35 | * This defines the mnemonics for the socket types. |
---|
36 | ******************************************************************************************/ |
---|
37 | |
---|
38 | #define SOCK_DGRAM 0 |
---|
39 | #define SOCK_STREAM 1 |
---|
40 | |
---|
41 | /******************************************************************************************* |
---|
42 | * This defines macros for endiannes handling. |
---|
43 | ******************************************************************************************/ |
---|
44 | |
---|
45 | /* |
---|
46 | #define HTONS( x ) (((x >> 8) & 0x00FF) + ((x << 8) & 0XFF00)) |
---|
47 | |
---|
48 | #define HTONL( x ) (((x >> 24) & 0x000000FF) + \ |
---|
49 | ((x >> 8 ) & 0x0000FF00) + \ |
---|
50 | ((x << 8 ) & 0x00FF0000) + \ |
---|
51 | ((x << 24) & 0xFF000000)) |
---|
52 | */ |
---|
53 | |
---|
54 | #define HTONS( x ) (x) |
---|
55 | |
---|
56 | #define HTONL( x ) (x) |
---|
57 | |
---|
58 | /******************************************************************************************* |
---|
59 | * This enum defines the user operation mnemonics for socket access. |
---|
60 | ******************************************************************************************/ |
---|
61 | |
---|
62 | typedef enum |
---|
63 | { |
---|
64 | SOCK_CREATE = 0, |
---|
65 | SOCK_BIND = 1, |
---|
66 | SOCK_LISTEN = 2, |
---|
67 | SOCK_CONNECT = 3, |
---|
68 | SOCK_ACCEPT = 4, |
---|
69 | SOCK_SEND = 5, |
---|
70 | SOCK_RECV = 6, |
---|
71 | SOCK_SENDTO = 7, |
---|
72 | SOCK_RECVFROM = 8, |
---|
73 | } |
---|
74 | socket_operation_type_t; |
---|
75 | |
---|
76 | /***************************************************************************************** |
---|
77 | * These structures define an user defined address in the communication space. |
---|
78 | * - sockaddr is the generic structure required by bind(), connect() & accept(), |
---|
79 | * that supports various socket types. |
---|
80 | * _ sockaddr_in is the specific structure, used to build an IPv4 network address |
---|
81 | * composed of an IP_address (32 bits) and a port_number (16 bits). |
---|
82 | ****************************************************************************************/ |
---|
83 | |
---|
84 | typedef struct sockaddr |
---|
85 | { |
---|
86 | unsigned short sa_domain; // protocols family |
---|
87 | char sa_data[14]; // address (format depends on sa_domain) |
---|
88 | } |
---|
89 | sockaddr_t; |
---|
90 | |
---|
91 | typedef struct sockaddr_in |
---|
92 | { |
---|
93 | unsigned short sin_domain; // AF_INET / AF_UNIX |
---|
94 | unsigned short sin_port; // port number |
---|
95 | unsigned long sin_addr; // IP address |
---|
96 | } |
---|
97 | sockaddr_in_t; |
---|
98 | |
---|
99 | |
---|
100 | #endif // _SHARED_SOCKET_H_ |
---|
101 | |
---|
102 | |
---|