Do you know what port the router is using for NAT?  Are you sure that the 
router is not simply choosing the same port, so 25890 is both your local 
port and the port used by the router?

Alex.

On Wednesday, September 25, 2019 at 1:08:16 PM UTC+8, David Storrs wrote:
>
> udp-receive! is giving me unexpected results when my local machine -> 
> router -> server shows the UDP port of the process running on the 
> local machine instead of the one from the router.  I'm not sure how to 
> get the router's port instead. 
>
>
> The AWS server does this: 
>   (define-values (len senders-host senders-port) (udp-receive! socket 
> buffer)) 
>
> What I'm actually getting is: 
>
> senders-host:  <public IP address of my router> 
> senders-port: 25890 ; this is the UDP port bound by the process on the 
> local machine 
>
> What I'm expecting is: 
>
> senders-host:  <public IP address of my router> 
> senders-port:  <port number that my router chose when it relayed the 
> message from my machine to the AWS server> 
>
> I've been digging through the  RFCs for UDP and Traditional NAT 
> (https://www.ietf.org/rfc/rfc768.txt and 
> https://www.ietf.org/rfc/rfc3022.txt) to make sure that I haven't 
> randomly gotten confused about how routers work but it seems to be 
> what I recall: The local machine sends to the router using the port 
> number 25890, the router rewrites it to an arbitrary port number 
> chosen on the fly, the AWS server sees the router's assigned port and 
> not 25890. 
>
> What am I missing here?  I'm sure it's something embarrassingly obvious. 
>
>
>
> Simplified form of code for reference: 
>
> ------------------- 
> shared code 
> ------------------- 
> (struct Message (message-id attributes)     #:prefab) 
> (struct Binding-Request          Message () #:prefab) 
> (struct Binding-Success-Response Message () #:prefab) 
> (struct transport-address (ip port) #:prefab) 
>
> (define (write-to-bytes v) 
>   (define out (open-output-bytes)) 
>   (write v out) 
>   (get-output-bytes out)) 
>
> ------------------- 
> local machine: 
> ------------------- 
> (define socket (udp-open-socket #f #f)) 
> (udp-bind! socket #f 25890 #t) 
> (thread 
>  (thunk 
>   (define-values (len senders-host senders-port) (udp-receive! socket 
> buffer)) 
>   (log-msg-debug "host: ~a, port ~a, buffer ~a " senders-host 
> senders-port buffer))) 
>
> (udp-send-to socket default-host default-port 
>              (wrap (Binding-Request 17 (hash)))) 
>
> ----------------- 
> AWS server: 
> ----------------- 
> The server has its own UDP socket (bound to 54545, fwiw) and a receive 
> loop that identifies the Binding-Request and routes it to the 
> following code: 
>
>     (define-values (len senders-host senders-port) (udp-receive! 
> socket buffer) 
> (define mapped-address (transport-address senders-host senders-port)) 
>     (define msg-out 
>           (Binding-Success-Response mid 
>                                         (hasheq 'mapped-address 
> mapped-address))) 
>      (udp-send-to socket senders-host senders-port (wrap msg-out)) 
>

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/0fc8af6a-c50c-4a90-ba8e-64718161379e%40googlegroups.com.

Reply via email to