From 3be3c332a5e47434d74e99e2ed77e9fb9f4cf60c Mon Sep 17 00:00:00 2001 From: "B. Watson" Date: Fri, 15 Mar 2019 17:14:18 -0400 Subject: printf removal --- src/formatip.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 src/formatip.c (limited to 'src/formatip.c') diff --git a/src/formatip.c b/src/formatip.c new file mode 100644 index 0000000..f1a2fd1 --- /dev/null +++ b/src/formatip.c @@ -0,0 +1,34 @@ +#include +#include "uip.h" + +/* easier to copy/paste this tiny function from uip.c + than it would be to rebuild all of uIP for use in + this program! Also don't want to bloat fujiconf by + linking uip.a, even if it would link without a + recompile. */ +/* +u16_t local_htons(u16_t val) { + return HTONS(val); +} +*/ + +/* this version's half the size */ +static u16_t local_htons(u16_t val) { + __AX__ = val; + asm("sta tmp1"); + asm("txa"); + asm("ldx tmp1"); +} + +static char ipbuf[20]; + +char *format_ip(uip_ipaddr_t *ip) { + u16_t *ipaddr = (u16_t *)ip; + sprintf(ipbuf, "%d.%d.%d.%d", + local_htons(ipaddr[0]) >> 8, + local_htons(ipaddr[0]) & 0xff, + local_htons(ipaddr[1]) >> 8, + local_htons(ipaddr[1]) & 0xff); + + return ipbuf; +} -- cgit v1.2.3