2 * Conky, a system monitor, based on torsmo
4 * Any original torsmo code is licensed under the BSD license
6 * All code written since the fork of torsmo is licensed under the GPL
8 * Please see COPYING for details
10 * Copyright (c) 2004, Hannu Saransaari and Lauri Hakkarainen
11 * Copyright (c) 2005-2007 Brenden Matthews, Philip Kovacs, et. al. (see AUTHORS)
12 * All rights reserved.
14 * This program is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU General Public License as published by
16 * the Free Software Foundation, either version 3 of the License, or
17 * (at your option) any later version.
19 * This program is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU General Public License for more details.
23 * You should have received a copy of the GNU General Public License
24 * along with this program. If not, see <http://www.gnu.org/licenses/>.
37 #include <sys/select.h>
38 #include <sys/socket.h>
39 #include <netinet/in.h>
46 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port)
48 char buf1[32], buf2[64];
51 ret = sscanf(arg, "%31s %63s %d", buf1, buf2, &n);
60 *addr = strdup("127.0.0.1");
70 char *get_hddtemp_info(char *dev, char *hostaddr, int port, char *unit)
74 struct sockaddr_in addr;
77 int len, i, devlen = strlen(dev);
79 char *p, *out, *r = NULL;
81 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
86 he = gethostbyname(hostaddr);
88 perror("gethostbyname");
92 addr.sin_family = AF_INET;
93 addr.sin_port = htons(port);
94 addr.sin_addr = *((struct in_addr *)he->h_addr);
95 memset(&(addr.sin_zero), 0, 8);
97 if (connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) {
103 FD_SET(sockfd, &rfds);
105 /* We're going to wait up to a quarter a second to see whether
106 * there's any data available. Polling with timeout set to 0
107 * doesn't seem to work with hddtemp. */
111 i = select(sockfd+1, &rfds, NULL, NULL, &tv);
114 if (errno == EINTR) /* silently ignore interrupted system call */
120 /* No data available */
127 i = recv(sockfd, p, BUFLEN - (p-buf), 0);
134 } while (i > 0 && p < buf + BUFLEN - 1);
142 /* The first character read is the separator. */
147 if (!strncmp(p, dev, devlen)) {
160 if (!strncmp(out, "NA", 2)) {
168 for (i = 0; i < 5; i++) {