syslog_rs/
socket.rs

1/*-
2 * syslog-rs - a syslog client translated from libc to rust
3 * 
4 * Copyright 2025 Aleksandr Morozov
5 * 
6 * The syslog-rs crate can be redistributed and/or modified
7 * under the terms of either of the following licenses:
8 *
9 *   1. the Mozilla Public License Version 2.0 (the “MPL”) OR
10 *                     
11 *   2. EUROPEAN UNION PUBLIC LICENCE v. 1.2 EUPL © the European Union 2007, 2016
12 */
13
14
15use std::fmt;
16
17
18/// An enum of types of the current syslog tap instance.
19#[derive(Copy, Clone, Debug, PartialEq, Eq)]
20pub enum TapType
21{
22    /// Not defined
23    None, 
24
25    /// Unprivileged socket used
26    UnPriv,
27
28    /// Privileged socket used
29    Priv,
30
31    /// A compatibility socket used
32    OldLog,
33
34    /// Custom unix datagram
35    CustomLog,
36
37    /// Writing to file directly
38    LocalFile,
39
40    /// Network UDP
41    NetUdp,
42
43    /// Network TCP
44    NetTcp,
45
46    /// Network TLS over TCP
47    NetTls,
48}
49
50impl fmt::Display for TapType
51{
52    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result 
53    {
54        match self
55        {
56            Self::None => 
57                write!(f, "NO TYPE"),
58            Self::UnPriv => 
59                write!(f, "UNPRIV"),
60            Self::Priv => 
61                write!(f, "PRIV"),
62            Self::OldLog =>
63                write!(f, "OLD LOG"),
64            Self::CustomLog => 
65                write!(f, "CUSTOM LOG"),
66            Self::LocalFile =>
67                write!(f, "LOCAL FILE"),
68            Self::NetUdp => 
69                write!(f, "NET UDP"),
70            Self::NetTcp => 
71                write!(f, "NET TCP"),
72            Self::NetTls => 
73                write!(f, "NET TLS TCP")
74        }
75    }
76}
77
78impl TapType
79{
80    pub(crate) 
81    fn is_priv(&self) -> bool
82    {
83        return *self == Self::Priv;
84    }
85
86    pub(crate) 
87    fn is_network(&self) -> bool
88    {
89        return *self == Self::NetTcp || *self == Self::NetUdp;
90    }
91
92    pub(crate)
93    fn is_file(&self) -> bool
94    {
95        return *self == Self::LocalFile;
96    }
97
98}