void epmd_call(EpmdVars *g,int what) { char buf[OUTBUF_SIZE]; int rval,fd,i,j; fd = conn_to_epmd(g); put_int16(1,buf); buf[2] = what; write(fd,buf,3); if (read(fd,(char *)&i,4) != 4) { if (!g->silent) printf("epmd: no response from local epmd\n"); epmd_cleanup_exit(g,1); } j = ntohl(i); if (!g->silent) printf("epmd: up and running on port %d with data:\n", j); while(1) { if ((rval = read(fd,buf,1)) <= 0) { close(fd); epmd_cleanup_exit(g,0); } buf[rval] = '\0'; if (!g->silent) printf("%s",buf); } }
void stop_cli(EpmdVars *g, char *name) { char buf[1024]; int fd, rval, bsize; bsize = strlen(name); if (bsize > 1000) { printf("epmd: Name too long!"); epmd_cleanup_exit(g, 1); } fd = conn_to_epmd(g); bsize++; put_int16(bsize, buf); buf[2] = EPMD_STOP_REQ; bsize += 2; strcpy(buf+3, name); if (write(fd, buf, bsize) != bsize) { printf("epmd: Can't write to epmd\n"); epmd_cleanup_exit(g,1); } if ((rval = read_fill(fd,buf,7)) == 7) { buf[7] = '\000'; printf("%s\n", buf); epmd_cleanup_exit(g,0); } else if (rval < 0) { printf("epmd: failed to read answer from local epmd\n"); epmd_cleanup_exit(g,1); } else { /* rval is now 0 or 1 */ buf[rval] = '\0'; printf("epmd: local epmd responded with <%s>\n", buf); epmd_cleanup_exit(g,1); } }
void kill_epmd(EpmdVars *g) { char buf[5]; int fd, rval; fd = conn_to_epmd(g); put_int16(1,buf); buf[2] = EPMD_KILL_REQ; if (write(fd, buf, 3) != 3) { printf("epmd: Can't write to epmd\n"); epmd_cleanup_exit(g,1); } if ((rval = read_fill(fd,buf,2)) == 2) { if (buf[0] == 'O' && buf[1] == 'K') { printf("Killed\n"); } else { printf("Killing not allowed - living nodes in database.\n"); } epmd_cleanup_exit(g,0); } else if (rval < 0) { printf("epmd: failed to read answer from local epmd\n"); epmd_cleanup_exit(g,1); } else { /* rval is now 0 or 1 */ buf[rval] = '\0'; printf("epmd: local epmd responded with <%s>\n", buf); epmd_cleanup_exit(g,1); } }
void epmd_call(EpmdVars *g,int what) { char buf[OUTBUF_SIZE]; int rval,fd,i,j; fd = conn_to_epmd(g); put_int16(1,buf); buf[2] = what; if (write(fd, buf, 3) != 3) { printf("epmd: Can't write to epmd\n"); epmd_cleanup_exit(g,1); } if (read(fd,(char *)&i,4) != 4) { if (!g->silent) printf("epmd: no response from local epmd\n"); epmd_cleanup_exit(g,1); } j = ntohl(i); if (!g->silent) { rval = erts_snprintf(buf, OUTBUF_SIZE, "epmd: up and running on port %d with data:\n", j); fwrite(buf, 1, rval, stdout); } while(1) { if ((rval = read(fd,buf,OUTBUF_SIZE)) <= 0) { close(fd); epmd_cleanup_exit(g,0); } if (!g->silent) fwrite(buf, 1, rval, stdout); /* Potentially UTF-8 encoded */ } }
static void wstart() { char buf[5]; sprintf(&buf[2], "ok"); put_int16(2, &buf[0]); if (write_fill(1, buf, 4) != 4) { exit(1); } }
static void wok(int sid) { char buf[BUFSIZ]; int len; sprintf(&buf[2], "pam %d yes", sid); len = strlen(&buf[2]); put_int16(len, &buf[0]); if (write_fill(1, buf, len+2) != len+2) exit(1); }
static void werr(pam_handle_t *pamh, int sid, int ecode, char *phase) { char buf[BUFSIZ]; int len; sprintf(&buf[2], "pam %d no %s %s", sid, phase, pam_strerror(pamh, ecode)); len = strlen(&buf[2]); put_int16(len, &buf[0]); if (write_fill(1, buf, len+2) != len+2) exit(1); }
/** * Add data and its length in the buffer. * @param data_bytes The raw data to add. * @param data_len The length of the data. */ void put_data(char *data_bytes, int data_len) { put_int16(data_len ); put_raw_data(data_bytes, data_len ); }