|
From: <sv...@va...> - 2005-11-17 12:02:07
|
Author: tom
Date: 2005-11-17 12:01:56 +0000 (Thu, 17 Nov 2005)
New Revision: 5162
Log:
Provide a full set of ntohl/htonl/ntohs/htons routines in the=20
valgrind C library.
Modified:
trunk/coregrind/m_libcfile.c
trunk/coregrind/pub_core_libcfile.h
Modified: trunk/coregrind/m_libcfile.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/m_libcfile.c 2005-11-17 11:45:28 UTC (rev 5161)
+++ trunk/coregrind/m_libcfile.c 2005-11-17 12:01:56 UTC (rev 5162)
@@ -339,8 +339,7 @@
Int my_connect ( Int sockfd, struct vki_sockaddr_in* serv_addr,=20
Int addrlen );
=20
-static=20
-UInt my_htonl ( UInt x )
+UInt VG_(htonl) ( UInt x )
{
# if defined(VG_BIGENDIAN)
return x;
@@ -351,18 +350,38 @@
# endif
}
=20
-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
}
=20
+UShort VG_(ntohs) ( UShort x )
+{
+# if defined(VG_BIGENDIAN)
+ return x;
+# else
+ return
+ (((x >> 8) & 0xFF) << 0) | (((x >> 0) & 0xFF) << 8);
+# endif
+}
=20
+
/* The main function.=20
=20
Supplied string contains either an ip address "192.168.0.1" or
@@ -390,8 +409,8 @@
// (UInt)port );
=20
servAddr.sin_family =3D VKI_AF_INET;
- servAddr.sin_addr.s_addr =3D my_htonl(ip);
- servAddr.sin_port =3D my_htons(port);
+ servAddr.sin_addr.s_addr =3D VG_(htonl)(ip);
+ servAddr.sin_port =3D VG_(htons)(port);
=20
/* create socket */
sd =3D my_socket(VKI_AF_INET, VKI_SOCK_STREAM, 0 /* IPPROTO_IP ? */);
Modified: trunk/coregrind/pub_core_libcfile.h
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
--- trunk/coregrind/pub_core_libcfile.h 2005-11-17 11:45:28 UTC (rev 5161=
)
+++ trunk/coregrind/pub_core_libcfile.h 2005-11-17 12:01:56 UTC (rev 5162=
)
@@ -55,6 +55,11 @@
none specified. */
#define VG_CLO_DEFAULT_LOGPORT 1500
=20
+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 *na=
melen );
|