8 #include <sys/select.h>
9 #include <sys/socket.h>
10 #include <netinet/in.h>
17 int scan_hddtemp(const char *arg, char **dev, char **addr, int *port)
19 char buf1[32], buf2[64];
22 ret = sscanf(arg, "%31s %63s %d", buf1, buf2, &n);
31 *addr = strdup("127.0.0.1");
41 char *get_hddtemp_info(char *dev, char *hostaddr, int port, char *unit)
45 struct sockaddr_in addr;
48 int len, i, devlen = strlen(dev);
50 char *p, *out, *r = NULL;
52 if ((sockfd = socket(AF_INET, SOCK_STREAM, 0)) == -1) {
57 he = gethostbyname(hostaddr);
59 perror("gethostbyname");
63 addr.sin_family = AF_INET;
64 addr.sin_port = htons(port);
65 addr.sin_addr = *((struct in_addr *)he->h_addr);
66 memset(&(addr.sin_zero), 0, 8);
68 if (connect(sockfd, (struct sockaddr *)&addr, sizeof(struct sockaddr)) == -1) {
74 FD_SET(sockfd, &rfds);
76 /* We're going to wait up to a quarter a second to see whether
77 * there's any data available. Polling with timeout set to 0
78 * doesn't seem to work with hddtemp. */
82 i = select(sockfd+1, &rfds, NULL, NULL, &tv);
86 /* No data available */
93 i = recv(sockfd, p, BUFLEN - (p-buf), 0);
100 } while (i > 0 && p < buf + BUFLEN - 1);
108 /* The first character read is the separator. */
113 if (!strncmp(p, dev, devlen)) {
126 if (!strncmp(out, "NA", 2)) {
134 for (i = 0; i < 5; i++) {