Add FTP protocol debugging facilities.
[dftpd.git] / SymbianNetwork.cpp
blob1d15b3c5c0d8a3b84950e7b2f424b65d35eb1c21
1 #include <unistd.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <sys/socket.h>
5 #include <sys/sockio.h>
6 #include <netinet/in.h>
7 #include <net/if.h>
8 #include <arpa/inet.h>
9 #include "SymbianNetwork.hpp"
11 std::string EstablishConnection()
13 // Open connection connection, otherwise we'll have no network access
14 int sock = socket( PF_INET, SOCK_STREAM, 0 );
16 ifreq ifr;
17 sockaddr_in *sa = (sockaddr_in*)&ifr.ifr_addr;
19 sa->sin_family = AF_INET;
20 sa->sin_port = htons( 80 );
21 sa->sin_addr.s_addr = inet_addr( "147.243.3.83" ); // www.nokia.com
22 memset( sa->sin_zero, 0, sizeof( sa->sin_zero ) );
24 connect( sock, (sockaddr*)sa, sizeof( sockaddr ) );
26 ioctl( sock, SIOCGIFADDR, &ifr );
28 // Bug? Address is in host byte order.
29 in_addr addr;
30 addr.s_addr = htonl( ((sockaddr_in*)&ifr.ifr_addr)->sin_addr.s_addr );
32 close( sock );
34 return inet_ntoa( addr );