Implement bind
This commit is contained in:
parent
b10b219003
commit
6f49424fb0
2 changed files with 18 additions and 16 deletions
|
@ -63,11 +63,11 @@
|
||||||
(domain->int af)
|
(domain->int af)
|
||||||
src dst))
|
src dst))
|
||||||
|
|
||||||
; htons
|
|
||||||
(define (htons host)
|
(define (htons host)
|
||||||
((foreign-procedure
|
((foreign-procedure
|
||||||
"htons"
|
"htons"
|
||||||
(
|
(short)
|
||||||
|
short) host))
|
||||||
|
|
||||||
(define (setsockopt sockfd level optname optval optlen)
|
(define (setsockopt sockfd level optname optval optlen)
|
||||||
((foreign-procedure
|
((foreign-procedure
|
||||||
|
|
|
@ -32,22 +32,24 @@
|
||||||
(ftype-sizeof int))
|
(ftype-sizeof int))
|
||||||
"Unable to set REUSE ADDRESS"))))
|
"Unable to set REUSE ADDRESS"))))
|
||||||
|
|
||||||
(define (udpsock-bind sock addr port)
|
(define (udpsock-bind sock host port)
|
||||||
(alloc
|
(alloc
|
||||||
(ftype-sizeof sockaddr_in)
|
(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_family) addr (domain->int 'AF_INET))
|
||||||
(ftype-set! sockaddr_in (sin_port) addr (htons port))
|
(ftype-set! sockaddr_in (sin_port) addr (htons port))
|
||||||
(check-err
|
(check-err
|
||||||
(inet_pton
|
(inet_pton
|
||||||
'AF_INET
|
'AF_INET
|
||||||
addr
|
host
|
||||||
(ftype-&ref sockaddr_in (sin_addr) addr))
|
(ftype-pointer-address
|
||||||
|
(ftype-&ref sockaddr_in (sin_addr) addr)))
|
||||||
"Unable to convert your IP address to binary")
|
"Unable to convert your IP address to binary")
|
||||||
(bind
|
(bind
|
||||||
sock
|
sock
|
||||||
addr
|
(ftype-pointer-address addr)
|
||||||
(ftype-sizeof addr)))))
|
(ftype-sizeof sockaddr_in))))))
|
||||||
|
|
||||||
(udpsock-create
|
(udpsock-create
|
||||||
(lambda (sock)
|
(lambda (sock)
|
||||||
|
|
Loading…
Reference in a new issue