]> git.ipfire.org Git - thirdparty/valgrind.git/commitdiff
Provide a full set of ntohl/htonl/ntohs/htons routines in the
authorTom Hughes <tom@compton.nu>
Thu, 17 Nov 2005 12:01:56 +0000 (12:01 +0000)
committerTom Hughes <tom@compton.nu>
Thu, 17 Nov 2005 12:01:56 +0000 (12:01 +0000)
valgrind C library.

git-svn-id: svn://svn.valgrind.org/valgrind/trunk@5162

coregrind/m_libcfile.c
coregrind/pub_core_libcfile.h

index 8c299e50860b379c0eab2891debc46aad4912fce..8a78d6db565625f881b5e4c891e96020fa2d158c 100644 (file)
@@ -339,8 +339,7 @@ static
 Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr, 
                  Int addrlen );
 
-static 
-UInt my_htonl ( UInt x )
+UInt VG_(htonl) ( UInt x )
 {
 #  if defined(VG_BIGENDIAN)
    return x;
@@ -351,8 +350,28 @@ UInt my_htonl ( UInt x )
 #  endif
 }
 
-static
-UShort my_htons ( UShort x )
+UInt VG_(ntohl) ( UInt x )
+{
+#  if defined(VG_BIGENDIAN)
+   return x;
+#  else
+   return
+      (((x >> 24) & 0xFF) << 0) | (((x >> 16) & 0xFF) << 8)
+      | (((x >> 8) & 0xFF) << 16) | (((x >> 0) & 0xFF) << 24);
+#  endif
+}
+
+UShort VG_(htons) ( UShort x )
+{
+#  if defined(VG_BIGENDIAN)
+   return x;
+#  else
+   return
+      (((x >> 8) & 0xFF) << 0) | (((x >> 0) & 0xFF) << 8);
+#  endif
+}
+
+UShort VG_(ntohs) ( UShort x )
 {
 #  if defined(VG_BIGENDIAN)
    return x;
@@ -390,8 +409,8 @@ Int VG_(connect_via_socket)( UChar* str )
    //               (UInt)port );
 
    servAddr.sin_family = VKI_AF_INET;
-   servAddr.sin_addr.s_addr = my_htonl(ip);
-   servAddr.sin_port = my_htons(port);
+   servAddr.sin_addr.s_addr = VG_(htonl)(ip);
+   servAddr.sin_port = VG_(htons)(port);
 
    /* create socket */
    sd = my_socket(VKI_AF_INET, VKI_SOCK_STREAM, 0 /* IPPROTO_IP ? */);
index ef0791e32de05bf8b2c346bd719348f47ca992c1..aa964f8168913d05f6dc5f80b4d836596e67e371 100644 (file)
@@ -55,6 +55,11 @@ extern Bool VG_(is_dir) ( HChar* f );
    none specified. */
 #define VG_CLO_DEFAULT_LOGPORT 1500
 
+extern UInt   VG_(htonl) ( UInt x );
+extern UInt   VG_(ntohl) ( UInt x );
+extern UShort VG_(htons) ( UShort x );
+extern UShort VG_(ntohs) ( UShort x );
+
 extern Int VG_(write_socket)( Int sd, void *msg, Int count );
 extern Int VG_(connect_via_socket)( UChar* str );
 extern Int VG_(getsockname) ( Int sd, struct vki_sockaddr *name, Int *namelen );