-
Notifications
You must be signed in to change notification settings - Fork 125
/
miniupnp.ml
49 lines (37 loc) · 1.53 KB
/
miniupnp.ml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
(*
Copyright © 2011 MLstate
This file is part of OPA.
OPA is free software: you can redistribute it and/or modify it under the
terms of the GNU Affero General Public License, version 3, as published by
the Free Software Foundation.
OPA is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
more details.
You should have received a copy of the GNU Affero General Public License
along with OPA. If not, see <http://www.gnu.org/licenses/>.
*)
type miniupnp_err =
| MINIUPNP_GENERIC_ERR of int ;;
let string_of_miniupnp_err = function
| MINIUPNP_GENERIC_ERR i -> Printf.sprintf "MINIUPNP_GENERIC_ERR : '%d'" i ;;
module Helpers =
struct
type result = Correct | Wrong of miniupnp_err ;;
let string_of_protocol protocol =
match protocol with
| `Udp -> "UDP"
| `Tcp -> "TCP" ;;
let open_a_port ~ip ~internalPort ~externalPort ~protocol =
let protocol = string_of_protocol protocol in
let ires = Stubsminiupnpc.open_a_port ip externalPort internalPort protocol in
match ires with
| 0 -> Correct
| _ -> Wrong (MINIUPNP_GENERIC_ERR ires) ;;
let close_a_port ~ip ~externalPort ~protocol =
let protocol = string_of_protocol protocol in
let ires = Stubsminiupnpc.close_a_port ip (string_of_int externalPort) protocol in
match ires with
| 0 -> Correct
| _ -> Wrong (MINIUPNP_GENERIC_ERR ires) ;;
end