@@ 83-103 (lines=21) @@ | ||
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 | break; |
|
98 | default: |
|
99 | throw new \UnexpectedValueException("Invalid protocol."); |
|
100 | ||
101 | } |
|
102 | return $result; |
|
103 | } |
|
104 | ||
105 | protected static function decodeAddress($version, $address, $protocol) |
|
106 | { |
|
@@ 105-126 (lines=22) @@ | ||
102 | return $result; |
|
103 | } |
|
104 | ||
105 | protected static function decodeAddress($version, $address, $protocol) |
|
106 | { |
|
107 | if ($version == 1) { |
|
108 | return $address; |
|
109 | } |
|
110 | switch ($protocol) { |
|
111 | case self::TCP4: |
|
112 | case self::UDP4: |
|
113 | case self::TCP6: |
|
114 | case self::UDP6: |
|
115 | $result = inet_ntop($address); |
|
116 | break; |
|
117 | case self::USTREAM: |
|
118 | case self::USOCK: |
|
119 | throw new \Exception("Unix socket not (yet) supported."); |
|
120 | break; |
|
121 | default: |
|
122 | throw new \UnexpectedValueException("Invalid protocol."); |
|
123 | ||
124 | } |
|
125 | return $result; |
|
126 | } |
|
127 | ||
128 | /** |
|
129 | * @return string |
|
@@ 137-157 (lines=21) @@ | ||
134 | return $this->encodeAddress($this->sourceAddress, $this->protocol) . ($this->version == 1 ? " " : "") .$this->encodeAddress($this->targetAddress, $this->protocol); |
|
135 | } |
|
136 | ||
137 | protected function encodePort($port, $protocol) { |
|
138 | if ($this->version == 1) { |
|
139 | return $port; |
|
140 | } |
|
141 | switch ($protocol) { |
|
142 | case self::TCP4: |
|
143 | case self::UDP4: |
|
144 | case self::TCP6: |
|
145 | case self::UDP6: |
|
146 | $result = pack('n', $port); |
|
147 | break; |
|
148 | case self::USTREAM: |
|
149 | case self::USOCK: |
|
150 | throw new \Exception("Unix socket not (yet) supported."); |
|
151 | break; |
|
152 | default: |
|
153 | throw new \UnexpectedValueException("Invalid protocol."); |
|
154 | ||
155 | } |
|
156 | return $result; |
|
157 | } |
|
158 | ||
159 | /** |
|
160 | * @return string |