join 1.0
lightweight network framework library
Loading...
Searching...
No Matches
protocol.hpp
Go to the documentation of this file.
1
25#ifndef JOIN_CORE_PROTOCOL_HPP
26#define JOIN_CORE_PROTOCOL_HPP
27
28// libjoin.
29#include <join/endpoint.hpp>
30
31// C.
32#include <linux/netlink.h>
33#include <net/ethernet.h>
34
35namespace join
36{
37 template <class Protocol>
38 class BasicSocket;
39 template <class Protocol>
40 class BasicDatagramSocket;
41 template <class Protocol>
42 class BasicStreamSocket;
43 template <class Protocol>
44 class BasicTlsSocket;
45
46 template <class Protocol>
47 class BasicSocketStream;
48 template <class Protocol>
49 class BasicTlsStream;
50
51 template <class Protocol>
53 template <class Protocol>
55
56 template <class Protocol>
57 class BasicHttpClient;
58 template <class Protocol>
60
61 template <class Protocol>
62 class BasicHttpWorker;
63 template <class Protocol>
64 class BasicHttpServer;
65 template <class Protocol>
67
68 template <class Protocol>
69 class BasicSmtpClient;
70 template <class Protocol>
72
77 {
78 public:
81
85 constexpr UnixDgram () noexcept = default;
86
91 constexpr int family () const noexcept
92 {
93 return AF_UNIX;
94 }
95
100 constexpr int type () const noexcept
101 {
102 return SOCK_DGRAM;
103 }
104
109 constexpr int protocol () const noexcept
110 {
111 return 0;
112 }
113 };
114
119 {
120 public:
125
129 constexpr UnixStream () noexcept = default;
130
135 constexpr int family () const noexcept
136 {
137 return AF_UNIX;
138 }
139
144 constexpr int type () const noexcept
145 {
146 return SOCK_STREAM;
147 }
148
153 constexpr int protocol () const noexcept
154 {
155 return 0;
156 }
157 };
158
163 {
164 public:
167
172 constexpr Netlink (int proto = NETLINK_ROUTE) noexcept
173 : _proto (proto)
174 {
175 }
176
181 static inline Netlink& rt () noexcept
182 {
183 static Netlink route (NETLINK_ROUTE);
184 return route;
185 }
186
191 static inline Netlink& nf () noexcept
192 {
193 static Netlink netfilter (NETLINK_NETFILTER);
194 return netfilter;
195 }
196
201 constexpr int family () const noexcept
202 {
203 return AF_NETLINK;
204 }
205
210 constexpr int type () const noexcept
211 {
212 return SOCK_RAW;
213 }
214
219 constexpr int protocol () const noexcept
220 {
221 return _proto;
222 }
223
224 private:
226 int _proto;
227 };
228
235 constexpr bool operator== (const Netlink& a, const Netlink& b) noexcept
236 {
237 return a.protocol () == b.protocol ();
238 }
239
246 constexpr bool operator!= (const Netlink& a, const Netlink& b) noexcept
247 {
248 return !(a == b);
249 }
250
254 class Raw
255 {
256 public:
259
263 constexpr Raw () noexcept = default;
264
269 constexpr int family () const noexcept
270 {
271 return AF_PACKET;
272 }
273
278 constexpr int type () const noexcept
279 {
280 return SOCK_RAW;
281 }
282
287 constexpr int protocol () const noexcept
288 {
289 if (BYTE_ORDER == LITTLE_ENDIAN)
290 {
291 return (ETH_P_ALL >> 8) | (ETH_P_ALL << 8);
292 }
293 return ETH_P_ALL;
294 }
295 };
296
300 class Udp
301 {
302 public:
305
310 constexpr Udp (int family = AF_INET) noexcept
311 : _family (family)
312 {
313 }
314
319 static inline Udp& v4 () noexcept
320 {
321 static Udp udpv4 (AF_INET);
322 return udpv4;
323 }
324
329 static inline Udp& v6 () noexcept
330 {
331 static Udp udpv6 (AF_INET6);
332 return udpv6;
333 }
334
339 constexpr int family () const noexcept
340 {
341 return _family;
342 }
343
348 constexpr int type () const noexcept
349 {
350 return SOCK_DGRAM;
351 }
352
357 constexpr int protocol () const noexcept
358 {
359 return IPPROTO_UDP;
360 }
361
362 private:
364 int _family;
365 };
366
373 constexpr bool operator== (const Udp& a, const Udp& b) noexcept
374 {
375 return a.family () == b.family ();
376 }
377
384 constexpr bool operator!= (const Udp& a, const Udp& b) noexcept
385 {
386 return !(a == b);
387 }
388
392 class Icmp
393 {
394 public:
397
402 constexpr Icmp (int family = AF_INET) noexcept
403 : _family (family)
404 {
405 }
406
411 static inline Icmp& v4 () noexcept
412 {
413 static Icmp icmpv4 (AF_INET);
414 return icmpv4;
415 }
416
421 static inline Icmp& v6 () noexcept
422 {
423 static Icmp icmpv6 (AF_INET6);
424 return icmpv6;
425 }
426
431 constexpr int family () const noexcept
432 {
433 return _family;
434 }
435
440 constexpr int type () const noexcept
441 {
442 return SOCK_RAW;
443 }
444
449 constexpr int protocol () const noexcept
450 {
451 if (family () == AF_INET6)
452 {
453 return int (IPPROTO_ICMPV6);
454 }
455
456 return IPPROTO_ICMP;
457 }
458
459 private:
461 int _family;
462 };
463
470 constexpr bool operator== (const Icmp& a, const Icmp& b) noexcept
471 {
472 return a.family () == b.family ();
473 }
474
481 constexpr bool operator!= (const Icmp& a, const Icmp& b) noexcept
482 {
483 return !(a == b);
484 }
485
489 class Tcp
490 {
491 public:
496
501 constexpr Tcp (int family = AF_INET) noexcept
502 : _family (family)
503 {
504 }
505
510 static inline Tcp& v4 () noexcept
511 {
512 static Tcp tcpv4 (AF_INET);
513 return tcpv4;
514 }
515
520 static inline Tcp& v6 () noexcept
521 {
522 static Tcp tcpv6 (AF_INET6);
523 return tcpv6;
524 }
525
530 constexpr int family () const noexcept
531 {
532 return _family;
533 }
534
539 constexpr int type () const noexcept
540 {
541 return SOCK_STREAM;
542 }
543
548 constexpr int protocol () const noexcept
549 {
550 return IPPROTO_TCP;
551 }
552
553 private:
555 int _family;
556 };
557
564 constexpr bool operator== (const Tcp& a, const Tcp& b) noexcept
565 {
566 return a.family () == b.family ();
567 }
568
575 constexpr bool operator!= (const Tcp& a, const Tcp& b) noexcept
576 {
577 return !(a == b);
578 }
579
583 class Tls
584 {
585 public:
590
595 constexpr Tls (int family = AF_INET) noexcept
596 : _family (family)
597 {
598 }
599
604 static inline Tls& v4 () noexcept
605 {
606 static Tls tlsv4 (AF_INET);
607 return tlsv4;
608 }
609
614 static inline Tls& v6 () noexcept
615 {
616 static Tls tlsv6 (AF_INET6);
617 return tlsv6;
618 }
619
624 constexpr int family () const noexcept
625 {
626 return _family;
627 }
628
633 constexpr int type () const noexcept
634 {
635 return SOCK_STREAM;
636 }
637
642 constexpr int protocol () const noexcept
643 {
644 return IPPROTO_TCP;
645 }
646
647 private:
649 int _family;
650 };
651
658 constexpr bool operator== (const Tls& a, const Tls& b) noexcept
659 {
660 return a.family () == b.family ();
661 }
662
669 constexpr bool operator!= (const Tls& a, const Tls& b) noexcept
670 {
671 return !(a == b);
672 }
673
677 class Http
678 {
679 public:
687
692 constexpr Http (int family = AF_INET) noexcept
693 : _family (family)
694 {
695 }
696
701 static inline Http& v4 () noexcept
702 {
703 static Http httpv4 (AF_INET);
704 return httpv4;
705 }
706
711 static inline Http& v6 () noexcept
712 {
713 static Http httpv6 (AF_INET6);
714 return httpv6;
715 }
716
721 constexpr int family () const noexcept
722 {
723 return _family;
724 }
725
730 constexpr int type () const noexcept
731 {
732 return SOCK_STREAM;
733 }
734
739 constexpr int protocol () const noexcept
740 {
741 return IPPROTO_TCP;
742 }
743
744 private:
746 int _family;
747 };
748
755 constexpr bool operator== (const Http& a, const Http& b) noexcept
756 {
757 return a.family () == b.family ();
758 }
759
766 constexpr bool operator!= (const Http& a, const Http& b) noexcept
767 {
768 return !(a == b);
769 }
770
774 class Https
775 {
776 public:
784
789 constexpr Https (int family = AF_INET) noexcept
790 : _family (family)
791 {
792 }
793
798 static inline Https& v4 () noexcept
799 {
800 static Https httpsv4 (AF_INET);
801 return httpsv4;
802 }
803
808 static inline Https& v6 () noexcept
809 {
810 static Https httpsv6 (AF_INET6);
811 return httpsv6;
812 }
813
818 constexpr int family () const noexcept
819 {
820 return _family;
821 }
822
827 constexpr int type () const noexcept
828 {
829 return SOCK_STREAM;
830 }
831
836 constexpr int protocol () const noexcept
837 {
838 return IPPROTO_TCP;
839 }
840
841 private:
843 int _family;
844 };
845
852 constexpr bool operator== (const Https& a, const Https& b) noexcept
853 {
854 return a.family () == b.family ();
855 }
856
863 constexpr bool operator!= (const Https& a, const Https& b) noexcept
864 {
865 return !(a == b);
866 }
867
871 class Smtp
872 {
873 public:
878
883 constexpr Smtp (int family = AF_INET) noexcept
884 : _family (family)
885 {
886 }
887
892 static inline Smtp& v4 () noexcept
893 {
894 static Smtp smtpv4 (AF_INET);
895 return smtpv4;
896 }
897
902 static inline Smtp& v6 () noexcept
903 {
904 static Smtp smtpv6 (AF_INET6);
905 return smtpv6;
906 }
907
912 constexpr int family () const noexcept
913 {
914 return _family;
915 }
916
921 constexpr int type () const noexcept
922 {
923 return SOCK_STREAM;
924 }
925
930 constexpr int protocol () const noexcept
931 {
932 return IPPROTO_TCP;
933 }
934
935 private:
937 int _family;
938 };
939
946 constexpr bool operator== (const Smtp& a, const Smtp& b) noexcept
947 {
948 return a.family () == b.family ();
949 }
950
957 constexpr bool operator!= (const Smtp& a, const Smtp& b) noexcept
958 {
959 return !(a == b);
960 }
961
965 class Smtps
966 {
967 public:
972
977 constexpr Smtps (int family = AF_INET) noexcept
978 : _family (family)
979 {
980 }
981
986 static inline Smtps& v4 () noexcept
987 {
988 static Smtps smtpsv4 (AF_INET);
989 return smtpsv4;
990 }
991
996 static inline Smtps& v6 () noexcept
997 {
998 static Smtps smtpsv6 (AF_INET6);
999 return smtpsv6;
1000 }
1001
1006 constexpr int family () const noexcept
1007 {
1008 return _family;
1009 }
1010
1015 constexpr int type () const noexcept
1016 {
1017 return SOCK_STREAM;
1018 }
1019
1024 constexpr int protocol () const noexcept
1025 {
1026 return IPPROTO_TCP;
1027 }
1028
1029 private:
1031 int _family;
1032 };
1033
1040 constexpr bool operator== (const Smtps& a, const Smtps& b) noexcept
1041 {
1042 return a.family () == b.family ();
1043 }
1044
1051 constexpr bool operator!= (const Smtps& a, const Smtps& b) noexcept
1052 {
1053 return !(a == b);
1054 }
1055}
1056
1057#endif
basic datagram socket class.
Definition socket.hpp:645
basic HTTP client.
Definition httpclient.hpp:46
basic HTTPS client.
Definition httpclient.hpp:488
basic HTTPS server.
Definition httpserver.hpp:978
basic HTTP server.
Definition httpserver.hpp:643
basic HTTP worker.
Definition httpserver.hpp:81
basic internet endpoint class.
Definition endpoint.hpp:670
basic link layer endpoint class.
Definition endpoint.hpp:498
basic netlink endpoint class.
Definition endpoint.hpp:266
basic SMTP client.
Definition smtpclient.hpp:41
Basic SMTPS client.
Definition smtpclient.hpp:650
socket stream class.
Definition socketstream.hpp:329
basic socket class.
Definition socket.hpp:60
basic stream acceptor class.
Definition protocol.hpp:52
basic stream socket class.
Definition socket.hpp:1142
basic TLS acceptor class.
Definition protocol.hpp:54
basic TLS socket class.
Definition socket.hpp:1552
TLS stream class.
Definition socketstream.hpp:513
basic unix endpoint class.
Definition endpoint.hpp:98
HTTP protocol class.
Definition protocol.hpp:678
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:739
constexpr Http(int family=AF_INET) noexcept
create the HTTP protocol instance.
Definition protocol.hpp:692
static Http & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:701
static Http & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:711
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:730
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:721
HTTPS protocol class.
Definition protocol.hpp:775
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:836
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:818
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:827
static Https & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:808
static Https & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:798
constexpr Https(int family=AF_INET) noexcept
create the HTTPS protocol instance.
Definition protocol.hpp:789
ICMP protocol class.
Definition protocol.hpp:393
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:431
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:449
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:440
static Icmp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:421
static Icmp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:411
constexpr Icmp(int family=AF_INET) noexcept
create the icmp protocol instance.
Definition protocol.hpp:402
RAW protocol class.
Definition protocol.hpp:255
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:278
constexpr Raw() noexcept=default
default constructor.
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:269
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:287
SMTP protocol class.
Definition protocol.hpp:872
static Smtp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:892
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:930
static Smtp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:902
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:912
constexpr Smtp(int family=AF_INET) noexcept
create the SMTP protocol instance.
Definition protocol.hpp:883
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:921
SMTPS protocol class.
Definition protocol.hpp:966
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:1024
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:1015
constexpr Smtps(int family=AF_INET) noexcept
create the SMTPS protocol instance.
Definition protocol.hpp:977
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:1006
static Smtps & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:996
static Smtps & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:986
TCP protocol class.
Definition protocol.hpp:490
static Tcp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:520
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:539
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:530
constexpr Tcp(int family=AF_INET) noexcept
create the tcp protocol instance.
Definition protocol.hpp:501
static Tcp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:510
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:548
SSL/TLS protocol class.
Definition protocol.hpp:584
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:642
static Tls & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:614
static Tls & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:604
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:624
constexpr Tls(int family=AF_INET) noexcept
create the tcp protocol instance.
Definition protocol.hpp:595
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:633
UDP protocol class.
Definition protocol.hpp:301
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:348
static Udp & v6() noexcept
get protocol suitable for IPv6 address family.
Definition protocol.hpp:329
static Udp & v4() noexcept
get protocol suitable for IPv4 address family.
Definition protocol.hpp:319
constexpr Udp(int family=AF_INET) noexcept
construct the udp protocol instance.
Definition protocol.hpp:310
constexpr int family() const noexcept
get the protocol IP address family.
Definition protocol.hpp:339
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:357
unix datagram protocol class.
Definition protocol.hpp:77
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:100
constexpr UnixDgram() noexcept=default
construct the unix datagram protocol instance by default.
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:109
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:91
unix stream protocol class.
Definition protocol.hpp:119
constexpr UnixStream() noexcept=default
construct the unix stream protocol instance by default.
constexpr int type() const noexcept
get the protocol communication semantic.
Definition protocol.hpp:144
constexpr int family() const noexcept
get the protocol ip address family.
Definition protocol.hpp:135
constexpr int protocol() const noexcept
get the protocol type.
Definition protocol.hpp:153
Definition acceptor.hpp:32
bool operator!=(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are not equal.
Definition endpoint.hpp:195
bool operator==(const BasicUnixEndpoint< Protocol > &a, const BasicUnixEndpoint< Protocol > &b) noexcept
compare if endpoints are equal.
Definition endpoint.hpp:183