/* $Id$
* $URL$
*
* plugin hddtemp
*
* Copyright (C) 2007 Scott Bronson <brons_lcd4linux@rinspin.com>
* Copyright (C) 2004, 2005, 2006, 2007, 2008 The LCD4Linux Team <lcd4linux-devel@users.sourceforge.net>
*
* This file is part of LCD4Linux.
*
* LCD4Linux is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* LCD4Linux 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 General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*
*/
/* Example:
* (I tried to put this info on the wiki but Akismet claimed it was spam)
Widget SmallHDDTemp {
class 'Text'
expression hddtemp('/dev/hda')
width 4
precision 1
align 'R'
update tick
}
hddtemp home page: http://www.guzu.net/linux/hddtemp.php
Quick Examples:
* hddtemp() -- return temperature of first drive (order is defined by the hddtemp daemon).
* hddtemp('/dev/hda') -- return temperature of /dev/hda on localhost.
* hddtemp('ST3400832A') -- return temperature of the drive with the given ID.
* hddtemp('burly', '') -- return temperature of the first drive on host burly.
* hddtemp('burly', 17634, '/dev/hda') -- return temperature of /dev/hda on burly connecting to the hddtemp daemon listening on port 17634.
You can find out what drives are being monitored by running
telnet HOST PORT
i.e.
$ telnet localhost 7634
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
|/dev/hda|ST3400832A|53|C|Connection closed by foreign host.
This tells me that /dev/hda is a Seagate ST3400832A running at an awfully
toasty 53 degC.
*/
/*
* exported functions:
*
* int plugin_init_hddtemp (void)
* adds various functions
* void plugin_exit_hddtemp (void)
*
*/
#include "config.h"
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <errno.h>
/* network specific includes */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <arpa/inet.h>
/* these should always be included */
#include "debug.h"
#include "plugin.h"
static int socket_open(const char *name, int port)
{
struct sockaddr_in server;
struct hostent *host_info;
unsigned long addr;
int sock;
sock = socket(PF_INET, SOCK_STREAM, 0);
if (sock < 0) {
error("[hddtemp] failed to create socket: %s", strerror(errno));
return -1;
}
memset(&server, 0, sizeof(server));
if ((addr = inet_addr(name)) != INADDR_NONE) {
memcpy((char *) &server.sin_addr, &addr, sizeof(addr));
} else {
host_info = gethostbyname(name);
if (NULL == host_info) {
error("[hddtemp] Unknown server: %s", name);
return -1;
}
memcpy((char *) &server.sin_addr, host_info->h_addr, host_info->h_length);
}
server.sin_family = AF_INET;
server.sin_port = htons(port);
if (connect(sock, (struct sockaddr *) &server,