gui/nfs: implement mac address lookup

Conflicts:
	src/gui/moviebrowser.cpp
	src/gui/nfs.cpp


Origin commit data
------------------
Branch: ni/coolstream
Commit: 706ea95092
Author: martii <m4rtii@gmx.de>
Date: 2013-06-29 (Sat, 29 Jun 2013)



------------------
This commit was generated by Migit
This commit is contained in:
martii
2013-06-29 15:22:39 +02:00
committed by [CST] Focus
parent d6e0068d0b
commit 1aa1acce45
10 changed files with 77 additions and 32 deletions

View File

@@ -1698,6 +1698,7 @@ nfs.mountnow Jetzt mounten
nfs.mountok Mount erfolgreich nfs.mountok Mount erfolgreich
nfs.mounttimeout Mount-Fehler: Timeout nfs.mounttimeout Mount-Fehler: Timeout
nfs.password Passwort nfs.password Passwort
nfs.refresh_mac MAC-Adresse feststellen
nfs.remount Verzeichnisse erneut mounten nfs.remount Verzeichnisse erneut mounten
nfs.type Typ nfs.type Typ
nfs.type_cifs CIFS nfs.type_cifs CIFS

View File

@@ -1698,6 +1698,7 @@ nfs.mountnow mount now
nfs.mountok mount successful nfs.mountok mount successful
nfs.mounttimeout mount error: timeout nfs.mounttimeout mount error: timeout
nfs.password password nfs.password password
nfs.refresh_mac look up MAC address
nfs.remount remount directories nfs.remount remount directories
nfs.type type nfs.type type
nfs.type_cifs CIFS nfs.type_cifs CIFS

View File

@@ -121,7 +121,6 @@ void netGetIP(std::string &dev, std::string &ip, std::string &mask, std::string
brdcast = std::string(tmp); brdcast = std::string(tmp);
close(fd); close(fd);
return;
} }
#if 0 #if 0
//never used //never used

View File

