Skip to Content.
Sympa Menu

ndt-dev - [ndt-dev] [ndt] r802 committed - Include richard sanger's patch for issue 70

Subject: NDT-DEV email list created

List archive

[ndt-dev] [ndt] r802 committed - Include richard sanger's patch for issue 70


Chronological Thread 
  • From:
  • To:
  • Subject: [ndt-dev] [ndt] r802 committed - Include richard sanger's patch for issue 70
  • Date: Tue, 09 Apr 2013 13:12:04 +0000
  • Authentication-results: sfpop-ironport04.merit.edu; dkim=neutral (message not signed) header.i=none

Revision: 802
Author:

Date: Tue Apr 9 06:11:48 2013
Log: Include richard sanger's patch for issue 70


http://code.google.com/p/ndt/source/detail?r=802

Modified:
/trunk/src/web100-util.c
/trunk/src/web100clt.c

=======================================
--- /trunk/src/web100-util.c Thu Nov 15 13:34:19 2012
+++ /trunk/src/web100-util.c Tue Apr 9 06:11:48 2013
@@ -55,6 +55,48 @@

return (count_vars);
}
+
+/**
+ * Get a string representation of an ip address.
+ *
+ * @param addr A sockaddr structure which contains the address
+ * @param buf A buffer to fill with the ip address as a string
+ * @param len The length of buf.
+ */
+static void addr2a(struct sockaddr_storage * addr,char * buf, int len){
+ if(((struct sockaddr *)addr)->sa_family == AF_INET){
+ /* IPv4 */
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)addr)->sin_addr),
+ buf, len);
+ }
+#ifdef AF_INET6
+ else if(((struct sockaddr *)addr)->sa_family == AF_INET6 ){
+ /* IPv6 */
+ inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)addr)->sin6_addr),
+ buf, len);
+ }
+#endif
+}
+
+/**
+ * Get a string representation of an port number.
+ *
+ * @param addr A sockaddr structure which contains the port number
+ * @param buf A buffer to fill with the port number as a string
+ * @param len The length of buf.
+ */
+static void port2a(struct sockaddr_storage * addr,char * buf, int len){
+ if(((struct sockaddr *)addr)->sa_family == AF_INET){
+ /* IPv4 */
+ snprintf(buf, len, "%hu", ntohs(((struct sockaddr_in *)addr)->sin_port));
+ }
+#ifdef AF_INET6
+ else if(((struct sockaddr *)addr)->sa_family == AF_INET6 ){
+ /* IPv6 */
+ snprintf(buf, len, "%hu", ntohs(((struct sockaddr_in6 *)addr)->sin6_port));
+ }
+#endif
+}

/**
* Performs part of the middlebox test.
@@ -88,10 +130,11 @@
int ret;
char tmpstr[200];
size_t tmpstrlen = sizeof(tmpstr);
- I2Addr addr = NULL;
web100_var *LimCwnd;
u_int32_t limcwnd_val;
-
+ struct sockaddr_storage saddr;
+ socklen_t saddr_size;
+
// middlebox test results
static char vars[][255] = { "CurMSS", "WinScaleSent", "WinScaleRecv", };

@@ -101,16 +144,24 @@

// get Server address and add to "results"

- // get socket name
- addr = I2AddrByLocalSockFD(get_errhandle(), sock, False);
- memset(tmpstr, 0, 200);
- // copy address into tmpstr String
- I2AddrNodeName(addr, tmpstr, &tmpstrlen);
- // now copy tmpstr containing address into "line"
- snprintf(line, sizeof(line), "%s;", tmpstr);
- memset(tmpstr, 0, 200);
- // service name into tmpstr
- I2AddrServName(addr, tmpstr, &tmpstrlen);
+ // get socket IP address
+ saddr_size = sizeof(saddr);
+ if (getsockname(sock,(struct sockaddr *) &saddr, &saddr_size) == -1) {
+ /* Make it clear something failed but continue test */
+ log_println(0,"Middlebox - getsockname() failed: %s", strerror(errno));
+ snprintf(line, sizeof(line), "address_error;");
+ snprintf(tmpstr, sizeof(tmpstr), "0");
+ } else {
+ // copy address into tmpstr String
+ memset(tmpstr, 0, 200);
+ addr2a(&saddr, tmpstr , tmpstrlen);
+ // now copy tmpstr containing address into "line"
+ snprintf(line, sizeof(line), "%s;", tmpstr);
+ memset(tmpstr, 0, 200);
+ // service name into tmpstr
+ tmpstrlen = sizeof(tmpstr);
+ port2a(&saddr, tmpstr, tmpstrlen);
+ }
log_print(3, "Server: %s%s ", line, tmpstr);
// copy servers address into the meta test struct
memcpy(meta.server_ip, line, strlen(line));
@@ -118,19 +169,26 @@
meta.server_ip[(strlen(line) - 1)] = 0;
// Add this address to results
strlcat(results, line, results_strlen);
- I2AddrFree(addr); // free memory

// Now perform the above set of functions for client address/service name
// and copy into results
tmpstrlen = sizeof(tmpstr);
- addr = I2AddrBySockFD(get_errhandle(), sock, False);
- memset(tmpstr, 0, 200);
- I2AddrNodeName(addr, tmpstr, &tmpstrlen);
- snprintf(line, sizeof(line), "%s;", tmpstr);
- I2AddrServName(addr, tmpstr, &tmpstrlen);
+ saddr_size = sizeof(saddr);
+ if (getpeername(sock,(struct sockaddr *) &saddr, &saddr_size) == -1) {
+ /* Make it clear something failed but continue test */
+ log_println(0,"Middlebox - getpeername() failed: %s", strerror(errno));
+ snprintf(line, sizeof(line), "address_error;");
+ snprintf(tmpstr, sizeof(tmpstr), "0");
+ } else {
+ // copy address into tmpstr String
+ memset(tmpstr, 0, 200);
+ addr2a(&saddr, tmpstr , tmpstrlen);
+ snprintf(line, sizeof(line), "%s;", tmpstr);
+ tmpstrlen = sizeof(tmpstr);
+ port2a(&saddr, tmpstr, tmpstrlen);
+ }
log_print(3, "Client: %s%s ", line, tmpstr);
strlcat(results, line, results_strlen);
- I2AddrFree(addr);

// get web100 values for the middlebox test result group
for (i = 0; i < 3; i++) {
=======================================
--- /trunk/src/web100clt.c Thu Nov 15 13:34:19 2012
+++ /trunk/src/web100clt.c Tue Apr 9 06:11:48 2013
@@ -19,6 +19,8 @@
#include "clt_tests.h"
#include "strlutils.h"
#include "test_results_clt.h"
+#include <arpa/inet.h>
+#include <assert.h>

extern int h_errno;

@@ -235,6 +237,28 @@
"and switch=Half mismatch condition\n");
}
}
+
+/**
+ * Get a string representation of an ip address.
+ *
+ * @param addr A sockaddr structure which contains the address
+ * @param buf A buffer to fill with the ip address as a string
+ * @param len The length of buf.
+ */
+static void addr2a(struct sockaddr_storage * addr,char * buf, int len){
+ if(((struct sockaddr *)addr)->sa_family == AF_INET){
+ /* IPv4 */
+ inet_ntop(AF_INET, &(((struct sockaddr_in *)addr)->sin_addr),
+ buf, len);
+ }
+#ifdef AF_INET6
+ else if(((struct sockaddr *)addr)->sa_family == AF_INET6 ){
+ /* IPv6 */
+ inet_ntop(AF_INET6, &(((struct sockaddr_in6 *)addr)->sin6_addr),
+ buf, len);
+ }
+#endif
+}

/**
* This routine decodes the middlebox test results. The data is returned
@@ -247,14 +271,14 @@
* Client then adds
* Server IP; Client IP.
* @param midresult_str String containing test results
- * @param local_addr Client IP address
- * @param peer_addr Server IP address
+ * @param cltsock Used to get address information
*/

-void middleboxResults(char *midresult_str, I2Addr local_addr,
- I2Addr peer_addr) {
+void middleboxResults(char *midresult_str, int cltsock) {
char ssip[64], scip[64], *str;
char csip[64], ccip[64];
+ struct sockaddr_storage addr;
+ socklen_t addr_size;
int mss;
size_t tmpLen;

@@ -271,13 +295,26 @@
winssent = atoi(str);
str = strtok(NULL, ";");
winsrecv = atoi(str);
-
+
+ /* Get the our local IP address */
+ addr_size = sizeof(addr);
memset(ccip, 0, 64);
tmpLen = 63;
- I2AddrNodeName(local_addr, ccip, &tmpLen);
+ if (getsockname(cltsock,(struct sockaddr *) &addr, &addr_size) == -1) {
+ perror("Middlebox - getsockname() failed");
+ } else {
+ addr2a(&addr, ccip , tmpLen);
+ }
+
+ /* Get the server IP address */
+ addr_size = sizeof(addr);
memset(csip, 0, 64);
tmpLen = 63;
- I2AddrNodeName(peer_addr, csip, &tmpLen);
+ if (getpeername(cltsock,(struct sockaddr *) &addr, &addr_size) == -1) {
+ perror("Middlebox - getpeername() failed");
+ } else {
+ addr2a(&addr, csip , tmpLen);
+ }

// Check if MSS modification is happening
check_MSS_modification(TimestampsEnabled, &mss);
@@ -486,7 +523,6 @@
int testId; // test ID received from server
// addresses..
I2Addr server_addr = NULL;
- I2Addr local_addr = NULL, remote_addr = NULL;
char* ptr;
#ifdef AF_INET6
#define GETOPT_LONG_INET6(x) "46"x
@@ -853,10 +889,6 @@
strlcat(resultstr, buff, sizeof(resultstr));
log_println(6, "resultstr = '%s'", resultstr);
}
-
- local_addr = I2AddrByLocalSockFD(get_errhandle(), ctlSocket, False);
- remote_addr = I2AddrBySockFD(get_errhandle(), ctlSocket, False);
- I2AddrFree(server_addr);

strlcpy(varstr, resultstr, sizeof(varstr));
// print test results
@@ -864,8 +896,10 @@

// print middlebox test results
if (tests & TEST_MID) {
- middleboxResults(mid_resultstr, local_addr, remote_addr);
+ middleboxResults(mid_resultstr, ctlSocket);
}
+
+ I2AddrFree(server_addr);

// print extra information collected from web100 variables
if ((tests & TEST_S2C) && (msglvl > 1))


  • [ndt-dev] [ndt] r802 committed - Include richard sanger's patch for issue 70, ndt, 04/09/2013

Archive powered by MHonArc 2.6.16.

Top of Page