vlc/src/network/tcp.c

297 lines
9.3 KiB
C
Raw Normal View History

2005-12-05 10:36:39 +01:00
/*****************************************************************************
* tcp.c:
*****************************************************************************
LGPL Re-license almost all of libVLC and libVLCcore to LGPLv2.1+ This move was authorized by the developers, either: - by e-mail, - by vote at the VideoLAN Dev Days 2011, - on the license website, - in a contract, oral or written. No objection was raised, so far. The developers agreeing are: Justus Piater Alexis Ballier Alexander Bethke Mohammed Adnène Trojette Alex Converse Alexey Sokolov Alexis de Lattre Andre Pang Anthony Loiseau Cyril Deguet André Weber Boris Dorès Brieuc Jeunhomme Benjamin Drung Hugo Beauzée-Luyssen Benoit Steiner Benjamin Pracht Bernie Purcell Przemyslaw Fiala Arnaud de Bossoreille de Ribou Brad Smith Nick Briggs Christopher Rath Christophe Courtaut Christopher Mueller Clement Chesnin Andres Krapf Damien Fouilleul David Flynn Sebastien Zwickert Antoine Cellerier Jérôme Decoodt Jérome Decoodt Dylan Yudaken Eduard Babayan Eugenio Jarosiewicz Elliot Murphy Eric Petit Erwan Tulou Etienne Membrives Ludovic Fauvet Fabio Ritrovato Tobias Güntner Jakub Wieczorek Frédéric Crozat Francois Cartegnie Laurent Aimar Florian G. Pflug Felix Paul Kühne Frank Enderle Rafaël Carré Simon Latapie Gildas Bazin Geoffroy Couprie Julien / Gellule Gildas Bazin Arnaud Schauly Toralf Niebuhr Vicente Jimenez Aguilar Derk-Jan Hartman Henri Fallon Ilkka Ollakka Olivier Teulière Rémi Duraffort Jakob Leben Jean-Baptiste Kempf Jean-Paul Saman Jean-Philippe Grimaldi Jean-François Massol Gaël Hendryckx Jakob Leben Jean-Marc Dressler Jai Menon Johan Bilien Johann Ransay Joris van Rooij JP Dinger Jean-Philippe André Adrien Grand Juha Jeronen Juho Vähä-Herttua Kaarlo Raiha Kaarlo Raiha Kamil Baldyga Keary Griffin Ken Self KO Myung-Hun Pierre Ynard Filippo Carone Loïc Minier Luca Barbato Lucas C. Villa Real Lukas Durfina Adrien Maglo Marc Ariberti Mark Lee Mark Moriarty Martin Storsjö Christophe Massiot Michel Kaempf Marian Ďurkovič Mirsal Ennaime Carlo Calabrò Damien Lucas Naohiro Koriyama Basos G Pierre Baillet Vincent Penquerc'h Olivier Aubert Pankaj Yadav Paul Corke Pierre d'Herbemont Philippe Morin Antoine Lejeune Michael Ploujnikov Jean-Marc Dressler Michael Hanselmann Rafaël Carré Ramiro Polla Rémi Denis-Courmont Renaud Dartus Richard Shepherd Faustino Osuna Arnaud Vallat Rob Jonson Robert Jedrzejczyk Steve Lhomme Rocky Bernstein Romain Goyet Rov Juvano Sam Hocevar Martin T. H. Sandsmark Sebastian Birk Sébastien Escudier Vincent Seguin Fabio Ritrovato Sigmund Augdal Helberg Casian Andrei Srikanth Raju Hannes Domani Stéphane Borel Stephan Krempel Stephan Assmus Tony Castley Pavlov Konstantin Eric Petit Tanguy Krotoff Dennis van Amerongen Michel Lespinasse Can Wu Xavier Marchesini Sébastien Toque Christophe Mutricy Yoann Peronneau Yohann Martineau Yuval Tze Scott Caudle Clément Stenac It is possible, that some minor piece of code was badly tracked, for some reasons (SVN, mainly) or that some small developers did not answer. However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3", and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and the very vast majority of developers have agreed (> 99.99% of the code, > 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
* Copyright (C) 2004-2005 VLC authors and VideoLAN
* Copyright (C) 2005-2006 Rémi Denis-Courmont
2005-12-05 10:36:39 +01:00
*
* Authors: Laurent Aimar <fenrir@videolan.org>
2019-09-04 21:10:51 +02:00
* Rémi Denis-Courmont
2005-12-05 10:36:39 +01:00
*
LGPL Re-license almost all of libVLC and libVLCcore to LGPLv2.1+ This move was authorized by the developers, either: - by e-mail, - by vote at the VideoLAN Dev Days 2011, - on the license website, - in a contract, oral or written. No objection was raised, so far. The developers agreeing are: Justus Piater Alexis Ballier Alexander Bethke Mohammed Adnène Trojette Alex Converse Alexey Sokolov Alexis de Lattre Andre Pang Anthony Loiseau Cyril Deguet André Weber Boris Dorès Brieuc Jeunhomme Benjamin Drung Hugo Beauzée-Luyssen Benoit Steiner Benjamin Pracht Bernie Purcell Przemyslaw Fiala Arnaud de Bossoreille de Ribou Brad Smith Nick Briggs Christopher Rath Christophe Courtaut Christopher Mueller Clement Chesnin Andres Krapf Damien Fouilleul David Flynn Sebastien Zwickert Antoine Cellerier Jérôme Decoodt Jérome Decoodt Dylan Yudaken Eduard Babayan Eugenio Jarosiewicz Elliot Murphy Eric Petit Erwan Tulou Etienne Membrives Ludovic Fauvet Fabio Ritrovato Tobias Güntner Jakub Wieczorek Frédéric Crozat Francois Cartegnie Laurent Aimar Florian G. Pflug Felix Paul Kühne Frank Enderle Rafaël Carré Simon Latapie Gildas Bazin Geoffroy Couprie Julien / Gellule Gildas Bazin Arnaud Schauly Toralf Niebuhr Vicente Jimenez Aguilar Derk-Jan Hartman Henri Fallon Ilkka Ollakka Olivier Teulière Rémi Duraffort Jakob Leben Jean-Baptiste Kempf Jean-Paul Saman Jean-Philippe Grimaldi Jean-François Massol Gaël Hendryckx Jakob Leben Jean-Marc Dressler Jai Menon Johan Bilien Johann Ransay Joris van Rooij JP Dinger Jean-Philippe André Adrien Grand Juha Jeronen Juho Vähä-Herttua Kaarlo Raiha Kaarlo Raiha Kamil Baldyga Keary Griffin Ken Self KO Myung-Hun Pierre Ynard Filippo Carone Loïc Minier Luca Barbato Lucas C. Villa Real Lukas Durfina Adrien Maglo Marc Ariberti Mark Lee Mark Moriarty Martin Storsjö Christophe Massiot Michel Kaempf Marian Ďurkovič Mirsal Ennaime Carlo Calabrò Damien Lucas Naohiro Koriyama Basos G Pierre Baillet Vincent Penquerc'h Olivier Aubert Pankaj Yadav Paul Corke Pierre d'Herbemont Philippe Morin Antoine Lejeune Michael Ploujnikov Jean-Marc Dressler Michael Hanselmann Rafaël Carré Ramiro Polla Rémi Denis-Courmont Renaud Dartus Richard Shepherd Faustino Osuna Arnaud Vallat Rob Jonson Robert Jedrzejczyk Steve Lhomme Rocky Bernstein Romain Goyet Rov Juvano Sam Hocevar Martin T. H. Sandsmark Sebastian Birk Sébastien Escudier Vincent Seguin Fabio Ritrovato Sigmund Augdal Helberg Casian Andrei Srikanth Raju Hannes Domani Stéphane Borel Stephan Krempel Stephan Assmus Tony Castley Pavlov Konstantin Eric Petit Tanguy Krotoff Dennis van Amerongen Michel Lespinasse Can Wu Xavier Marchesini Sébastien Toque Christophe Mutricy Yoann Peronneau Yohann Martineau Yuval Tze Scott Caudle Clément Stenac It is possible, that some minor piece of code was badly tracked, for some reasons (SVN, mainly) or that some small developers did not answer. However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3", and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and the very vast majority of developers have agreed (> 99.99% of the code, > 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
* 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.1 of the License, or
2005-12-05 10:36:39 +01:00
* (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
LGPL Re-license almost all of libVLC and libVLCcore to LGPLv2.1+ This move was authorized by the developers, either: - by e-mail, - by vote at the VideoLAN Dev Days 2011, - on the license website, - in a contract, oral or written. No objection was raised, so far. The developers agreeing are: Justus Piater Alexis Ballier Alexander Bethke Mohammed Adnène Trojette Alex Converse Alexey Sokolov Alexis de Lattre Andre Pang Anthony Loiseau Cyril Deguet André Weber Boris Dorès Brieuc Jeunhomme Benjamin Drung Hugo Beauzée-Luyssen Benoit Steiner Benjamin Pracht Bernie Purcell Przemyslaw Fiala Arnaud de Bossoreille de Ribou Brad Smith Nick Briggs Christopher Rath Christophe Courtaut Christopher Mueller Clement Chesnin Andres Krapf Damien Fouilleul David Flynn Sebastien Zwickert Antoine Cellerier Jérôme Decoodt Jérome Decoodt Dylan Yudaken Eduard Babayan Eugenio Jarosiewicz Elliot Murphy Eric Petit Erwan Tulou Etienne Membrives Ludovic Fauvet Fabio Ritrovato Tobias Güntner Jakub Wieczorek Frédéric Crozat Francois Cartegnie Laurent Aimar Florian G. Pflug Felix Paul Kühne Frank Enderle Rafaël Carré Simon Latapie Gildas Bazin Geoffroy Couprie Julien / Gellule Gildas Bazin Arnaud Schauly Toralf Niebuhr Vicente Jimenez Aguilar Derk-Jan Hartman Henri Fallon Ilkka Ollakka Olivier Teulière Rémi Duraffort Jakob Leben Jean-Baptiste Kempf Jean-Paul Saman Jean-Philippe Grimaldi Jean-François Massol Gaël Hendryckx Jakob Leben Jean-Marc Dressler Jai Menon Johan Bilien Johann Ransay Joris van Rooij JP Dinger Jean-Philippe André Adrien Grand Juha Jeronen Juho Vähä-Herttua Kaarlo Raiha Kaarlo Raiha Kamil Baldyga Keary Griffin Ken Self KO Myung-Hun Pierre Ynard Filippo Carone Loïc Minier Luca Barbato Lucas C. Villa Real Lukas Durfina Adrien Maglo Marc Ariberti Mark Lee Mark Moriarty Martin Storsjö Christophe Massiot Michel Kaempf Marian Ďurkovič Mirsal Ennaime Carlo Calabrò Damien Lucas Naohiro Koriyama Basos G Pierre Baillet Vincent Penquerc'h Olivier Aubert Pankaj Yadav Paul Corke Pierre d'Herbemont Philippe Morin Antoine Lejeune Michael Ploujnikov Jean-Marc Dressler Michael Hanselmann Rafaël Carré Ramiro Polla Rémi Denis-Courmont Renaud Dartus Richard Shepherd Faustino Osuna Arnaud Vallat Rob Jonson Robert Jedrzejczyk Steve Lhomme Rocky Bernstein Romain Goyet Rov Juvano Sam Hocevar Martin T. H. Sandsmark Sebastian Birk Sébastien Escudier Vincent Seguin Fabio Ritrovato Sigmund Augdal Helberg Casian Andrei Srikanth Raju Hannes Domani Stéphane Borel Stephan Krempel Stephan Assmus Tony Castley Pavlov Konstantin Eric Petit Tanguy Krotoff Dennis van Amerongen Michel Lespinasse Can Wu Xavier Marchesini Sébastien Toque Christophe Mutricy Yoann Peronneau Yohann Martineau Yuval Tze Scott Caudle Clément Stenac It is possible, that some minor piece of code was badly tracked, for some reasons (SVN, mainly) or that some small developers did not answer. However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3", and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and the very vast majority of developers have agreed (> 99.99% of the code, > 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
2005-12-05 10:36:39 +01:00
*
LGPL Re-license almost all of libVLC and libVLCcore to LGPLv2.1+ This move was authorized by the developers, either: - by e-mail, - by vote at the VideoLAN Dev Days 2011, - on the license website, - in a contract, oral or written. No objection was raised, so far. The developers agreeing are: Justus Piater Alexis Ballier Alexander Bethke Mohammed Adnène Trojette Alex Converse Alexey Sokolov Alexis de Lattre Andre Pang Anthony Loiseau Cyril Deguet André Weber Boris Dorès Brieuc Jeunhomme Benjamin Drung Hugo Beauzée-Luyssen Benoit Steiner Benjamin Pracht Bernie Purcell Przemyslaw Fiala Arnaud de Bossoreille de Ribou Brad Smith Nick Briggs Christopher Rath Christophe Courtaut Christopher Mueller Clement Chesnin Andres Krapf Damien Fouilleul David Flynn Sebastien Zwickert Antoine Cellerier Jérôme Decoodt Jérome Decoodt Dylan Yudaken Eduard Babayan Eugenio Jarosiewicz Elliot Murphy Eric Petit Erwan Tulou Etienne Membrives Ludovic Fauvet Fabio Ritrovato Tobias Güntner Jakub Wieczorek Frédéric Crozat Francois Cartegnie Laurent Aimar Florian G. Pflug Felix Paul Kühne Frank Enderle Rafaël Carré Simon Latapie Gildas Bazin Geoffroy Couprie Julien / Gellule Gildas Bazin Arnaud Schauly Toralf Niebuhr Vicente Jimenez Aguilar Derk-Jan Hartman Henri Fallon Ilkka Ollakka Olivier Teulière Rémi Duraffort Jakob Leben Jean-Baptiste Kempf Jean-Paul Saman Jean-Philippe Grimaldi Jean-François Massol Gaël Hendryckx Jakob Leben Jean-Marc Dressler Jai Menon Johan Bilien Johann Ransay Joris van Rooij JP Dinger Jean-Philippe André Adrien Grand Juha Jeronen Juho Vähä-Herttua Kaarlo Raiha Kaarlo Raiha Kamil Baldyga Keary Griffin Ken Self KO Myung-Hun Pierre Ynard Filippo Carone Loïc Minier Luca Barbato Lucas C. Villa Real Lukas Durfina Adrien Maglo Marc Ariberti Mark Lee Mark Moriarty Martin Storsjö Christophe Massiot Michel Kaempf Marian Ďurkovič Mirsal Ennaime Carlo Calabrò Damien Lucas Naohiro Koriyama Basos G Pierre Baillet Vincent Penquerc'h Olivier Aubert Pankaj Yadav Paul Corke Pierre d'Herbemont Philippe Morin Antoine Lejeune Michael Ploujnikov Jean-Marc Dressler Michael Hanselmann Rafaël Carré Ramiro Polla Rémi Denis-Courmont Renaud Dartus Richard Shepherd Faustino Osuna Arnaud Vallat Rob Jonson Robert Jedrzejczyk Steve Lhomme Rocky Bernstein Romain Goyet Rov Juvano Sam Hocevar Martin T. H. Sandsmark Sebastian Birk Sébastien Escudier Vincent Seguin Fabio Ritrovato Sigmund Augdal Helberg Casian Andrei Srikanth Raju Hannes Domani Stéphane Borel Stephan Krempel Stephan Assmus Tony Castley Pavlov Konstantin Eric Petit Tanguy Krotoff Dennis van Amerongen Michel Lespinasse Can Wu Xavier Marchesini Sébastien Toque Christophe Mutricy Yoann Peronneau Yohann Martineau Yuval Tze Scott Caudle Clément Stenac It is possible, that some minor piece of code was badly tracked, for some reasons (SVN, mainly) or that some small developers did not answer. However, as an "œuvre collective", defined as in "CPI 113-2 alinéa 3", and seeing "Cour. Cass. 17 Mai 1978", and seeing that the editor and the very vast majority of developers have agreed (> 99.99% of the code, > 99% of developers), we are fine here.
2011-11-27 21:44:15 +01:00
* 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., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
2005-12-05 10:36:39 +01:00
*****************************************************************************/
/*****************************************************************************
* Preamble
*****************************************************************************/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include <vlc_common.h>
2005-12-05 10:36:39 +01:00
#include <unistd.h>
2005-12-05 10:36:39 +01:00
#include <vlc_network.h>
#include <vlc_interrupt.h>
2005-12-05 10:36:39 +01:00
/*****************************************************************************
2008-06-08 16:52:43 +02:00
* SocksNegotiate:
2005-12-05 10:36:39 +01:00
*****************************************************************************
2008-06-08 16:52:43 +02:00
* Negotiate authentication with a SOCKS server.
2005-12-05 10:36:39 +01:00
*****************************************************************************/
2008-06-08 16:52:43 +02:00
static int SocksNegotiate( vlc_object_t *p_obj,
2005-12-05 10:36:39 +01:00
int fd, int i_socks_version,
2007-09-16 11:32:30 +02:00
const char *psz_socks_user,
const char *psz_socks_passwd )
2005-12-05 10:36:39 +01:00
{
uint8_t buffer[128+2*256];
int i_len;
bool b_auth = false;
2005-12-05 10:36:39 +01:00
if( i_socks_version != 5 )
return VLC_SUCCESS;
2008-06-08 16:52:43 +02:00
/* We negotiate authentication */
2005-12-05 10:36:39 +01:00
buffer[0] = i_socks_version; /* SOCKS version */
if( psz_socks_user != NULL && psz_socks_passwd != NULL )
2005-12-05 10:36:39 +01:00
{
buffer[1] = 2; /* Number of methods */
buffer[2] = 0x00; /* - No auth required */
buffer[3] = 0x02; /* - USer/Password */
i_len = 4;
b_auth = true;
2005-12-05 10:36:39 +01:00
}
else
{
buffer[1] = 1; /* Number of methods */
buffer[2] = 0x00; /* - No auth required */
i_len = 3;
}
if( net_Write( p_obj, fd, buffer, i_len ) != i_len )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
if( net_Read( p_obj, fd, buffer, 2) != 2 )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d method=%x", buffer[0], buffer[1] );
if( buffer[1] == 0x00 )
{
msg_Dbg( p_obj, "socks: no authentication required" );
}
else if( buffer[1] == 0x02 )
{
if( psz_socks_user == NULL || psz_socks_passwd == NULL )
{
msg_Err( p_obj, "socks: server mandates authentication but "
"a username and/or password was not supplied" );
return VLC_EGENERIC;
}
int const i_user = strlen( psz_socks_user );
int const i_pasw = strlen( psz_socks_passwd );
if( i_user > 255 || i_pasw > 255 )
{
msg_Err( p_obj, "socks: rejecting username and/or password due to "
"violation of RFC1929 (longer than 255 bytes)" );
return VLC_EGENERIC;
}
2005-12-05 10:36:39 +01:00
msg_Dbg( p_obj, "socks: username/password authentication" );
buffer[0] = i_socks_version; /* Version */
buffer[1] = i_user; /* User length */
memcpy( &buffer[2], psz_socks_user, i_user );
buffer[2+i_user] = i_pasw; /* Password length */
memcpy( &buffer[2+i_user+1], psz_socks_passwd, i_pasw );
2005-12-05 10:36:39 +01:00
i_len = 3 + i_user + i_pasw;
2005-12-05 10:36:39 +01:00
if( net_Write( p_obj, fd, buffer, i_len ) != i_len )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
if( net_Read( p_obj, fd, buffer, 2 ) != 2 )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d status=%x", buffer[0], buffer[1] );
if( buffer[1] != 0x00 )
{
msg_Err( p_obj, "socks: authentication rejected" );
return VLC_EGENERIC;
}
}
else
{
if( b_auth )
msg_Err( p_obj, "socks: unsupported authentication method %x",
buffer[0] );
else
2009-07-11 21:21:52 +02:00
msg_Err( p_obj, "socks: authentication needed" );
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
/*****************************************************************************
* SocksHandshakeTCP:
*****************************************************************************
* Open a TCP connection using a SOCKS server and return a handle (RFC 1928)
*****************************************************************************/
static int SocksHandshakeTCP( vlc_object_t *p_obj,
int fd,
int i_socks_version,
2007-09-16 11:32:30 +02:00
const char *psz_user, const char *psz_passwd,
2005-12-05 10:36:39 +01:00
const char *psz_host, int i_port )
{
uint8_t buffer[128+2*256];
if( i_socks_version != 4 && i_socks_version != 5 )
{
msg_Warn( p_obj, "invalid socks protocol version %d", i_socks_version );
i_socks_version = 5;
}
2007-09-10 20:56:52 +02:00
if( i_socks_version == 5 &&
2008-06-08 16:52:43 +02:00
SocksNegotiate( p_obj, fd, i_socks_version,
2007-09-16 11:32:30 +02:00
psz_user, psz_passwd ) )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
if( i_socks_version == 4 )
{
/* v4 only support ipv4 */
static const struct addrinfo hints = {
.ai_family = AF_INET,
.ai_socktype = SOCK_STREAM,
.ai_protocol = IPPROTO_TCP,
.ai_flags = AI_IDN,
};
struct addrinfo *res;
if (vlc_getaddrinfo_i11e(psz_host, 0, &hints, &res))
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
buffer[0] = i_socks_version;
buffer[1] = 0x01; /* CONNECT */
SetWBE( &buffer[2], i_port ); /* Port */
memcpy (&buffer[4], /* Address */
&((struct sockaddr_in *)(res->ai_addr))->sin_addr, 4);
freeaddrinfo (res);
2005-12-05 10:36:39 +01:00
buffer[8] = 0; /* Empty user id */
if( net_Write( p_obj, fd, buffer, 9 ) != 9 )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
if( net_Read( p_obj, fd, buffer, 8 ) != 8 )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d cd=%d",
buffer[0], buffer[1] );
if( buffer[1] != 90 )
return VLC_EGENERIC;
}
else if( i_socks_version == 5 )
{
int i_hlen = __MIN(strlen( psz_host ), 255);
int i_len;
buffer[0] = i_socks_version; /* Version */
buffer[1] = 0x01; /* Cmd: connect */
buffer[2] = 0x00; /* Reserved */
buffer[3] = 3; /* ATYP: for now domainname */
buffer[4] = i_hlen;
memcpy( &buffer[5], psz_host, i_hlen );
SetWBE( &buffer[5+i_hlen], i_port );
i_len = 5 + i_hlen + 2;
if( net_Write( p_obj, fd, buffer, i_len ) != i_len )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
/* Read the header */
if( net_Read( p_obj, fd, buffer, 5 ) != 5 )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
msg_Dbg( p_obj, "socks: v=%d rep=%d atyp=%d",
buffer[0], buffer[1], buffer[3] );
if( buffer[1] != 0x00 )
{
msg_Err( p_obj, "socks: CONNECT request failed" );
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
}
/* Read the remaining bytes */
if( buffer[3] == 0x01 )
i_len = 4-1 + 2;
else if( buffer[3] == 0x03 )
i_len = buffer[4] + 2;
else if( buffer[3] == 0x04 )
i_len = 16-1+2;
2007-09-10 20:56:52 +02:00
else
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
if( net_Read( p_obj, fd, buffer, i_len ) != i_len )
2005-12-05 10:36:39 +01:00
return VLC_EGENERIC;
}
return VLC_SUCCESS;
}
2018-11-09 21:58:36 +01:00
int (net_ConnectTCP)(vlc_object_t *obj, const char *host, int serv)
{
const char *realhost;
int realserv;
char *socks = var_InheritString(obj, "socks");
if (socks != NULL)
{
realhost = socks;
char *p = strchr(socks, ':');
if (p != NULL)
{
*(p++) = '\0';
realserv = atoi(p);
}
else
realserv = 1080;
msg_Dbg(obj, "net: connecting to %s port %d (SOCKS) "
"for %s port %d", realhost, realserv, host, serv);
}
else
{
msg_Dbg(obj, "net: connecting to %s port %d", host, serv);
realhost = host;
realserv = serv;
}
int fd = net_Connect(obj, realhost, realserv, SOCK_STREAM, IPPROTO_TCP);
if (socks != NULL && fd != -1)
{
/* NOTE: psz_socks already free'd! */
char *user = var_InheritString(obj, "socks-user");
char *pwd = var_InheritString(obj, "socks-pwd");
if (SocksHandshakeTCP(obj, fd, 5, user, pwd, host, serv))
{
msg_Err(obj, "SOCKS handshake failed");
net_Close(fd);
fd = -1;
}
free(pwd);
free(user);
}
return fd;
2018-11-09 21:58:36 +01:00
}