diff -r 5a3b443728a3 src/iperf.h
--- a/src/iperf.h	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/iperf.h	Tue Jan 07 13:00:38 2014 +0530
@@ -15,6 +15,12 @@
 #include <stdint.h>
 #include <sys/socket.h>
 #include <netinet/tcp.h>
+
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#endif
+
 #include "timer.h"
 #include "queue.h"
 #include "cjson.h"
@@ -161,6 +167,9 @@
     int       duration;                         /* total duration of test (-t flag) */
     char     *diskfile_name;			/* -F option */
     int       affinity, server_affinity;	/* -A option */
+#if (__FreeBSD__)
+    cpuset_t cpumask;
+#endif
     char     *title;				/* -T option */
     char     *congestion;			/* -C option */
 
diff -r 5a3b443728a3 src/iperf_api.c
--- a/src/iperf_api.c	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/iperf_api.c	Tue Jan 07 13:00:38 2014 +0530
@@ -35,6 +35,11 @@
 #include <setjmp.h>
 #include <stdarg.h>
 
+#if defined(__FreeBSD__)
+#include <sys/param.h>
+#include <sys/cpuset.h>
+#endif
+
 #include "net.h"
 #include "iperf.h"
 #include "iperf_api.h"
@@ -531,7 +536,9 @@
         {"zerocopy", no_argument, NULL, 'Z'},
         {"omit", required_argument, NULL, 'O'},
         {"file", required_argument, NULL, 'F'},
+#if defined(linux) || defined(__FreeBSD__)
         {"affinity", required_argument, NULL, 'A'},
+#endif
         {"title", required_argument, NULL, 'T'},
 #if defined(linux)
         {"linux-congestion", required_argument, NULL, 'C'},
@@ -713,6 +720,7 @@
                 test->diskfile_name = optarg;
                 break;
             case 'A':
+#if defined(linux) || defined(__FreeBSD__)
                 test->affinity = atoi(optarg);
                 if (test->affinity < 0 || test->affinity > 1024) {
                     i_errno = IEAFFINITY;
@@ -727,6 +735,10 @@
 		    }
 		    client_flag = 1;
 		}
+#else 
+                i_errno = IEUNIMP;
+                return -1;
+#endif 
                 break;
             case 'T':
                 test->title = malloc(strlen(optarg) + 4);
@@ -1457,6 +1469,9 @@
     testp->diskfile_name = (char*) 0;
     testp->affinity = -1;
     testp->server_affinity = -1;
+#if defined(__FreeBSD__)
+    CPU_ZERO(&testp->cpumask);
+#endif
     testp->title = NULL;
     testp->congestion = NULL;
     testp->server_port = PORT;
@@ -1614,6 +1629,9 @@
     test->omit = OMIT;
     test->duration = DURATION;
     test->server_affinity = -1;
+#if defined(__FreeBSD__)
+    CPU_ZERO(&test->cpumask);
+#endif
     test->state = 0;
 
     if(test->title) {
@@ -2373,7 +2391,7 @@
 /* CPU affinity stuff - linux only. */
 
 int
-iperf_setaffinity(int affinity)
+iperf_setaffinity(struct iperf_test *test, int affinity)
 {
 #ifdef linux
     cpu_set_t cpu_set;
@@ -2385,6 +2403,29 @@
         return -1;
     }
     return 0;
+#elif (__FreeBSD__)
+    int i;
+    cpuset_t cpumask;
+
+    if(cpuset_getaffinity(CPU_LEVEL_WHICH, CPU_WHICH_PID, -1,
+                          sizeof(cpuset_t), &test->cpumask) != 0) {
+        i_errno = IEAFFINITY;
+        return -1;
+    }
+
+    CPU_ZERO(&cpumask);
+    for (i=0; i<32; i++) {
+        if (test->affinity & (1 << i)) {
+            CPU_SET(i, &cpumask);
+        }
+    }
+
+    if(cpuset_setaffinity(CPU_LEVEL_WHICH,CPU_WHICH_PID, -1,
+                          sizeof(cpuset_t), &cpumask) != 0) {
+        i_errno = IEAFFINITY;
+        return -1;
+    }
+    return 0;
 #else /*linux*/
     i_errno = IEAFFINITY;
     return -1;
@@ -2392,7 +2433,7 @@
 }
 
 int
