Created
April 27, 2016 23:04
-
-
Save austinschwartz/8e3a59eae62ff318692f459fcc0575fa to your computer and use it in GitHub Desktop.
the most beautiful code that ever was
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This code is awful | |
// IT WORKS THOUGH :D | |
// High five whoevers reading this! | |
char *host_addr_to_string(char *addr) { | |
char *buf = (char*)malloc(22); | |
uint8_t ipb[4]; | |
uint16_t port; | |
sscanf(addr, "%03hhu%03hhu%03hhu%03hhu:%05hu", &ipb[3], &ipb[2], &ipb[1], &ipb[0], &port); | |
sprintf(buf, "%hhu.%hhu.%hhu.%hhu:%03hu", ipb[3], ipb[2], ipb[1], ipb[0], port); | |
return buf; | |
} | |
// This code is also awful | |
char *addr_to_host_addr(const char *ip, uint16_t port) { | |
char *buf = (char*)malloc(20); | |
uint8_t ipb[4]; | |
sscanf(ip, "%03hhu.%03hhu.%03hhu.%03hhu", &ipb[3], &ipb[2], &ipb[1], &ipb[0]); | |
sprintf(buf, "%03hhu%03hhu%03hhu%03hhu:%05hu", ipb[3], ipb[2], ipb[1], ipb[0], port); | |
return buf; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment