@@ -4817,7 +4817,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
48174817long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
48184818 struct mg_tcpip_if *ifp = c->mgr->ifp;
48194819 struct connstate *s = (struct connstate *) (c + 1);
4820- uint32_t dst_ip = *(uint32_t *) c->rem.ip ;
4820+ uint32_t dst_ip = c->rem.ip4 ;
48214821 len = trim_len(c, len);
48224822 if (c->is_udp) {
48234823 if (!tx_udp(ifp, s->mac, ifp->ip, c->loc.port, dst_ip, c->rem.port, buf,
@@ -4864,8 +4864,7 @@ static void read_conn(struct mg_connection *c, struct pkt *pkt) {
48644864 struct connstate *s = (struct connstate *) (c + 1);
48654865 struct mg_iobuf *io = c->is_tls ? &c->rtls : &c->recv;
48664866 uint32_t seq = mg_ntohl(pkt->tcp->seq);
4867- uint32_t rem_ip;
4868- memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
4867+ uint32_t rem_ip = c->rem.ip4;
48694868 if (pkt->tcp->flags & TH_FIN) {
48704869 uint8_t flags = TH_ACK;
48714870 if (mg_ntohl(pkt->tcp->seq) != s->ack) {
@@ -5353,7 +5352,7 @@ static void mg_tcpip_poll(struct mg_tcpip_if *ifp, uint64_t now) {
53535352 uint32_t rem_ip;
53545353 if ((c->is_udp && !c->is_arplooking) || c->is_listening || c->is_resolving)
53555354 continue;
5356- memcpy(& rem_ip, c->rem.ip, sizeof(uint32_t)) ;
5355+ rem_ip = c->rem.ip4 ;
53575356 if (ifp->now > s->timer) {
53585357 if (s->ttype == MIP_TTYPE_ARP) {
53595358 mg_error(c, "ARP timeout");
@@ -5444,8 +5443,7 @@ void mg_tcpip_free(struct mg_tcpip_if *ifp) {
54445443static void send_syn(struct mg_connection *c) {
54455444 struct connstate *s = (struct connstate *) (c + 1);
54465445 uint32_t isn = mg_htonl((uint32_t) mg_ntohs(c->loc.port));
5447- uint32_t rem_ip;
5448- memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5446+ uint32_t rem_ip = c->rem.ip4;
54495447 tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0,
54505448 NULL, 0);
54515449}
@@ -5469,11 +5467,10 @@ static void ip4_mcastmac(uint8_t *mac, uint32_t *ip) {
54695467
54705468void mg_connect_resolved(struct mg_connection *c) {
54715469 struct mg_tcpip_if *ifp = c->mgr->ifp;
5472- uint32_t rem_ip;
5473- memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5470+ uint32_t rem_ip = c->rem.ip4;
54745471 c->is_resolving = 0;
54755472 if (ifp->eport < MG_EPHEMERAL_PORT_BASE) ifp->eport = MG_EPHEMERAL_PORT_BASE;
5476- memcpy( c->loc.ip, & ifp->ip, sizeof(uint32_t)) ;
5473+ c->loc.ip4 = ifp->ip;
54775474 c->loc.port = mg_htons(ifp->eport++);
54785475 MG_DEBUG(("%lu %M -> %M", c->id, mg_print_ip_port, &c->loc, mg_print_ip_port,
54795476 &c->rem));
@@ -5525,8 +5522,7 @@ static void init_closure(struct mg_connection *c) {
55255522 struct connstate *s = (struct connstate *) (c + 1);
55265523 if (c->is_udp == false && c->is_listening == false &&
55275524 c->is_connecting == false) { // For TCP conns,
5528- uint32_t rem_ip;
5529- memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5525+ uint32_t rem_ip = c->rem.ip4;
55305526 tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
55315527 c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
55325528 settmout(c, MIP_TTYPE_FIN);
@@ -5580,8 +5576,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
55805576bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
55815577 struct mg_tcpip_if *ifp = c->mgr->ifp;
55825578 bool res = false;
5583- uint32_t rem_ip;
5584- memcpy(&rem_ip, c->rem.ip, sizeof(uint32_t));
5579+ uint32_t rem_ip = c->rem.ip4;
55855580 if (ifp->ip == 0 || ifp->state != MG_TCPIP_STATE_READY) {
55865581 mg_error(c, "net down");
55875582 } else if (c->is_udp && (c->is_arplooking || c->is_resolving)) {
0 commit comments