Remove old CVS $Id$ keyword
[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 ;;;; This file, part of UFFI, is Copyright (c) 2002-2010 by Kevin M. Rosenberg
11 ;;;;
12 ;;;; *************************************************************************
13
14 (in-package :cl-user)
15
16 ;; Values for linux
17 (uffi:def-constant PF_UNIX 1)
18 (uffi:def-constant SOCK_STREAM 1)
19
20 (uffi:def-function ("socket" c-socket)
21     ((family :int)
22      (type :int)
23      (protocol :int))
24     :returning :int)
25
26 (uffi:def-function ("connect" c-connect)
27     ((sockfd :int)
28      (serv-addr :void-pointer)
29      (addr-len :int))
30     :returning :int)
31
32 (defun connect-to-file-socket (filename)
33   (let ((socket (c-socket PF_UNIX SOCK_STREAM 0)))
34     (if (plusp socket)
35         (let ((stream (c-connect socket filename (length filename))))
36           stream)
37       (error "Unable to create socket"))))