* fd is connected to the remote side; send the sideband data * over multiplexed packet stream. */
| 437 | * over multiplexed packet stream. |
| 438 | */ |
| 439 | void send_sideband(int fd, int band, const char *data, ssize_t sz, int packet_max) |
| 440 | { |
| 441 | const char *p = data; |
| 442 | |
| 443 | while (sz) { |
| 444 | unsigned n; |
| 445 | char hdr[5]; |
| 446 | |
| 447 | n = sz; |
| 448 | if (packet_max - 5 < n) |
| 449 | n = packet_max - 5; |
| 450 | if (0 <= band) { |
| 451 | xsnprintf(hdr, sizeof(hdr), "%04x", n + 5); |
| 452 | hdr[4] = band; |
| 453 | write_or_die(fd, hdr, 5); |
| 454 | } else { |
| 455 | xsnprintf(hdr, sizeof(hdr), "%04x", n + 4); |
| 456 | write_or_die(fd, hdr, 4); |
| 457 | } |
| 458 | write_or_die(fd, p, n); |
| 459 | p += n; |
| 460 | sz -= n; |
| 461 | } |
| 462 | } |