diff options
author | Michael Scott <michael.scott@linaro.org> | 2017-01-23 15:18:46 -0800 |
---|---|---|
committer | Jukka Rissanen <jukka.rissanen@linux.intel.com> | 2017-02-03 15:59:16 +0200 |
commit | 50a93d906d248b847f8436923644a602d0b99b5c (patch) | |
tree | 78972ad0eee4d36154b2e2afe9d967fb83b8a57d /samples | |
parent | fc9443209f1d4f073ed223aa6194bc1ae200ebe3 (diff) |
samples: net: irc_bot: create semi-unique IRC user names
IRC won't allow 2 users to use the same user name, so let's add
a random number to the end of "zephyrbot" to make it semi-unique.
Change-Id: I56349de21823d8fd2c52646656615b42fc12de5e
Signed-off-by: Michael Scott <michael.scott@linaro.org>
Diffstat (limited to 'samples')
-rw-r--r-- | samples/net/irc_bot/src/irc-bot.c | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/samples/net/irc_bot/src/irc-bot.c b/samples/net/irc_bot/src/irc-bot.c index c9b96654e..e92b6aa84 100644 --- a/samples/net/irc_bot/src/irc-bot.c +++ b/samples/net/irc_bot/src/irc-bot.c @@ -419,6 +419,7 @@ zirc_connect(struct zirc *irc, const char *host, int port, void *data) struct sockaddr dst_addr, src_addr; struct zirc_chan *chan; int ret; + char name_buf[32]; NET_INFO("Connecting to %s:%d...", host, port); @@ -462,14 +463,20 @@ zirc_connect(struct zirc *irc, const char *host, int port, void *data) chan = irc->data; - if (zirc_nick_set(irc, "zephyrbot") < 0) { - panic("Could not set nick"); + ret = snprintk(name_buf, sizeof(name_buf), "zephyrbot%u", + sys_rand32_get()); + if (ret < 0 || ret >= sizeof(name_buf)) { + panic("Can't fill name buffer"); } - if (zirc_user_set(irc, "zephyrbot", "Zephyr IRC Bot") < 0) { + if (zirc_nick_set(irc, name_buf) < 0) { panic("Could not set nick"); } + if (zirc_user_set(irc, name_buf, "Zephyr IRC Bot") < 0) { + panic("Could not set user"); + } + if (zirc_chan_join(irc, chan, DEFAULT_CHANNEL, on_msg_rcvd, NULL) < 0) { panic("Could not join channel"); } |