* Read and display the next incoming control message */
| 127 | * Read and display the next incoming control message |
| 128 | */ |
| 129 | void |
| 130 | MsgRead(void) |
| 131 | { |
| 132 | struct ng_mesg *m, *m2; |
| 133 | struct ng_mesg *ascii; |
| 134 | char path[NG_PATHSIZ]; |
| 135 | |
| 136 | /* Get incoming message (in binary form) */ |
| 137 | if (NgAllocRecvMsg(csock, &m, path) < 0) { |
| 138 | warn("recv incoming message"); |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | /* Ask originating node to convert message to ASCII */ |
| 143 | if (NgSendMsg(csock, path, NGM_GENERIC_COOKIE, |
| 144 | NGM_BINARY2ASCII, m, sizeof(*m) + m->header.arglen) < 0 |
| 145 | || NgAllocRecvMsg(csock, &m2, NULL) < 0) { |
| 146 | printf("Rec'd %s %d from \"%s\":\n", |
| 147 | (m->header.flags & NGF_RESP) != 0 ? "response" : "command", |
| 148 | m->header.cmd, path); |
| 149 | if (m->header.arglen == 0) |
| 150 | printf("No arguments\n"); |
| 151 | else |
| 152 | DumpAscii((const u_char *)m->data, m->header.arglen); |
| 153 | free(m); |
| 154 | return; |
| 155 | } |
| 156 | |
| 157 | /* Display message in ASCII form */ |
| 158 | free(m); |
| 159 | ascii = (struct ng_mesg *)m2->data; |
| 160 | printf("Rec'd %s \"%s\" (%d) from \"%s\":\n", |
| 161 | (ascii->header.flags & NGF_RESP) != 0 ? "response" : "command", |
| 162 | ascii->header.cmdstr, ascii->header.cmd, path); |
| 163 | if (*ascii->data != '\0') |
| 164 | printf("Args:\t%s\n", ascii->data); |
| 165 | else |
| 166 | printf("No arguments\n"); |
| 167 | free(m2); |
| 168 | } |
| 169 |
no test coverage detected