void transmission_tower(ZNotice_t *notice, char *packet, int pak_len) { ZNotice_t gack; Code_t ret; struct sockaddr_in gsin; nclt++; if (notice->z_kind == HMCTL) { if (!strcmp(notice->z_opcode, CLIENT_FLUSH)) { if (noflushflag) syslog(LOG_INFO, "Client requested hm flush (disabled)."); else { send_flush_notice(HM_FLUSH); deactivated = 1; } } else if (!strcmp(notice->z_opcode, CLIENT_NEW_SERVER)) { new_server((char *)NULL); } else { syslog (LOG_INFO, "Bad control notice from client."); } return; } else { if (notice->z_kind != UNSAFE) { gack = *notice; gack.z_kind = HMACK; gack.z_message_len = 0; gack.z_multinotice = ""; gsin = cli_sin; gsin.sin_port = from.sin_port; if (gack.z_port == 0) gack.z_port = from.sin_port; DPR2 ("Client Port = %u\n", ntohs(gack.z_port)); notice->z_port = gack.z_port; if ((ret = ZSetDestAddr(&gsin)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "setting destination"); } /* Bounce ACK to library */ if ((ret = send_outgoing(&gack)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "sending raw notice"); } } } if (!no_server) { DPR2 ("Server Port = %u\n", ntohs(serv_sin.sin_port)); if ((ret = ZSetDestAddr(&serv_sin)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "setting destination"); } if ((ret = ZSendPacket(packet, pak_len, 0)) != ZERR_NONE) { Zperr(ret); com_err("hm", ret, "while sending raw notice"); } } if (add_notice_to_queue(notice, packet, &gsin, pak_len) != ZERR_NONE) syslog(LOG_INFO, "Hey! Insufficient memory to add notice to queue!"); }
void owl_zephyr_initialize() { int ret; struct servent *sp; struct sockaddr_in sin; ZNotice_t req; Code_t code; owl_dispatch *dispatch; /* * Code modified from libzephyr's ZhmStat.c * * Modified to add the fd to our select loop, rather than hanging * until we get an ack. */ if ((ret = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Error opening Zephyr port: %s", error_message(ret)); return; } (void) memset((char *)&sin, 0, sizeof(struct sockaddr_in)); sp = getservbyname(HM_SVCNAME, "udp"); sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); (void) memset((char *)&req, 0, sizeof(req)); req.z_kind = STAT; req.z_port = 0; req.z_class = HM_STAT_CLASS; req.z_class_inst = HM_STAT_CLIENT; req.z_opcode = HM_GIMMESTATS; req.z_sender = ""; req.z_recipient = ""; req.z_default_format = ""; req.z_message_len = 0; if ((code = ZSetDestAddr(&sin)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } if ((code = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(code)); return; } dispatch = owl_malloc(sizeof(*dispatch)); dispatch->fd = ZGetFD(); dispatch->cfunc = owl_zephyr_finish_initialization; dispatch->destroy = (void(*)(owl_dispatch*))owl_free; owl_select_add_dispatch(dispatch); }
void owl_zephyr_initialize(void) { Code_t ret; struct servent *sp; struct sockaddr_in sin; ZNotice_t req; GIOChannel *channel; /* * Code modified from libzephyr's ZhmStat.c * * Modified to add the fd to our select loop, rather than hanging * until we get an ack. */ if ((ret = ZOpenPort(NULL)) != ZERR_NONE) { owl_function_error("Error opening Zephyr port: %s", error_message(ret)); return; } (void) memset(&sin, 0, sizeof(struct sockaddr_in)); sp = getservbyname(HM_SVCNAME, "udp"); sin.sin_port = (sp) ? sp->s_port : HM_SVC_FALLBACK; sin.sin_family = AF_INET; sin.sin_addr.s_addr = htonl(INADDR_LOOPBACK); (void) memset(&req, 0, sizeof(req)); req.z_kind = STAT; req.z_port = 0; req.z_class = zstr(HM_STAT_CLASS); req.z_class_inst = zstr(HM_STAT_CLIENT); req.z_opcode = zstr(HM_GIMMESTATS); req.z_sender = zstr(""); req.z_recipient = zstr(""); req.z_default_format = zstr(""); req.z_message_len = 0; if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(ret)); return; } if ((ret = ZSendNotice(&req, ZNOAUTH)) != ZERR_NONE) { owl_function_error("Initializing Zephyr: %s", error_message(ret)); return; } channel = g_io_channel_unix_new(ZGetFD()); g_io_add_watch(channel, G_IO_IN | G_IO_ERR | G_IO_HUP, &owl_zephyr_finish_initialization, NULL); g_io_channel_unref(channel); }
int srv_stat(char *host) { char *line[20],*mp; int sock,i,nf,ret; struct hostent *hp; struct sockaddr_in sin; ZNotice_t notice; time_t runtime; struct tm *tim; #ifdef _POSIX_VERSION struct sigaction sa; #endif (void) memset((char *) &sin, 0, sizeof(struct sockaddr_in)); sin.sin_port = srv_port; if ((sock = socket(PF_INET, SOCK_DGRAM, 0)) < 0) { perror("socket:"); exit(-1); } sin.sin_family = AF_INET; if ((sin.sin_addr.s_addr = inet_addr(host)) == (unsigned)(-1)) { if ((hp = gethostbyname(host)) == NULL) { fprintf(stderr,"Unknown host: %s\n",host); exit(-1); } (void) memcpy((char *) &sin.sin_addr, hp->h_addr, hp->h_length); printf("Server stats: %s\n", hp->h_name); } else { printf("Server stats: %s\n", host); } (void) memset((char *)¬ice, 0, sizeof(notice)); notice.z_kind = UNSAFE; notice.z_port = 0; notice.z_charset = ZCHARSET_UNKNOWN; notice.z_class = ZEPHYR_ADMIN_CLASS; notice.z_class_inst = ""; notice.z_opcode = ADMIN_STATUS; notice.z_sender = ""; notice.z_recipient = ""; notice.z_default_format = ""; notice.z_message_len = 0; if ((ret = ZSetDestAddr(&sin)) != ZERR_NONE) { com_err("zstat", ret, "setting destination"); exit(-1); } if ((ret = ZSendNotice(¬ice, ZNOAUTH)) != ZERR_NONE) { com_err("zstat", ret, "sending notice"); exit(-1); } #ifdef _POSIX_VERSION sigemptyset(&sa.sa_mask); sa.sa_flags = 0; sa.sa_handler = timeout; (void) sigaction(SIGALRM, &sa, (struct sigaction *)0); #else (void) signal(SIGALRM,timeout); #endif outoftime = 0; (void) alarm(10); if (((ret = ZReceiveNotice(¬ice, (struct sockaddr_in *) 0)) != ZERR_NONE) && ret != EINTR) { com_err("zstat", ret, "receiving notice"); return (1); } (void) alarm(0); if (outoftime) { fprintf(stderr,"No response after 10 seconds.\n"); return (1); } mp = notice.z_message; for (nf=0;mp<notice.z_message+notice.z_message_len;nf++) { line[nf] = mp; mp += strlen(mp)+1; } printf("Server protocol version = %s\n",notice.z_version); for (i=0; i < nf; i++) { if (i < 2) printf("%s %s\n",srv_head[i],line[i]); else if (i == 2) { /* uptime field */ runtime = atol(line[i]); tim = gmtime(&runtime); printf("%s %d days, %02d:%02d:%02d\n", srv_head[i], tim->tm_yday, tim->tm_hour, tim->tm_min, tim->tm_sec); } else if (i == 3) { printf("%s\n",srv_head[i]); printf("%s\n",line[i]); } else printf("%s\n",line[i]); } printf("\n"); (void) close(sock); ZFreeNotice(¬ice); return(0); }