Fix broken implem
This commit is contained in:
parent
f9b8f8a869
commit
1032ee7032
2 changed files with 29 additions and 19 deletions
|
@ -32,18 +32,27 @@
|
|||
(type->int type)
|
||||
(protocol->int protocol)))
|
||||
|
||||
(define-ftype
|
||||
(define-ftype
|
||||
[socklen_t unsigned-32]
|
||||
[in_addr_t unsigned-32]
|
||||
[in_addr
|
||||
(struct
|
||||
(s_addr unsigned-long))]
|
||||
|
||||
[addr in_addr_t])]
|
||||
[sa_family_t unsigned-short]
|
||||
[in_port_t unsigned-16]
|
||||
[sockaddr_common
|
||||
(struct
|
||||
[family sa_family_t])]
|
||||
[sockaddr
|
||||
(struct
|
||||
[common sockaddr_common]
|
||||
[data (array 14 char)])]
|
||||
[sockaddr_in
|
||||
(struct
|
||||
(sin_family short)
|
||||
(sin_port unsigned-short)
|
||||
(sin_addr in_addr)
|
||||
(sin_zero (array 8 char)))]
|
||||
)
|
||||
[common sockaddr_common]
|
||||
[port in_port_t]
|
||||
[addr in_addr]
|
||||
[zero (array 8 char)])])
|
||||
|
||||
(define (level->int flag)
|
||||
(case flag
|
||||
|
@ -66,7 +75,7 @@
|
|||
(define (inet_ntop af src dst size)
|
||||
((foreign-procedure
|
||||
"inet_ntop"
|
||||
(int void* (* char) int)
|
||||
(int void* (* char) unsigned-32)
|
||||
string)
|
||||
(domain->int af)
|
||||
src dst size))
|
||||
|
@ -107,7 +116,7 @@
|
|||
(define (recvfrom sockfd buf len msgflag src-addr addrlen)
|
||||
((foreign-procedure
|
||||
"recvfrom"
|
||||
(int void* int int (* sockaddr_in) (* int))
|
||||
(int void* size_t int (* sockaddr_in) (* socklen_t))
|
||||
int)
|
||||
sockfd
|
||||
buf
|
||||
|
|
|
@ -26,14 +26,14 @@
|
|||
(ftype-sizeof sockaddr_in)
|
||||
(lambda (raw-addr)
|
||||
(let ([addr (make-ftype-pointer sockaddr_in raw-addr)])
|
||||
(ftype-set! sockaddr_in (sin_family) addr (domain->int 'AF_INET))
|
||||
(ftype-set! sockaddr_in (sin_port) addr (htons port))
|
||||
(ftype-set! sockaddr_in (common family) addr (domain->int 'AF_INET))
|
||||
(ftype-set! sockaddr_in (port) addr (htons port))
|
||||
(check-err
|
||||
(inet_pton
|
||||
'AF_INET
|
||||
host
|
||||
(ftype-pointer-address
|
||||
(ftype-&ref sockaddr_in (sin_addr) addr)))
|
||||
(ftype-&ref sockaddr_in (addr) addr)))
|
||||
"Unable to convert your IP address to binary")
|
||||
(bind
|
||||
sock
|
||||
|
@ -46,9 +46,9 @@
|
|||
[buf (foreign-alloc bufsize)]
|
||||
[straddr (make-ftype-pointer char
|
||||
(foreign-alloc straddrsize))]
|
||||
[addrlen (make-ftype-pointer int
|
||||
(foreign-alloc (ftype-sizeof int)))]
|
||||
[_ (ftype-set! int () addrlen (ftype-sizeof sockaddr_in))]
|
||||
[addrlen (make-ftype-pointer socklen_t
|
||||
(foreign-alloc (ftype-sizeof socklen_t)))]
|
||||
[_ (ftype-set! socklen_t () addrlen (ftype-sizeof sockaddr_in))]
|
||||
[addr (make-ftype-pointer
|
||||
sockaddr_in
|
||||
(foreign-alloc (ftype-sizeof sockaddr_in)))]
|
||||
|
@ -57,14 +57,15 @@
|
|||
(loop
|
||||
(lambda ()
|
||||
(let ([nread (recvfrom sock buf bufsize 'MSG_DEFAULT addr addrlen)])
|
||||
(printf "~a~%" (ftype-pointer->sexpr addr))
|
||||
(fx
|
||||
(inet_ntop
|
||||
'AF_INET
|
||||
(ftype-pointer-address
|
||||
(ftype-&ref sockaddr_in (sin_addr) addr))
|
||||
(ftype-&ref sockaddr_in (addr) addr))
|
||||
straddr
|
||||
straddrsize)
|
||||
(ntohs (ftype-ref sockaddr_in (sin_port) addr))
|
||||
(ntohs (ftype-ref sockaddr_in (port) addr))
|
||||
buf nread))))
|
||||
|
||||
(foreign-free (ftype-pointer-address straddr))
|
||||
|
@ -75,7 +76,7 @@
|
|||
(udpsock-create
|
||||
(lambda (sock)
|
||||
(udpsock-reuseaddr sock)
|
||||
(udpsock-bind sock "0.0.0.0" 1337)
|
||||
(udpsock-bind sock "127.0.0.8" 1337)
|
||||
(udpsock-readblock
|
||||
sock
|
||||
(lambda (host port buf size)
|
||||
|
|
Loading…
Reference in a new issue