Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

ECL CFFI segfault

View gist:15dea89a0a7d591bba51
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
(ql:quickload :cffi)
 
(defpackage :sock-test
(:use :cl)
(:export :delay
:request))
(in-package :sock-test)
 
(defconstant +af-inet+ 2)
 
(cffi:defcstruct sockaddr-in
(sin-family :short)
(sin-port :unsigned-short)
(sin-addr :unsigned-int)
(sin-zero-0 :char)
(sin-zero-1 :char)
(sin-zero-2 :char)
(sin-zero-3 :char)
(sin-zero-4 :char)
(sin-zero-5 :char)
(sin-zero-6 :char)
(sin-zero-7 :char))
 
(defun create-sockaddr (address port)
(let ((sockaddr (cffi:foreign-alloc '(:pointer (:struct sockaddr-in))))
(size (cffi:foreign-type-size '(:struct sockaddr-in)))
(address (if (string= address "0.0.0.0")
nil
address)))
(cffi:foreign-funcall "memset" :pointer sockaddr :unsigned-char 0 :unsigned-char size)
(cffi:with-foreign-slots ((sin-family sin-port sin-addr) sockaddr (:struct sockaddr-in))
(setf sin-family +af-inet+
sin-port (cffi:foreign-funcall "htons" :int port :unsigned-short)
sin-addr (if address
(cffi:foreign-funcall "inet_addr" :string address :unsigned-long)
(cffi:foreign-funcall "htonl" :unsigned-long 0 :unsigned-long))))
(values sockaddr size)))
 
(compile 'create-sockaddr)
 
(create-sockaddr "50.116.25.201" 80)
 
Owner

GDB trace:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 2724.0x19d8]
0x00000143 in ?? ()
(gdb) bt
#0  0x00000143 in ?? ()
#1  0x00000000 in ?? ()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.