Implement bind

This commit is contained in:
Quentin 2020-07-09 14:16:50 +02:00
parent b10b219003
commit 6f49424fb0
2 changed files with 18 additions and 16 deletions

View file

@ -63,11 +63,11 @@
(domain->int af)
src dst))
; htons
(define (htons host)
((foreign-procedure
"htons"
(
(short)
short) host))
(define (setsockopt sockfd level optname optval optlen)
((foreign-procedure

View file

@ -32,22 +32,24 @@
(ftype-sizeof int))
"Unable to set REUSE ADDRESS"))))
(define (udpsock-bind sock addr port)
(define (udpsock-bind sock host port)
(alloc
(ftype-sizeof sockaddr_in)
(lambda (addr)
(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))
(check-err
(inet_pton
'AF_INET
addr
(ftype-&ref sockaddr_in (sin_addr) addr))
host
(ftype-pointer-address
(ftype-&ref sockaddr_in (sin_addr) addr)))
"Unable to convert your IP address to binary")
(bind
sock
addr
(ftype-sizeof addr)))))
(ftype-pointer-address addr)
(ftype-sizeof sockaddr_in))))))
(udpsock-create
(lambda (sock)