This is EthernetSpeed.m in view mode; [Download] [Up]
#import "EthernetSpeed.h" #import <appkit/appkit.h> #import <sys/types.h> #import <sys/socket.h> #import <sys/ioctl.h> #import <sys/time.h> #import <netinet/in.h> #define TELOPTS #import <arpa/telnet.h> #import <arpa/inet.h> #import <stdio.h> #import <ctype.h> #import <errno.h> #import <signal.h> #import <setjmp.h> #import <netdb.h> #import <strings.h> #import <libc.h> @implementation EthernetSpeed #define XFER 1024 - benchmark { struct hostent *host = 0; struct sockaddr_in sin; struct servent *sp; int tcpfd=0; int connected=0; char buf[8192]; int i; char *hostname = (char *)[hostCell stringValue]; sp = getservbyname("discard", "tcp"); host = gethostbyname(hostname); if (host) { sin.sin_family = host->h_addrtype; memcpy(&sin.sin_addr, host->h_addr_list[0], host->h_length); } else{ sin.sin_addr.s_addr = inet_addr((char *)hostname); if (sin.sin_addr.s_addr == -1) { printf("%s: unknown host\n", hostname); return self; } sin.sin_family = AF_INET; } sin.sin_port = sp->s_port; /* try all addresses for connections */ while(connected==0){ tcpfd = socket(AF_INET, SOCK_STREAM, 0); if (tcpfd < 0) { perror("telnet: socket"); return 0; } if (connect(tcpfd, (struct sockaddr *)&sin, sizeof (sin)) < 0){ if (host && host->h_addr_list[1]) { printf("connect to address %s: %s", inet_ntoa(sin.sin_addr), strerror(errno)); host->h_addr_list++; memcpy(&sin.sin_addr, host->h_addr_list[0], host->h_length); printf("Trying %s...\n", inet_ntoa(sin.sin_addr)); close(tcpfd); continue; } perror("connect"); return 0; } connected = 1; } /* at this point, anything written to tcpfd will get sent, and * anything read from tcpfd will be from the network... */ for(i=0;i<XFER;i++){ write(tcpfd,buf,sizeof(buf)); } close(tcpfd); return self; } -shutdownBenchmark { double mpersec = XFER * 8192 / (1024*1024 * wallTime); char buf[256]; [ethCell setDoubleValue:mpersec]; sprintf(buf,"Ethernet speed: %g",mpersec); [self logResults:buf]; return self; } @end
These are the contents of the former NiCE NeXT User Group NeXTSTEP/OpenStep software archive, currently hosted by Netfuture.ch.