File tree 4 files changed +19
-0
lines changed
4 files changed +19
-0
lines changed Original file line number Diff line number Diff line change @@ -30,6 +30,7 @@ module type S = sig
30
30
and type write_error : = write_error
31
31
32
32
val dst : flow -> ipaddr * int
33
+ val src : flow -> ipaddr * int
33
34
val write_nodelay : flow -> Cstruct .t -> (unit , write_error ) result Lwt .t
34
35
val writev_nodelay : flow -> Cstruct .t list -> (unit , write_error ) result Lwt .t
35
36
val create_connection : ?keepalive : Keepalive .t -> t -> ipaddr * int -> (flow , error ) result Lwt .t
Original file line number Diff line number Diff line change @@ -53,6 +53,10 @@ module type S = sig
53
53
(* * Get the destination IP address and destination port that a
54
54
flow is currently connected to. *)
55
55
56
+ val src : flow -> ipaddr * int
57
+ (* * Get the source IP address and source port that a flow is currently
58
+ connected to. *)
59
+
56
60
val write_nodelay : flow -> Cstruct .t -> (unit , write_error ) result Lwt .t
57
61
(* * [write_nodelay flow buffer] writes the contents of [buffer]
58
62
to the flow. The thread blocks until all data has been successfully
Original file line number Diff line number Diff line change @@ -78,6 +78,18 @@ let dst fd =
78
78
in
79
79
ip, port
80
80
81
+ let src fd =
82
+ match Lwt_unix. getsockname fd with
83
+ | Unix. ADDR_UNIX _ ->
84
+ raise (Failure " unexpected: got a unix instead of tcp sock" )
85
+ | Unix. ADDR_INET (ia ,port ) ->
86
+ let ip = Ipaddr_unix. of_inet_addr ia in
87
+ let ip = match Ipaddr. to_v4 ip with
88
+ | None -> ip
89
+ | Some v4 -> Ipaddr. V4 v4
90
+ in
91
+ ip, port
92
+
81
93
let create_connection ?keepalive t (dst ,dst_port ) =
82
94
match
83
95
match dst, t.interface with
Original file line number Diff line number Diff line change @@ -637,6 +637,8 @@ struct
637
637
638
638
let dst pcb = WIRE. dst pcb.id, WIRE. dst_port pcb.id
639
639
640
+ let src pcb = WIRE. src pcb.id, WIRE. src_port pcb.id
641
+
640
642
let getid t dst dst_port =
641
643
(* TODO: make this more robust and recognise when all ports are gone *)
642
644
let islistener _t _port =
You can’t perform that action at this time.
0 commit comments