diff --git a/snmplib/transports/snmpSSHDomain.c b/snmplib/transports/snmpSSHDomain.c
index a9ed81f..e745719 100644
--- a/snmplib/transports/snmpSSHDomain.c
+++ b/snmplib/transports/snmpSSHDomain.c
@@ -772,8 +772,8 @@ netsnmp_ssh_transport(struct sockaddr_in *addr, int local)
             return NULL;
         }
         memcpy(t->remote, (u_char *) & (addr->sin_addr.s_addr), 4);
-        t->remote[4] = (htons(addr->sin_port) & 0xff00) >> 8;
-        t->remote[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
+        t->remote[4] = (ntohs(addr->sin_port) & 0xff00) >> 8;
+        t->remote[5] = (ntohs(addr->sin_port) & 0x00ff) >> 0;
         t->remote_length = 6;
 
         /*
@@ -916,7 +916,7 @@ netsnmp_ssh_create_ostring(const u_char * o, size_t o_len, int local)
     struct sockaddr_in addr;
 
     if (o_len == 6) {
-        unsigned short porttmp = (o[4] << 8) + o[5];
+        unsigned short porttmp = (o[4] << 8) + o[5]; // ntohs()
         addr.sin_family = AF_INET;
         memcpy((u_char *) & (addr.sin_addr.s_addr), o, 4);
         addr.sin_port = htons(porttmp);
diff --git a/snmplib/transports/snmpTCPDomain.c b/snmplib/transports/snmpTCPDomain.c
index ce02bc0..2b2ce7b 100644
--- a/snmplib/transports/snmpTCPDomain.c
+++ b/snmplib/transports/snmpTCPDomain.c
@@ -221,8 +221,8 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
             return NULL;
         }
         memcpy(t->local, (u_char *) & (addr->sin_addr.s_addr), 4);
-        t->local[4] = (htons(addr->sin_port) & 0xff00) >> 8;
-        t->local[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
+        t->local[4] = (ntohs(addr->sin_port) & 0xff00) >> 8;
+        t->local[5] = (ntohs(addr->sin_port) & 0x00ff) >> 0;
         t->local_length = 6;
 
         /*
@@ -277,8 +277,8 @@ netsnmp_tcp_transport(struct sockaddr_in *addr, int local)
             return NULL;
         }
         memcpy(t->remote, (u_char *) & (addr->sin_addr.s_addr), 4);
-        t->remote[4] = (htons(addr->sin_port) & 0xff00) >> 8;
-        t->remote[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
+        t->remote[4] = (ntohs(addr->sin_port) & 0xff00) >> 8;
+        t->remote[5] = (ntohs(addr->sin_port) & 0x00ff) >> 0;
         t->remote_length = 6;
 
         /*
@@ -344,7 +344,7 @@ netsnmp_tcp_create_ostring(const u_char * o, size_t o_len, int local)
     struct sockaddr_in addr;
 
     if (o_len == 6) {
-        unsigned short porttmp = (o[4] << 8) + o[5];
+        unsigned short porttmp = (o[4] << 8) + o[5]; // ntohs()
         addr.sin_family = AF_INET;
         memcpy((u_char *) & (addr.sin_addr.s_addr), o, 4);
         addr.sin_port = htons(porttmp);
diff --git a/snmplib/transports/snmpTCPIPv6Domain.c b/snmplib/transports/snmpTCPIPv6Domain.c
index b0ad779..6973647 100644
--- a/snmplib/transports/snmpTCPIPv6Domain.c
+++ b/snmplib/transports/snmpTCPIPv6Domain.c
@@ -227,8 +227,8 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
             return NULL;
         }
         memcpy(t->local, addr->sin6_addr.s6_addr, 16);
-        t->local[16] = (addr->sin6_port & 0xff00) >> 8;
-        t->local[17] = (addr->sin6_port & 0x00ff) >> 0;
+        t->local[16] = (ntohs(addr->sin6_port) & 0xff00) >> 8;
+        t->local[17] = (ntohs(addr->sin6_port) & 0x00ff) >> 0;
         t->local_length = 18;
 
         /*
@@ -284,8 +284,8 @@ netsnmp_tcp6_transport(struct sockaddr_in6 *addr, int local)
             return NULL;
         }
         memcpy(t->remote, addr->sin6_addr.s6_addr, 16);
-        t->remote[16] = (addr->sin6_port & 0xff00) >> 8;
-        t->remote[17] = (addr->sin6_port & 0x00ff) >> 0;
+        t->remote[16] = (ntohs(addr->sin6_port) & 0xff00) >> 8;
+        t->remote[17] = (ntohs(addr->sin6_port) & 0x00ff) >> 0;
         t->remote_length = 18;
 
         /*
@@ -365,10 +365,11 @@ netsnmp_tcp6_create_ostring(const u_char * o, size_t o_len, int local)
     struct sockaddr_in6 addr;
 
     if (o_len == 18) {
+        unsigned short porttmp = (o[16] << 8) + o[17]; // ntohs()
         memset((u_char *) & addr, 0, sizeof(struct sockaddr_in6));
         addr.sin6_family = AF_INET6;
         memcpy((u_char *) & (addr.sin6_addr.s6_addr), o, 16);
-        addr.sin6_port = (o[16] << 8) + o[17];
+        addr.sin6_port = htons(porttmp);
         return netsnmp_tcp6_transport(&addr, local);
     }
     return NULL;
diff --git a/snmplib/transports/snmpUDPIPv4BaseDomain.c b/snmplib/transports/snmpUDPIPv4BaseDomain.c
index eaf048e..fa39e4b 100644
--- a/snmplib/transports/snmpUDPIPv4BaseDomain.c
+++ b/snmplib/transports/snmpUDPIPv4BaseDomain.c
@@ -128,8 +128,8 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
             return NULL;
         }
         memcpy(t->local, (u_char *) & (addr->sin_addr.s_addr), 4);
-        t->local[4] = (htons(addr->sin_port) & 0xff00) >> 8;
-        t->local[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
+        t->local[4] = (ntohs(addr->sin_port) & 0xff00) >> 8;
+        t->local[5] = (ntohs(addr->sin_port) & 0x00ff) >> 0;
         t->local_length = 6;
 
 #ifndef WIN32
@@ -250,8 +250,8 @@ netsnmp_udpipv4base_transport(struct sockaddr_in *addr, int local)
             return NULL;
         }
         memcpy(t->remote, (u_char *) & (addr->sin_addr.s_addr), 4);
-        t->remote[4] = (htons(addr->sin_port) & 0xff00) >> 8;
-        t->remote[5] = (htons(addr->sin_port) & 0x00ff) >> 0;
+        t->remote[4] = (ntohs(addr->sin_port) & 0xff00) >> 8;
+        t->remote[5] = (ntohs(addr->sin_port) & 0x00ff) >> 0;
         t->remote_length = 6;
         memcpy(t->data, &addr_pair, sizeof(netsnmp_indexed_addr_pair));
         t->data_length = sizeof(netsnmp_indexed_addr_pair);
diff --git a/snmplib/transports/snmpUDPIPv6Domain.c b/snmplib/transports/snmpUDPIPv6Domain.c
index 00e567f..77e6ead 100644
--- a/snmplib/transports/snmpUDPIPv6Domain.c
+++ b/snmplib/transports/snmpUDPIPv6Domain.c
@@ -275,8 +275,8 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
             return NULL;
         }
         memcpy(t->local, addr->sin6_addr.s6_addr, 16);
-        t->local[16] = (addr->sin6_port & 0xff00) >> 8;
-        t->local[17] = (addr->sin6_port & 0x00ff) >> 0;
+        t->local[16] = (ntohs(addr->sin6_port) & 0xff00) >> 8;
+        t->local[17] = (ntohs(addr->sin6_port) & 0x00ff) >> 0;
         t->local_length = 18;
         t->data = NULL;
         t->data_length = 0;
@@ -304,8 +304,8 @@ netsnmp_udp6_transport(struct sockaddr_in6 *addr, int local)
             return NULL;
         }
         memcpy(t->remote, addr->sin6_addr.s6_addr, 16);
-        t->remote[16] = (addr->sin6_port & 0xff00) >> 8;
-        t->remote[17] = (addr->sin6_port & 0x00ff) >> 0;
+        t->remote[16] = (ntohs(addr->sin6_port) & 0xff00) >> 8;
+        t->remote[17] = (ntohs(addr->sin6_port) & 0x00ff) >> 0;
         t->remote_length = 18;
     }
 
@@ -766,10 +766,11 @@ netsnmp_udp6_create_ostring(const u_char * o, size_t o_len, int local)
     struct sockaddr_in6 addr;
 
     if (o_len == 18) {
+        unsigned short porttmp = (o[16] << 8) + o[17]; // ntohs()
         memset((u_char *) & addr, 0, sizeof(struct sockaddr_in6));
         addr.sin6_family = AF_INET6;
         memcpy((u_char *) & (addr.sin6_addr.s6_addr), o, 16);
-        addr.sin6_port = (o[16] << 8) + o[17];
+        addr.sin6_port = htons(porttmp);
         return netsnmp_udp6_transport(&addr, local);
     }
     return NULL;
