Skip to content

Commit

Permalink
Merge pull request #23 from PDP-10/bictorv-dynamic-chudp-fix
Browse files Browse the repository at this point in the history
Make dynamic chudp work again.
  • Loading branch information
Björn Victor authored Aug 29, 2017
2 parents 3f3945f + 9d12eee commit 6f268f9
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/dpchudp.c
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ are completely independent.
#include <signal.h>
#include <stdarg.h>

#include <arpa/inet.h>

#include "klh10.h" /* Get config params */

/* This must precede any other OSD includes to ensure that DECOSF gets
Expand Down Expand Up @@ -442,7 +444,7 @@ chudptohost(register struct dpchudp_s *dpchudp)
/* OK, now do a blocking read on UDP socket! */
errno = 0; /* Clear to make sure it's the actual error */
memset(&ip_sender, 0, sizeof(ip_sender));
memset(&iplen, 0, sizeof(iplen));
iplen = sizeof(ip_sender); /* Supply size of ip_sender, and get actual stored length */
cnt = recvfrom(sock, buffp, DPCHUDP_MAXLEN, 0, (struct sockaddr *)&ip_sender, &iplen);
if (cnt <= DPCHUDP_DATAOFFSET) {
if (DBGFLG)
Expand Down Expand Up @@ -498,7 +500,7 @@ chudptohost(register struct dpchudp_s *dpchudp)
int chalen = ((buffp[DPCHUDP_DATAOFFSET+2] & 0xf)<<4) | buffp[DPCHUDP_DATAOFFSET+3];
int datalen = (DPCHUDP_DATAOFFSET + CHAOS_HEADERSIZE + chalen);
int chafrom = (buffp[cnt-4]<<8) | buffp[cnt-3];
unsigned char *ip = (unsigned char *)&ip_sender.sin_addr.s_addr;
char *ip = inet_ntoa(ip_sender.sin_addr);
in_port_t port = ntohs(ip_sender.sin_port);
time_t now = time(NULL);
int i, cks;
Expand All @@ -519,9 +521,9 @@ chudptohost(register struct dpchudp_s *dpchudp)
}
#if 0
if (DBGFLG) {
dbprintln("Rcv from chaos %o = ip %d.%d.%d.%d port %d., %d. bytes (datalen %d)",
dbprintln("Rcv from chaos %o = ip %s port %d., %d. bytes (datalen %d)",
chafrom,
ip[0],ip[1],ip[2],ip[3], port,
ip, port,
cnt, datalen);
dumppkt(buffp,cnt);
}
Expand All @@ -539,10 +541,10 @@ chudptohost(register struct dpchudp_s *dpchudp)
DPCHUDP_CHIP_DYNAMIC_AGE_LIMIT) {
/* Old, update it (in case he moved) */
if (1 || DBGFLG)
dbprintln("Updating CHIP entry %d for %o/%d.%d.%d.%d:%d",
i, chafrom, ip[0],ip[1],ip[2],ip[3], port);
dbprintln("Updating CHIP entry %d for %o/%s:%d",
i, chafrom, ip, port);
dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipport = port;
memcpy(&dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipaddr, ip, IP_ADRSIZ);
memcpy(&dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipaddr, &ip_sender.sin_addr, IP_ADRSIZ);
}
/* update timestamp */
dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_lastrcvd = now;
Expand All @@ -554,12 +556,12 @@ chudptohost(register struct dpchudp_s *dpchudp)
/* It's OK to write here, the other fork will see it when tlen is updated */
i = dpchudp->dpchudp_chip_tlen;
if (1 || DBGFLG)
dbprintln("Adding CHIP entry %d for %o/%d.%d.%d.%d:%d",
i, chafrom, ip[0],ip[1],ip[2],ip[3], port);
dbprintln("Adding CHIP entry %d for %o/%s:%d",
i, chafrom, ip, port);
dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_chaddr = chafrom;
dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipport = port;
dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_lastrcvd = now;
memcpy(&dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipaddr, ip, IP_ADRSIZ);
memcpy(&dpchudp->dpchudp_chip_tbl[i].dpchudp_chip_ipaddr, &ip_sender.sin_addr, IP_ADRSIZ);
dpchudp->dpchudp_chip_tlen++;
}
#if 0
Expand Down

0 comments on commit 6f268f9

Please sign in to comment.