From c8f4fe0fe282ca40388586e070a3bd26f54299af Mon Sep 17 00:00:00 2001 From: Willy Tarreau Date: Tue, 31 Jan 2023 23:31:30 +0100 Subject: src: keep a copy of non-standard baud rates for reporting On macos we can set a non-standard baud rate but not report it. Instead of reporting 9600, let's report a copy of the configured baud rate if it was successful. We try to avoid that as much as possible as it's better to always report what the OS sees, so we only copy it on non-standard with macos. --- src/bt.c | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/bt.c b/src/bt.c index 3194f21..9447bed 100644 --- a/src/bt.c +++ b/src/bt.c @@ -308,6 +308,7 @@ int nbports = 0; int currport = -1; // last one int quiet = 0; int baud = 115200; +int write_only_baud = 0; // report this value if non-zero char cap_name[PATH_MAX]; int cap_fd = -1; // -1 = no capture in progress @@ -462,6 +463,13 @@ int get_baud_rate(int fd) struct termios2 tio; int idx; + /* We may have to report a copy of a previously set non-standard baud + * rate on some platforms because there is no way to retrieve the + * info from the OS (eg: macos). + */ + if (write_only_baud) + return write_only_baud; + ioctl(fd, TCGETS2, &tio); if ((tio.c_cflag & (CBAUD|CBAUDEX)) == BOTHER) return tio.c_ospeed; @@ -557,6 +565,8 @@ int set_port(int fd, int baud) #ifdef __APPLE__ /* try to set a non-standard baud rate */ else if (ioctl(fd, IOSSIOSPEED, &baud) >= 0) { + /* keep a copy of it as we can't retrieve it */ + write_only_baud = baud; /* finally succeeded */ baud_flag = 0; } -- 2.17.5