r10608: update license
[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-2005 by Kevin M. Rosenberg
13 ;;;;
14 ;;;; *************************************************************************
15
16 (in-package :cl-user)
17
18 ;; Values for linux
19 (uffi:def-constant PF_UNIX 1)
20 (uffi:def-constant SOCK_STREAM 1)
21
22 (uffi:def-function ("socket" c-socket)
23     ((family :int)
24      (type :int)
25      (protocol :int))
26     :returning :int)
27
28 (uffi:def-function ("connect" c-connect)
29     ((sockfd :int)
30      (serv-addr :void-pointer)
31      (addr-len :int))
32     :returning :int)
33                   
34 (defun connect-to-file-socket (filename)
35   (let ((socket (c-socket PF_UNIX SOCK_STREAM 0)))
36     (if (plusp socket)
37         (let ((stream (c-connect socket filename (length filename))))
38           stream)
39       (error "Unable to create socket"))))