MCPcopy Create free account
hub / github.com/bk138/multivnc / parseHostString

Method parseHostString

src/gui/MyFrameMain.cpp:1585–1625  ·  view source on GitHub ↗

parse ipv4 or ipv6 address string. taken from remmina, thanks! */

Source from the content-addressed store, hash-verified

1583 taken from remmina, thanks!
1584*/
1585void MyFrameMain::parseHostString(const char *server, int defaultport, char **host, int *port)
1586{
1587 char *str, *ptr, *ptr2;
1588
1589 str = strdup(server);
1590
1591 /* [server]:port format */
1592 ptr = strchr(str, '[');
1593 if (ptr)
1594 {
1595 ptr++;
1596 ptr2 = strchr(ptr, ']');
1597 if (ptr2)
1598 *ptr2++ = '\0';
1599 if (*ptr2 == ':')
1600 defaultport = atoi(ptr2 + 1);
1601 if (host)
1602 *host = strdup(ptr);
1603 if (port)
1604 *port = defaultport;
1605 free(str);
1606 return;
1607 }
1608
1609 /* server:port format, IPv6 cannot use this format */
1610 ptr = strchr(str, ':');
1611 if (ptr)
1612 {
1613 ptr2 = strchr(ptr + 1, ':');
1614 if (ptr2 == NULL)
1615 {
1616 *ptr++ = '\0';
1617 defaultport = atoi(ptr);
1618 }
1619 /* More than one ':' means this is IPv6 address. Treat it as a whole address */
1620 }
1621 if (host)
1622 *host = str;
1623 if (port)
1624 *port = defaultport;
1625}
1626
1627
1628/*

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected