Sun, 20 May 2007 06:19:49 +0000
merge of 'b98e72d4089afb8a1879e5fe9627cfb132ee88de'
and 'b2836a24d81e7a1bd1d21b3aea8794b094391344'
| 2419 | 1 | /* This file is part of the Project Athena Zephyr Notification System. |
| 2 | * It contains the ZhmStat() function. | |
| 3 | * | |
| 4 | * Created by: Marc Horowitz | |
| 5 | * | |
| 6 | * Copyright (c) 1996 by the Massachusetts Institute of Technology. | |
| 7 | * For copying and distribution information, see the file | |
| 8 | * "mit-copyright.h". | |
| 9 | */ | |
| 10 | ||
|
8792
b0645c9dc276
[gaim-migrate @ 9554]
Christian Hammond <chipx86@chipx86.com>
parents:
2419
diff
changeset
|
11 | #include "internal.h" |
| 10867 | 12 | |
| 13 | #ifdef WIN32 | |
| 14 | #include <winsock2.h> | |
| 15 | #else | |
| 2419 | 16 | #include <sys/socket.h> |
| 10867 | 17 | #endif |
| 2419 | 18 | |
| 19 | #ifndef INADDR_LOOPBACK | |
| 20 | #define INADDR_LOOPBACK 0x7f000001 | |
| 21 | #endif | |
| 22 | ||
| 23 | Code_t ZhmStat(hostaddr, notice) | |
| 24 | struct in_addr *hostaddr; | |
| 25 | ZNotice_t *notice; | |
| 26 | { | |
| 27 | struct servent *sp; | |
| 28 | struct sockaddr_in sin; | |
| 29 | ZNotice_t req; | |
| 30 | Code_t code; | |
| 31 | struct timeval tv; | |
| 32 | fd_set readers; | |
| 33 | ||
| 34 | (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in)); | |
| 35 | ||
| 36 | sp = getservbyname(HM_SVCNAME, "udp"); | |
| 37 | ||
| 38 | sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; | |
| 39 | sin.sin_family = AF_INET; | |
| 40 | ||
| 41 | if (hostaddr) | |
| 42 | sin.sin_addr = *hostaddr; | |
| 43 | else | |
| 44 | sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); | |
| 45 | ||
| 46 | (void) memset((char *)&req, 0, sizeof(req)); | |
| 47 | req.z_kind = STAT; | |
| 48 | req.z_port = 0; | |
| 49 | req.z_class = HM_STAT_CLASS; | |
| 50 | req.z_class_inst = HM_STAT_CLIENT; | |
| 51 | req.z_opcode = HM_GIMMESTATS; | |
| 52 | req.z_sender = ""; | |
| 53 | req.z_recipient = ""; | |
| 54 | req.z_default_format = ""; | |
| 55 | req.z_message_len = 0; | |
| 56 | ||
| 57 | if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) | |
| 58 | return(code); | |
| 59 | ||
| 60 | if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) | |
| 61 | return(code); | |
| 62 | ||
| 63 | /* Wait up to ten seconds for a response. */ | |
| 64 | FD_ZERO(&readers); | |
| 65 | FD_SET(ZGetFD(), &readers); | |
| 66 | tv.tv_sec = 10; | |
| 67 | tv.tv_usec = 0; | |
| 68 | code = select(ZGetFD() + 1, &readers, NULL, NULL, &tv); | |
| 69 | if (code < 0 && errno != EINTR) | |
| 70 | return(errno); | |
| 71 | if (code == 0 || (code < 0 && errno == EINTR) || ZPending() == 0) | |
| 72 | return(ZERR_HMDEAD); | |
| 73 | ||
| 74 | return(ZReceiveNotice(notice, (struct sockaddr_in *) 0)); | |
| 75 | } |