@@ -3089,7 +3089,7 @@ int CMovieBrowser::showMovieInfoMenu(MI_MOVIE_INFO* movie_info)
return res; return res;
} }
extern "C" int pinghost( const char *hostname ); extern int pinghost (const std::string &hostname, std::string *ip = NULL);
bool CMovieBrowser::showMenu(MI_MOVIE_INFO* /*movie_info*/) bool CMovieBrowser::showMenu(MI_MOVIE_INFO* /*movie_info*/)
{ {
/* first clear screen */ /* first clear screen */
@@ -4085,7 +4085,7 @@ void CDirMenu::updateDirState(void)
printf("updateDirState: %d: state %d nfs %d\n", i, dirState[i], dirNfsMountNr[i]); printf("updateDirState: %d: state %d nfs %d\n", i, dirState[i], dirNfsMountNr[i]);
if(dirNfsMountNr[i] != -1) if(dirNfsMountNr[i] != -1)
{ {
int retvalue = pinghost(g_settings.network_nfs[dirNfsMountNr[i]].ip.c_str()); int retvalue = pinghost(g_settings.network_nfs[dirNfsMountNr[i]].ip);
if (retvalue == 0)//LOCALE_PING_UNREACHABLE if (retvalue == 0)//LOCALE_PING_UNREACHABLE
{ {
dirOptionText[i]="Server, offline"; dirOptionText[i]="Server, offline";

View File

@@ -58,7 +58,7 @@
#include <libnet.h> #include <libnet.h>
#include <libiw/iwscan.h> #include <libiw/iwscan.h>
extern "C" int pinghost( const char *hostname ); extern int pinghost (const std::string &hostname, std::string *ip = NULL);
CNetworkSetup::CNetworkSetup(bool wizard_mode) CNetworkSetup::CNetworkSetup(bool wizard_mode)
{ {
@@ -702,7 +702,7 @@ void CNetworkSetup::showCurrentNetworkSettings()
const char * CNetworkSetup::mypinghost(std::string &host) const char * CNetworkSetup::mypinghost(std::string &host)
{ {
int retvalue = pinghost(host.c_str()); int retvalue = pinghost(host);
switch (retvalue) switch (retvalue)
{ {
case 1: return (g_Locale->getText(LOCALE_PING_OK)); case 1: return (g_Locale->getText(LOCALE_PING_OK));
@@ -776,7 +776,7 @@ void CNetworkSetup::testNetworkSettings()
text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n"; text += (std::string)g_Locale->getText(LOCALE_NETWORKMENU_NAMESERVER) + ":\n";
text += offset + our_nameserver + " " + mypinghost(our_nameserver) + "\n"; text += offset + our_nameserver + " " + mypinghost(our_nameserver) + "\n";
//NTPserver //NTPserver
if ( (pinghost(our_nameserver.c_str()) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") ) if ( (pinghost(our_nameserver) == 1) && g_settings.network_ntpenable && (g_settings.network_ntpserver != "") )
{ {
text += std::string(g_Locale->getText(LOCALE_NETWORKMENU_NTPSERVER)) + ":\n"; text += std::string(g_Locale->getText(LOCALE_NETWORKMENU_NTPSERVER)) + ":\n";
text += offset + g_settings.network_ntpserver + " " + mypinghost(g_settings.network_ntpserver) + "\n"; text += offset + g_settings.network_ntpserver + " " + mypinghost(g_settings.network_ntpserver) + "\n";
@@ -784,7 +784,7 @@ void CNetworkSetup::testNetworkSettings()
//Wiki //Wiki
text += wiki_URL + ":\n"; text += wiki_URL + ":\n";
text += offset + "via IP (" + wiki_IP + "): " + mypinghost(wiki_IP) + "\n"; text += offset + "via IP (" + wiki_IP + "): " + mypinghost(wiki_IP) + "\n";
if (pinghost(our_nameserver.c_str()) == 1) if (pinghost(our_nameserver) == 1)
{ {
text += offset + "via DNS: " + mypinghost(wiki_URL) + "\n"; text += offset + "via DNS: " + mypinghost(wiki_URL) + "\n";
//testsite (or defaultsite) //testsite (or defaultsite)

View File

@@ -45,6 +45,7 @@
#include <fstream> #include <fstream>
#include <system/helpers.h>
#include <global.h> #include <global.h>
#include <errno.h> #include <errno.h>
@@ -54,6 +55,8 @@
#include <neutrino.h> #include <neutrino.h>
#include <zapit/client/zapittools.h> #include <zapit/client/zapittools.h>
extern int pinghost (const std::string &hostname, std::string *ip = NULL);
CNFSMountGui::CNFSMountGui() CNFSMountGui::CNFSMountGui()
{ {
// FIXME #warning move probing from exec() to fsmounter // FIXME #warning move probing from exec() to fsmounter
@@ -134,6 +137,27 @@ int CNFSMountGui::exec( CMenuTarget* parent, const std::string & actionKey )
ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str()); ISO_8859_1_entry[i] = ZapitTools::UTF8_to_Latin1(m_entry[i].c_str());
} }
} }
else if(actionKey.substr(0,10)=="refreshMAC")
{
int nr=atoi(actionKey.substr(10,1));
std::string h;
pinghost(g_settings.network_nfs[nr].ip, &h);
if (!h.empty()) {
FILE *arptable = fopen("/proc/net/arp", "r");
if (arptable) {
char line[120], ip[120], mac[120];
while (fgets(line, sizeof(line), arptable)) {
if (2 == sscanf(line, "%s %*s %*s %s %*[^\n]", ip, mac)) {
if (!strcmp(ip, h.c_str())) {
g_settings.network_nfs[nr].mac = std::string(mac);
break;
}
}
}
fclose(arptable);
}
}
}
else if(actionKey.substr(0,10)=="mountentry") else if(actionKey.substr(0,10)=="mountentry")
{ {
parent->hide(); parent->hide();
@@ -261,7 +285,9 @@ int CNFSMountGui::menuEntry(int nr)
CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (type != (int)CFSMounter::NFS), NULL, &passInput); CMenuForwarder *password_fwd = new CMenuForwarder(LOCALE_NFS_PASSWORD, (type != (int)CFSMounter::NFS), NULL, &passInput);
CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, &g_settings.network_nfs[nr].mac, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2); CMACInput macInput(LOCALE_RECORDINGMENU_SERVER_MAC, &g_settings.network_nfs[nr].mac, LOCALE_IPSETUP_HINT_1, LOCALE_IPSETUP_HINT_2);
CMenuForwarder * macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs[nr].mac, &macInput); CMenuForwarder *macInput_fwd = new CMenuForwarder(LOCALE_RECORDINGMENU_SERVER_MAC, true, g_settings.network_nfs[nr].mac, &macInput);
CMenuForwarder *refreshMAC_fwd = new CMenuForwarder(LOCALE_NFS_REFRESH_MAC, true, NULL, this, ("refreshMAC" + to_string(nr)).c_str(), CRCInput::RC_yellow, NEUTRINO_ICON_BUTTON_YELLOW);
CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs[nr].local_dir)), NULL, this, cmd); CMenuForwarder *mountnow_fwd = new CMenuForwarder(LOCALE_NFS_MOUNTNOW, !(CFSMounter::isMounted(g_settings.network_nfs[nr].local_dir)), NULL, this, cmd);
@@ -280,6 +306,8 @@ int CNFSMountGui::menuEntry(int nr)
mountMenuEntryW.addItem(username_fwd); mountMenuEntryW.addItem(username_fwd);
mountMenuEntryW.addItem(password_fwd); mountMenuEntryW.addItem(password_fwd);
mountMenuEntryW.addItem(macInput_fwd); mountMenuEntryW.addItem(macInput_fwd);
mountMenuEntryW.addItem(refreshMAC_fwd);
mountMenuEntryW.addItem(GenericMenuSeparatorLine);
mountMenuEntryW.addItem(mountnow_fwd); mountMenuEntryW.addItem(mountnow_fwd);
int ret = mountMenuEntryW.exec(this,""); int ret = mountMenuEntryW.exec(this,"");

View File

@@ -1725,6 +1725,7 @@ typedef enum
LOCALE_NFS_MOUNTOK, LOCALE_NFS_MOUNTOK,
LOCALE_NFS_MOUNTTIMEOUT, LOCALE_NFS_MOUNTTIMEOUT,
LOCALE_NFS_PASSWORD, LOCALE_NFS_PASSWORD,
LOCALE_NFS_REFRESH_MAC,
LOCALE_NFS_REMOUNT, LOCALE_NFS_REMOUNT,
LOCALE_NFS_TYPE, LOCALE_NFS_TYPE,
LOCALE_NFS_TYPE_CIFS, LOCALE_NFS_TYPE_CIFS,

View File

@@ -1725,6 +1725,7 @@ const char * locale_real_names[] =
"nfs.mountok", "nfs.mountok",
"nfs.mounttimeout", "nfs.mounttimeout",
"nfs.password", "nfs.password",
"nfs.refresh_mac",
"nfs.remount", "nfs.remount",
"nfs.type", "nfs.type",
"nfs.type_cifs", "nfs.type_cifs",

View File

@@ -38,12 +38,12 @@
#define MAXDATA (MAXPKT-HDRLEN-TIMLEN) #define MAXDATA (MAXPKT-HDRLEN-TIMLEN)
#define DEF_TIMEOUT 5 #define DEF_TIMEOUT 5
int ident = 0; static int ident = 0;
int timo = 2; static int timo = 2;
int rrt; static int rrt;
int sock; static int sock = -1;
int static int
in_checksum( u_short *buf, int len ) in_checksum( u_short *buf, int len )
{ {
register long sum = 0; register long sum = 0;
@@ -97,7 +97,7 @@ send_ping( const char *host, struct sockaddr_in *taddr )
return -1; return -1;
} }
if(( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){ if((sock < 0) && ( sock = socket( AF_INET, SOCK_RAW, proto->p_proto )) < 0 ){
#ifdef DEBUG #ifdef DEBUG
perror( "sock" ); perror( "sock" );
#endif/*DEBUG*/ #endif/*DEBUG*/
@@ -117,6 +117,7 @@ send_ping( const char *host, struct sockaddr_in *taddr )
perror( "sock" ); perror( "sock" );
#endif/*DEBUG*/ #endif/*DEBUG*/
close( sock ); close( sock );
sock = -1;
return -2; return -2;
} }
if( ss != len ){ if( ss != len ){
@@ -124,13 +125,14 @@ send_ping( const char *host, struct sockaddr_in *taddr )
perror( "malformed packet" ); perror( "malformed packet" );
#endif/*DEBUG*/ #endif/*DEBUG*/
close( sock ); close( sock );
sock = -1;
return -2; return -2;
} }
return 0; return 0;
} }
int static int
recv_ping( struct sockaddr_in *taddr ) recv_ping( struct sockaddr_in *taddr )
{ {
int len; int len;
@@ -188,7 +190,7 @@ recv_ping( struct sockaddr_in *taddr )
* returns an int value for the difference * returns an int value for the difference
* between now and starttime in milliseconds. * between now and starttime in milliseconds.
*/ */
int static int
elapsed_time( struct timeval *starttime ){ elapsed_time( struct timeval *starttime ){
struct timeval *newtime; struct timeval *newtime;
int elapsed; int elapsed;
@@ -209,47 +211,58 @@ elapsed_time( struct timeval *starttime ){
return( elapsed ); return( elapsed );
} }
int static int
myping( const char *hostname, int t ) myping(const std::string &hostname, int t, struct sockaddr_in *sa = NULL)
{ {
int err; int err;
struct sockaddr_in sa; struct sockaddr_in _sa;
struct timeval mytime; struct timeval mytime;
if (!sa)
sa = &_sa;
ident = getpid() & 0xFFFF; ident = getpid() & 0xFFFF;
if( t == 0 ) timo = 2; if( t == 0 ) timo = 2;
else timo = t; else timo = t;
(void) gettimeofday( &mytime, (struct timezone *)NULL); (void) gettimeofday( &mytime, (struct timezone *)NULL);
if(( err = send_ping( hostname, &sa )) < 0 ){ if(( err = send_ping( hostname.c_str(), sa )) < 0 ){
return err; return err;
} }
do{ do{
if(( rrt = elapsed_time( &mytime )) > timo * 1000 ){ if(( rrt = elapsed_time( &mytime )) > timo * 1000 ){
close( sock ); close( sock );
sock = -1;
return 0; return 0;
} }
} while( recv_ping( &sa )); } while( recv_ping(sa));
close( sock ); close( sock );
sock = -1;
return 1; return 1;
} }
int int
pinghost( const char *hostname ) pinghost(const std::string &hostname, std::string *ip)
{ {
return myping( hostname, 0 ); struct sockaddr_in sa;
int res = myping( hostname, 0, &sa);
if (ip) {
char *p = inet_ntoa(sa.sin_addr);
*ip = p ? std::string(p) : "";
}
return res;
} }
int int
pingthost( const char *hostname, int t ) pingthost(const std::string &hostname, int t)
{ {
return myping( hostname, t ); return myping( hostname, t );
} }
int int
tpinghost( const char *hostname ) tpinghost(const std::string &hostname)
{ {
int ret; int ret;
@@ -260,7 +273,7 @@ tpinghost( const char *hostname )
} }
int int
tpingthost( const char *hostname, int t ) tpingthost(const std::string &hostname, int t )
{ {
int ret; int ret;

View File

@@ -25,6 +25,7 @@
#define PING_H #define PING_H
#include <stdio.h> #include <stdio.h>
#include <string>
#include "ping-config.h" #include "ping-config.h"
@@ -74,13 +75,13 @@
# include <netinet/ip_icmp.h> # include <netinet/ip_icmp.h>
#endif /* defined(__linux__) */ #endif /* defined(__linux__) */
int send_ping( const char *host, struct sockaddr_in *taddr ); //int send_ping( const char *host, struct sockaddr_in *taddr );
int recv_ping( struct sockaddr_in *taddr ); //int recv_ping( struct sockaddr_in *taddr );
int pinghost ( const char *hostname ); int pinghost (const std::string &hostname, std::string *ip = NULL);
int pingthost ( const char *hostname, int t ); int pingthost (const std::string &hostname, int t );
int tpinghost ( const char *hostname ); int tpinghost (const std::string &hostname );
int tpingthost( const char *hostname, int t ); int tpingthost(const std::string &hostname, int t );
#endif/*PING_H*/ #endif/*PING_H*/