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)
|
||||||
(ftype-set! sockaddr_in (sin_family) addr (domain->int 'AF_INET))
|
(let ([addr (make-ftype-pointer sockaddr_in raw-addr)])
|
||||||
(ftype-set! sockaddr_in (sin_port) addr (htons port))
|
(ftype-set! sockaddr_in (sin_family) addr (domain->int 'AF_INET))
|
||||||
(check-err
|
(ftype-set! sockaddr_in (sin_port) addr (htons port))
|
||||||
(inet_pton
|
(check-err
|
||||||
'AF_INET
|
(inet_pton
|
||||||
addr
|
'AF_INET
|
||||||
(ftype-&ref sockaddr_in (sin_addr) addr))
|
host
|
||||||
"Unable to convert your IP address to binary")
|
(ftype-pointer-address
|
||||||
(bind
|
(ftype-&ref sockaddr_in (sin_addr) addr)))
|
||||||
sock
|
"Unable to convert your IP address to binary")
|
||||||
addr
|
(bind
|
||||||
(ftype-sizeof addr)))))
|
sock
|
||||||
|
(ftype-pointer-address addr)
|
||||||
|
(ftype-sizeof sockaddr_in))))))
|
||||||
|
|
||||||
(udpsock-create
|
(udpsock-create
|
||||||
(lambda (sock)
|
(lambda (sock)
|
||||||
|
|
Loading…
Reference in a new issue