This file is indexed.

/usr/include/happycoders/socket/tcpsocket.hh is in happycoders-libsocket-dev 1.6-1ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
** tcpsocket.hh
** Login : Julien Lemoine <speedblue@happycoders.org>
** Started on  Sun Mar  2 01:17:01 2003 Julien Lemoine
** $Id: tcpsocket.hh,v 1.3 2004/06/01 21:30:54 speedblue Exp $
**
** Copyright (C) 2003,2004 Julien Lemoine
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU Lesser General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
** GNU Lesser General Public License for more details.
**
** You should have received a copy of the GNU Lesser General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/

#ifndef   	TCPSOCKET_HH_
# define   	TCPSOCKET_HH_

#include "netsocket.hh"

namespace Network
{
  /// @brief This class represent a tcp connection (client and server)
  /// @author Julien Lemoine <speedblue at happycoders dot org>
  class TcpSocket : public NetSocket
  {
  public:
    TcpSocket(SOCKET_VERSION version = V4) :
      NetSocket(TCP, version)
    {}
    TcpSocket(PROTO_KIND pkind, SOCKET_VERSION version = V4) :
      NetSocket(TCP, pkind, version)
    {}
    TcpSocket(int socket, SOCKET_VERSION version = V4) :
      NetSocket(TCP, version)
    {
      _socket = socket;
    }
    TcpSocket(int socket, PROTO_KIND pkind, SOCKET_VERSION version = V4) :
      NetSocket(TCP, pkind, version)
    {
      _socket = socket;
    }

    virtual ~TcpSocket()
    {
      close();
    }

  public:
    /// @brief Connect as an TCP client
    /**
     * Here is an example of tcp client using libsocket :
     * <pre>
     * #include <stdlib.h>
     * #include <iostream>
     * #include <string>
     * #include "socket/tcpsocket.hh"
     *
     * int main(int argc, char **argv)
     * {
     *   Network::TcpSocket            client;
     *   std::string                   str;
     *
     *   if (argc < 3)
     *     {
     *       std::cout << "Use: " << argv[0] << " port hostname" << std::endl;
     *       exit(0);
     *     }
     *   try
     *     {
     *       client.connect(std::string(argv[2]), strtol(argv[1], NULL, 10));
     *       client >> str;
     *       std::cout << str << std::endl;
     *
     *       while (str != "quit")
     *         {
     *           std::cin >> str;
     *           client << str;
     *           client >> str;
     *         }
     *       client.close();
     *       exit (0);
     *     }
     *   catch (Network::Exception e) // catch all libsocket errors
     *     {
     *       std::cerr << e;
     *       exit(1);
     *     }
     *
     * }
     * </pre>
     */
    void	connect(const std::string& hostname, int port);
    /// @brief return ip of client (after an accept)
    std::string	get_ip(TcpSocket *client) const;

    /// @brief accept a new client (For server only)
    TcpSocket*	accept() const;
    /// @brief Connect as an TCP server (echo server)
    /**
     * Here is an example of tcp server using libsocket :
     * <pre>
     * #include <stdlib.h>
     * #include <iostream>
     * #include <string>
     * #include "socket/tcpsocket.hh"
     *
     * int main(int argc, char **argv)
     * {
     *   Network::TcpSocket            server;
     *   Network::TcpSocket            *client;
     *   std::string                   str;
     *
     *   if (argc < 2)
     *     {
     *       std::cout << "Use: " << argv[0] << " port" << std::endl;
     *       exit(0);
     *     }
     *   try
     *     {
     *       std::cout << "--- echo server ---" << std::endl;
     *       server.connect(strtol(argv[1], NULL, 10));
     *       client = server.accept();
     *       (*client) << "Welcome on test server";
     *       while (str != "quit")
     * 	       {
     *
     * 	         //(*client) >> str;
     * 	         // read with a timeout of 30 second and get port and host
     * 	         str = client->read(port, host, 30);
     * 	         std::cout << "[" << str << "] from [" << host << ":"
     * 		           << port << "]" << std::endl;
     * 	         (*client) << str;
     * 	       }
     *       server.close();
     *       exit (0);
     *     }
     *   catch (Network::Exception e) // catch all libsocket errors
     *     {
     *       std::cerr << e;
     *       exit(1);
     *     }
     * }
     * </pre>
     */
    void	connect(int port);
    /// @brief Close the connection
    void	close();

  protected:
    /// @brief Get a line from socket and store client hostname and
    /// port in port and host variable (when used with binary protocol)
    /// @exception NoConnection when there is no open socket
    /// @exception ConnectionClosed when there is no more connection
    /// @exception GetpeernameError when getpeername libc function
    /// return a negative value
    std::string	_read_line_bin(int socket, int& port,
			       std::string& host, unsigned int psize);
    /// @brief Get a line from socket (when used with binary protocol)
    /// @exception NoConnection when there is no open socket
    /// @exception ConnectionClosed when there is no more connection
    std::string	_read_line_bin(int socket, unsigned int psize);
  };
}

#endif	    /* !TCPSOCKET_HH_ */