- For writing sin_port, htons() must be used.
authorlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 8 Feb 2013 21:34:26 +0000 (21:34 +0000)
committerlpleahy <lpleahy@6f19259b-4bc3-4df7-8a09-765794883524>
Fri, 8 Feb 2013 21:34:26 +0000 (21:34 +0000)
- For reading sin_port, ntohs() must be used.

Contributed-under: TianoCore Contribution Agreement 1.0

Signed-off-by: lpleahy
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
git-svn-id: https://edk2.svn.sourceforge.net/svnroot/edk2/trunk/edk2@14127 6f19259b-4bc3-4df7-8a09-765794883524

AppPkg/Applications/Sockets/DataSink/DataSink.c

index f2c3b3b..14b2fd1 100644 (file)
@@ -340,7 +340,7 @@ SocketPoll (
                         ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                         ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                         ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                        htons ( pPortIpAddress4->sin_port ),\r
+                        ntohs ( pPortIpAddress4->sin_port ),\r
                         errno ));\r
             }\r
             else {\r
@@ -362,7 +362,7 @@ SocketPoll (
                         pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                         pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                         pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                        htons ( pPortIpAddress6->sin6_port ),\r
+                        ntohs ( pPortIpAddress6->sin6_port ),\r
                         errno ));\r
             }\r
 \r
@@ -380,7 +380,7 @@ SocketPoll (
                           ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pPortIpAddress4->sin_port )));\r
+                          ntohs ( pPortIpAddress4->sin_port )));\r
               }\r
               else {\r
                 DEBUG (( DEBUG_INFO,\r
@@ -402,7 +402,7 @@ SocketPoll (
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pPortIpAddress6->sin6_port )));\r
+                          ntohs ( pPortIpAddress6->sin6_port )));\r
               }\r
             }\r
             else {\r
@@ -414,7 +414,7 @@ SocketPoll (
                           ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pPortIpAddress4->sin_port ),\r
+                          ntohs ( pPortIpAddress4->sin_port ),\r
                           errno ));\r
               }\r
               else {\r
@@ -437,7 +437,7 @@ SocketPoll (
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pPortIpAddress6->sin6_port ),\r
+                          ntohs ( pPortIpAddress6->sin6_port ),\r
                           errno ));\r
               }\r
             }\r
@@ -484,7 +484,7 @@ SocketPoll (
                           ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pRemoteAddress4->sin_port ));\r
+                          ntohs ( pRemoteAddress4->sin_port ));\r
                 }\r
                 else {\r
                   Print ( L"Rejecting connection to remote system [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
@@ -504,7 +504,7 @@ SocketPoll (
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pRemoteAddress6->sin6_port ));\r
+                          ntohs ( pRemoteAddress6->sin6_port ));\r
                 }\r
 \r
                 //\r
@@ -522,7 +522,7 @@ SocketPoll (
                               ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                               ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                               ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                              htons ( pRemoteAddress4->sin_port )));\r
+                              ntohs ( pRemoteAddress4->sin_port )));\r
                   }\r
                   else {\r
                     DEBUG (( DEBUG_INFO,\r
@@ -544,7 +544,7 @@ SocketPoll (
                               pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                               pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                               pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                              htons ( pRemoteAddress6->sin6_port )));\r
+                              ntohs ( pRemoteAddress6->sin6_port )));\r
                   }\r
                 }\r
                 else {\r
@@ -570,7 +570,7 @@ SocketPoll (
                           ( pRemoteAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pRemoteAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pRemoteAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pRemoteAddress4->sin_port ));\r
+                          ntohs ( pRemoteAddress4->sin_port ));\r
                 }\r
                 else {\r
                   Print ( L"Connected to remote system [%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x:%02x%02x]:%d\r\n",\r
@@ -590,7 +590,7 @@ SocketPoll (
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pRemoteAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pRemoteAddress6->sin6_port ));\r
+                          ntohs ( pRemoteAddress6->sin6_port ));\r
                 }\r
 \r
                 //\r
@@ -625,7 +625,7 @@ SocketPoll (
                           ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pPortIpAddress4->sin_port )));\r
+                          ntohs ( pPortIpAddress4->sin_port )));\r
               }\r
               else {\r
                 DEBUG (( DEBUG_INFO,\r
@@ -648,7 +648,7 @@ SocketPoll (
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pPortIpAddress6->sin6_port )));\r
+                          ntohs ( pPortIpAddress6->sin6_port )));\r
               }\r
 \r
               //\r
@@ -677,7 +677,7 @@ SocketPoll (
                           ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                           ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                          htons ( pPortIpAddress4->sin_port ),\r
+                          ntohs ( pPortIpAddress4->sin_port ),\r
                           errno ));\r
               }\r
               else {\r
@@ -699,7 +699,7 @@ SocketPoll (
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                           pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                          htons ( pPortIpAddress6->sin6_port ),\r
+                          ntohs ( pPortIpAddress6->sin6_port ),\r
                           errno ));\r
               }\r
               CloseStatus = close ( PollFd[ Index ].fd );\r
@@ -713,7 +713,7 @@ SocketPoll (
                             ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                             ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                             ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                            htons ( pPortIpAddress4->sin_port )));\r
+                            ntohs ( pPortIpAddress4->sin_port )));\r
                 }\r
                 else {\r
                   DEBUG (( DEBUG_INFO,\r
@@ -735,7 +735,7 @@ SocketPoll (
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                            htons ( pPortIpAddress6->sin6_port )));\r
+                            ntohs ( pPortIpAddress6->sin6_port )));\r
                 }\r
               }\r
               else {\r
@@ -747,7 +747,7 @@ SocketPoll (
                             ( pPortIpAddress4->sin_addr.s_addr >> 8 ) & 0xff,\r
                             ( pPortIpAddress4->sin_addr.s_addr >> 16 ) & 0xff,\r
                             ( pPortIpAddress4->sin_addr.s_addr >> 24 ) & 0xff,\r
-                            htons ( pPortIpAddress4->sin_port ),\r
+                            ntohs ( pPortIpAddress4->sin_port ),\r
                             errno ));\r
                 }\r
                 else {\r
@@ -770,7 +770,7 @@ SocketPoll (
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 13 ],\r
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 14 ],\r
                             pPortIpAddress6->sin6_addr.__u6_addr.__u6_addr8[ 15 ],\r
-                            htons ( pPortIpAddress6->sin6_port ),\r
+                            ntohs ( pPortIpAddress6->sin6_port ),\r
                             errno ));\r
                 }\r
               }\r