2 // Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
3 // Kompetenzzentrum NETwork research (NET)
4 // David Wagner <david.wagner@fokus.fraunhofer.de>
6 // This program is free software; you can redistribute it and/or modify
7 // it under the terms of the GNU General Public License as published by
8 // the Free Software Foundation; either version 2 of the License, or
9 // (at your option) any later version.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this program; if not, write to the
18 // Free Software Foundation, Inc.,
19 // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 \brief UNProtocol non-inline non-template implementation */
24 #include "UNProtocol.hh"
25 //#include "UNProtocol.ih"
29 #include <sys/socket.h>
30 #include <sys/ioctl.h>
31 #include <linux/sockios.h> // for SIOCINQ / SIOCOUTQ
32 #include "../../../Utils/Exception.hh"
34 //#include "UNProtocol.mpp"
36 ///////////////////////////////cc.p////////////////////////////////////////
37 prefix_ unsigned senf::UNProtocol::available()
41 if (::ioctl(body().fd(),SIOCINQ,&n) < 0)
46 prefix_ bool senf::UNProtocol::eof()
52 prefix_ void senf::UNProtocol::connect(UNSocketAddress const & address)
55 if(::connect(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
59 prefix_ void senf::UNProtocol::bind(UNSocketAddress const & address)
62 if(::bind(body().fd(), address.sockaddr_p(), sizeof(sockaddr_un)) < 0)
69 prefix_ void senf::UNProtocol::close()
74 SocketProtocol::close();
77 prefix_ void senf::UNProtocol::terminate()
82 SocketProtocol::terminate();
85 prefix_ void senf::UNProtocol::check_and_unlink()
88 // struct sockaddr_un test;
90 // memset( (char*)&test, 0xff, sizeof( test));
91 // int fd = inputSocket.fd() ;
92 //// printf( "fd: %d\n", fd);
94 // int r = getsockname( fd, (struct sockaddr *)&test, &len);
99 // printf( "name: %d %d %s\n", r, len , test.sun_path);
100 // unsigned char *p = (unsigned char*) &test;for( r=0; r< len; r++) printf( "%2.2x ", (int)(p[r])); printf ("\n");
102 struct sockaddr_un test;
103 socklen_t len = sizeof( test);
104 int r = ::getsockname( body().fd(), (struct sockaddr *)&test, &len);
105 if( r == 0 && ::strlen(test.sun_path) > 0){
106 ::unlink( test.sun_path);
110 ///////////////////////////////cc.e////////////////////////////////////////
112 //#include "UNProtocol.mpp"
118 // comment-column: 40
119 // c-file-style: "senf"
120 // indent-tabs-mode: nil
121 // ispell-local-dictionary: "american"
122 // compile-command: "scons -u test"