@@ 83-101 (lines=19) @@ | ||
80 | ||
81 | } |
|
82 | ||
83 | protected function encodeAddress($address, $protocol) { |
|
84 | if ($this->version == 1) { |
|
85 | return $address; |
|
86 | } |
|
87 | switch ($protocol) { |
|
88 | case self::TCP4: |
|
89 | case self::UDP4: |
|
90 | case self::TCP6: |
|
91 | case self::UDP6: |
|
92 | $result = inet_pton($address); |
|
93 | break; |
|
94 | case self::USTREAM: |
|
95 | case self::USOCK: |
|
96 | throw new \Exception("Unix socket not (yet) supported."); |
|
97 | default: |
|
98 | throw new \UnexpectedValueException("Invalid protocol."); |
|
99 | } |
|
100 | return $result; |
|
101 | } |
|
102 | ||
103 | protected static function decodeAddress($version, $address, $protocol) |
|
104 | { |
|
@@ 103-123 (lines=21) @@ | ||
100 | return $result; |
|
101 | } |
|
102 | ||
103 | protected static function decodeAddress($version, $address, $protocol) |
|
104 | { |
|
105 | if ($version == 1) { |
|
106 | return $address; |
|
107 | } |
|
108 | switch ($protocol) { |
|
109 | case self::TCP4: |
|
110 | case self::UDP4: |
|
111 | case self::TCP6: |
|
112 | case self::UDP6: |
|
113 | $result = inet_ntop($address); |
|
114 | break; |
|
115 | case self::USTREAM: |
|
116 | case self::USOCK: |
|
117 | throw new \Exception("Unix socket not (yet) supported."); |
|
118 | default: |
|
119 | throw new \UnexpectedValueException("Invalid protocol."); |
|
120 | ||
121 | } |
|
122 | return $result; |
|
123 | } |
|
124 | ||
125 | /** |
|
126 | * @return string |
|
@@ 134-153 (lines=20) @@ | ||
131 | return $this->encodeAddress($this->sourceAddress, $this->protocol) . ($this->version == 1 ? " " : "") .$this->encodeAddress($this->targetAddress, $this->protocol); |
|
132 | } |
|
133 | ||
134 | protected function encodePort($port, $protocol) { |
|
135 | if ($this->version == 1) { |
|
136 | return $port; |
|
137 | } |
|
138 | switch ($protocol) { |
|
139 | case self::TCP4: |
|
140 | case self::UDP4: |
|
141 | case self::TCP6: |
|
142 | case self::UDP6: |
|
143 | $result = pack('n', $port); |
|
144 | break; |
|
145 | case self::USTREAM: |
|
146 | case self::USOCK: |
|
147 | throw new \Exception("Unix socket not (yet) supported."); |
|
148 | default: |
|
149 | throw new \UnexpectedValueException("Invalid protocol."); |
|
150 | ||
151 | } |
|
152 | return $result; |
|
153 | } |
|
154 | ||
155 | /** |
|
156 | * @return string |