58ef17c9d04acc527edf6e51bee9943b5a9b32af
[uffi.git] / examples / file-socket.lisp
1 ;;;; -*- Mode: LISP; Syntax: ANSI-Common-Lisp; Base: 10 -*-
2 ;;;; *************************************************************************
3 ;;;; FILE IDENTIFICATION
4 ;;;;
5 ;;;; Name:          file-socket.cl
6 ;;;; Purpose:       UFFI Example file to get a socket on a file
7 ;;;; Programmer:    Kevin M. Rosenberg
8 ;;;; Date Started:  Jul 2002
9 ;;;;
10 ;;;; $Id$
11 ;;;;
12 ;;;; This file, part of UFFI, is Copyright (c) 2002 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; UFFI users are granted the rights to distribute and use this software
15 ;;;; as governed by the terms of the Lisp Lesser GNU Public License
16 ;;;; (http://opensource.franz.com/preamble.html), also known as the LLGPL.
17 ;;;; *************************************************************************
18
19 (in-package :cl-user)
20
21 ;; Values for linux
22 (uffi:def-constant PF_UNIX 1)
23 (uffi:def-constant SOCK_STREAM 1)
24
25 (uffi:def-function ("socket" c-socket)
26     ((family :int)
27      (type :int)
28      (protocol :int))
29     :returning :int)
30
31 (uffi:def-function ("connect" c-connect)
32     ((sockfd :int)
33      (serv-addr :void-pointer)
34      (addr-len :int))
35     :returning :int)
36                   
37 (defun connect-to-file-socket (filename)
38   (let ((socket (c-socket PF_UNIX SOCK_STREAM 0)))
39     (if (plusp socket)
40         (let ((stream (c-connect socket filename (length filename))))
41           stream)
42       (error "Unable to create socket"))))