@@ -4817,7 +4817,7 @@ static size_t trim_len(struct mg_connection *c, size_t len) {
4817
4817
long mg_io_send(struct mg_connection *c, const void *buf, size_t len) {
4818
4818
struct mg_tcpip_if *ifp = c->mgr->ifp;
4819
4819
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 ;
4821
4821
len = trim_len(c, len);
4822
4822
if (c->is_udp) {
4823
4823
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) {
4864
4864
struct connstate *s = (struct connstate *) (c + 1);
4865
4865
struct mg_iobuf *io = c->is_tls ? &c->rtls : &c->recv;
4866
4866
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;
4869
4868
if (pkt->tcp->flags & TH_FIN) {
4870
4869
uint8_t flags = TH_ACK;
4871
4870
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) {
5353
5352
uint32_t rem_ip;
5354
5353
if ((c->is_udp && !c->is_arplooking) || c->is_listening || c->is_resolving)
5355
5354
continue;
5356
- memcpy(& rem_ip, c->rem.ip, sizeof(uint32_t)) ;
5355
+ rem_ip = c->rem.ip4 ;
5357
5356
if (ifp->now > s->timer) {
5358
5357
if (s->ttype == MIP_TTYPE_ARP) {
5359
5358
mg_error(c, "ARP timeout");
@@ -5444,8 +5443,7 @@ void mg_tcpip_free(struct mg_tcpip_if *ifp) {
5444
5443
static void send_syn(struct mg_connection *c) {
5445
5444
struct connstate *s = (struct connstate *) (c + 1);
5446
5445
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;
5449
5447
tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_SYN, c->loc.port, c->rem.port, isn, 0,
5450
5448
NULL, 0);
5451
5449
}
@@ -5469,11 +5467,10 @@ static void ip4_mcastmac(uint8_t *mac, uint32_t *ip) {
5469
5467
5470
5468
void mg_connect_resolved(struct mg_connection *c) {
5471
5469
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;
5474
5471
c->is_resolving = 0;
5475
5472
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;
5477
5474
c->loc.port = mg_htons(ifp->eport++);
5478
5475
MG_DEBUG(("%lu %M -> %M", c->id, mg_print_ip_port, &c->loc, mg_print_ip_port,
5479
5476
&c->rem));
@@ -5525,8 +5522,7 @@ static void init_closure(struct mg_connection *c) {
5525
5522
struct connstate *s = (struct connstate *) (c + 1);
5526
5523
if (c->is_udp == false && c->is_listening == false &&
5527
5524
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;
5530
5526
tx_tcp(c->mgr->ifp, s->mac, rem_ip, TH_FIN | TH_ACK, c->loc.port,
5531
5527
c->rem.port, mg_htonl(s->seq), mg_htonl(s->ack), NULL, 0);
5532
5528
settmout(c, MIP_TTYPE_FIN);
@@ -5580,8 +5576,7 @@ void mg_mgr_poll(struct mg_mgr *mgr, int ms) {
5580
5576
bool mg_send(struct mg_connection *c, const void *buf, size_t len) {
5581
5577
struct mg_tcpip_if *ifp = c->mgr->ifp;
5582
5578
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;
5585
5580
if (ifp->ip == 0 || ifp->state != MG_TCPIP_STATE_READY) {
5586
5581
mg_error(c, "net down");
5587
5582
} else if (c->is_udp && (c->is_arplooking || c->is_resolving)) {
0 commit comments