-iperf_clearaffinity(void)
+iperf_clearaffinity(struct iperf_test *test)
 {
 #ifdef linux
     cpu_set_t cpu_set;
@@ -2406,6 +2447,13 @@
         return -1;
     }
     return 0;
+#elif (__FreeBSD__)
+    if(cpuset_setaffinity(CPU_LEVEL_WHICH,CPU_WHICH_PID, -1,
+                          sizeof(cpuset_t), &test->cpumask) != 0) {
+        i_errno = IEAFFINITY;
+        return -1;
+    }
+    return 0;
 #else /*linux*/
     i_errno = IEAFFINITY;
     return -1;
diff -r 5a3b443728a3 src/iperf_api.h
--- a/src/iperf_api.h	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/iperf_api.h	Tue Jan 07 13:00:38 2014 +0530
@@ -213,8 +213,8 @@
 int iperf_json_finish(struct iperf_test *);
 
 /* CPU affinity routines */
-int iperf_setaffinity(int affinity);
-int iperf_clearaffinity(void);
+int iperf_setaffinity(struct iperf_test *, int affinity);
+int iperf_clearaffinity(struct iperf_test *);
 
 /* Custom printf routine. */
 int iprintf(struct iperf_test *test, const char *format, ...) __attribute__ ((format(printf,2,3)));
diff -r 5a3b443728a3 src/iperf_client_api.c
--- a/src/iperf_client_api.c	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/iperf_client_api.c	Tue Jan 07 13:00:38 2014 +0530
@@ -332,7 +332,7 @@
 	iperf_got_sigend(test);
 
     if (test->affinity != -1)
-	if (iperf_setaffinity(test->affinity) != 0)
+	if (iperf_setaffinity(test, test->affinity) != 0)
 	    return -1;
 
     if (test->json_output)
diff -r 5a3b443728a3 src/iperf_server_api.c
--- a/src/iperf_server_api.c	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/iperf_server_api.c	Tue Jan 07 13:00:38 2014 +0530
@@ -136,7 +136,7 @@
         if (iperf_exchange_parameters(test) < 0)
             return -1;
 	if (test->server_affinity != -1) 
-	    if (iperf_setaffinity(test->server_affinity) != 0)
+	    if (iperf_setaffinity(test, test->server_affinity) != 0)
 		return -1;
         if (test->on_connect)
             test->on_connect(test);
@@ -428,7 +428,7 @@
 	iperf_got_sigend(test);
 
     if (test->affinity != -1) 
-	if (iperf_setaffinity(test->affinity) != 0)
+	if (iperf_setaffinity(test, test->affinity) != 0)
 	    return -1;
 
     if (test->json_output)
@@ -595,7 +595,7 @@
     } 
 
     if (test->server_affinity != -1) 
-	if (iperf_clearaffinity() != 0)
+	if (iperf_clearaffinity(test) != 0)
 	    return -1;
 
     return 0;
diff -r 5a3b443728a3 src/locale.c
--- a/src/locale.c	Mon Jan 06 12:18:21 2014 -0800
+++ b/src/locale.c	Tue Jan 07 13:00:38 2014 +0530
@@ -73,7 +73,9 @@
                            "  -f, --format    [kmgKMG]  format to report: Kbits, Mbits, KBytes, MBytes\n"
                            "  -i, --interval  #         seconds between periodic bandwidth reports\n"
                            "  -F, --file name           xmit/recv the specified file\n"
+#if defined(linux) || defined(__FreeBSD__)
                            "  -A, --affinity n/n,m      set CPU affinity\n"
+#endif
                            "  -V, --verbose             more detailed output\n"
                            "  -J, --json                output in JSON format\n"
                            "  -v, --version             show version information and quit\n"
