* [9fans] BSD Sockets
@ 1998-11-15 15:12 Franklin
0 siblings, 0 replies; 2+ messages in thread
From: Franklin @ 1998-11-15 15:12 UTC (permalink / raw)
When I compile the following program I get the following error
messages.
/*
* tcpblast - test and estimate TCP throughput
*
* Daniel Karrenberg <dfk@nic.eu.net>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BLKSIZE 1024
struct sockaddr_in sock_in;
struct servent *sp;
struct hostent *host;
long starts, startms, stops, stopms, expms;
struct timeval ti;
struct timezone tiz;
char greet[BLKSIZE] = "Hi!";
int nblocks;
int f;
int main(argc, argv)
int argc; char **argv;
{
register int i;
if (argc!=3)
{
fprintf(stderr, "usage: tcpblast destination nblkocks\n");
fprintf(stderr, "blocksize: %d bytes\n", BLKSIZE);
exit(1);
}
nblocks = atoi(argv[2]);
if (nblocks<=1 || nblocks>=10000)
{
fprintf(stderr, "tcpblast: 1 < nblocks <= 10000 \n");
exit(1);
}
/*bzero((char *)&sock_in, sizeof (sock_in));*/
sock_in.sin_family = AF_INET;
f = socket(AF_INET, SOCK_STREAM, 0);
if (f < 0) {
perror("tcpblast: socket");
exit(3);
}
if (bind(f, (struct sockaddr*) &sock_in, sizeof (sock_in)) < 0) {
perror("tcpblast: bind");
exit(1);
}
host = gethostbyname(argv[1]);
if (host) {
sock_in.sin_family = host->h_addrtype;
/* bcopy(host->h_addr, &sock_in.sin_addr, host->h_length);*/
} else {
sock_in.sin_family = AF_INET;
sock_in.sin_addr.s_addr = inet_addr(argv[1]);
if (sock_in.sin_addr.s_addr == -1) {
fprintf(stderr, "tcpblast: %s unknown host\n", argv[1]);
exit(1);
}
}
sock_in.sin_port = htons(9);
if (connect(f, (struct sockaddr*) &sock_in, sizeof(sock_in)) <0)
{
perror("tcpblast connect:");
exit(1);
}
if (gettimeofday(&ti, &tiz) < 0)
{
perror("tcpblast time:");
exit(1);
}
/* starts = ti.tv_sec;
startms = ti.tv_usec / 1000L;*/
for (i=0; i<nblocks; i++)
{
/*if (write(f, greet, BLKSIZE) != BLKSIZE)
perror("tcpblast send:");
write(1, ".", 1);*/
}
if (gettimeofday(&ti, &tiz) < 0)
{
perror("tcpblast time:");
exit(1);
}
/* stops = ti.tv_sec;
stopms = ti.tv_usec / 1000L;*/
expms = (stops-starts)*1000 + (stopms-startms);
printf("\n%d KB in %ld msec", nblocks, expms);
printf(" = %.1f kbit/s", (double) (nblocks*BLKSIZE) / expms *
8000.0);
printf(" = %.1f kByte/s", (double) (nblocks*BLKSIZE) / expms * 1000);
printf(" = %.1f MByte/s\n", (double) (nblocks*BLKSIZE) /
(double)(expms*1024.0));
return(0);
}
Error messages:
term% pcc tcpblast.c
_sock_newrock: undefined: memset in _sock_newrock
socket: undefined: pipe in socket
gettimeofday: undefined: time in gettimeofday
connect: undefined: unlink in connect
_sock_srvname: undefined: strrchr in _sock_srvname
inet_ntoa: _ctype: not defined
The functions undefined in the error messages exist in
/sys/src/ape/lib/ap/plan9 (sources in .c).
_sock_newrock is in socket.c and _sock_srvname is in _sock_srv.c.
Socket.c, gettimeofday.c, connect.c, _sock_srv.c and inet_ntoa.c are in
/sys/src/ape/lib/bsd.
Thanks.
Franklin.
^ permalink raw reply [flat|nested] 2+ messages in thread
* [9fans] BSD Sockets
@ 1998-11-15 18:19 forsyth
0 siblings, 0 replies; 2+ messages in thread
From: forsyth @ 1998-11-15 18:19 UTC (permalink / raw)
move
#include <stdio.h>
...
#include <string.h>
above
#include <sys/types.h>
(they can go a bit lower down but that's enough to have the libraries
dealt with in the right order by the #lib system; alternatively enumerate them on the pcc
command line as on a unix system)
you can either include <bsd.h> to get the bzero stuff
or do as i did, and replace bzero by memset and bcopy by memmove, with suitable
changes to the corresponding argument lists.
add
#include <unistd.h>
after <sys/time.h> (say) to get the definition of system calls
include write(). i believe its absence is a bug in the original source.
then uncomment the calls to bzero, bcopy, the use of tv_sec and
tv_usec, not to mention the write that does the work.
i left a comment round the write "." because that will only slow
things down (for what it's worth on a benchmark like this).
pcc gives ANSI C only (see the man page and the APE
document); you'll need -D_POSIX_SOURCE to access
the Posix extensions and -D_BSD_EXTENSION to access
the BSD ones including sockets and associated sin:
pcc -D_POSIX_SOURCE -D_BSD_EXTENSION tcpblast.c
compiles it. if it hangs during the connect() it (probably) means you
haven't applied all the APE boddles required to swizzle things
consistently on a little-endian machine.
here's one i prepared earlier.
/*
* tcpblast - test and estimate TCP throughput
*
* Daniel Karrenberg <dfk@nic.eu.net>
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <time.h>
#include <sys/time.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#define BLKSIZE 1024
struct sockaddr_in sock_in;
struct servent *sp;
struct hostent *host;
long starts, startms, stops, stopms, expms;
struct timeval ti;
struct timezone tiz;
char greet[BLKSIZE] = "Hi!";
int nblocks;
int f;
int main(argc, argv)
int argc; char **argv;
{
register int i;
if (argc!=3)
{
fprintf(stderr, "usage: tcpblast destination nblkocks\n");
fprintf(stderr, "blocksize: %d bytes\n", BLKSIZE);
exit(1);
}
nblocks = atoi(argv[2]);
if (nblocks<=1 || nblocks>=10000)
{
fprintf(stderr, "tcpblast: 1 < nblocks <= 10000 \n");
exit(1);
}
memset(&sock_in, 0, sizeof (sock_in));
sock_in.sin_family = AF_INET;
f = socket(AF_INET, SOCK_STREAM, 0);
if (f < 0) {
perror("tcpblast: socket");
exit(3);
}
if (bind(f, (struct sockaddr*) &sock_in, sizeof (sock_in)) < 0) {
perror("tcpblast: bind");
exit(1);
}
host = gethostbyname(argv[1]);
if (host) {
sock_in.sin_family = host->h_addrtype;
memmove(&sock_in.sin_addr, host->h_addr, host->h_length);
} else {
sock_in.sin_family = AF_INET;
sock_in.sin_addr.s_addr = inet_addr(argv[1]);
if (sock_in.sin_addr.s_addr == -1) {
fprintf(stderr, "tcpblast: %s unknown host\n", argv[1]);
exit(1);
}
}
sock_in.sin_port = htons(9);
if (connect(f, (struct sockaddr*) &sock_in, sizeof(sock_in)) <0)
{
perror("tcpblast connect:");
exit(1);
}
if (gettimeofday(&ti, &tiz) < 0)
{
perror("tcpblast time:");
exit(1);
}
starts = ti.tv_sec;
startms = ti.tv_usec / 1000L;
for (i=0; i<nblocks; i++)
{
if (write(f, greet, BLKSIZE) != BLKSIZE)
perror("tcpblast send:");
/*write(1, ".", 1);*/
}
if (gettimeofday(&ti, &tiz) < 0)
{
perror("tcpblast time:");
exit(1);
}
stops = ti.tv_sec;
stopms = ti.tv_usec / 1000L;
expms = (stops-starts)*1000 + (stopms-startms);
printf("\n%d KB in %ld msec", nblocks, expms);
printf(" = %.1f kbit/s", (double) (nblocks*BLKSIZE) / expms *
8000.0);
printf(" = %.1f kByte/s", (double) (nblocks*BLKSIZE) / expms * 1000);
printf(" = %.1f MByte/s\n", (double) (nblocks*BLKSIZE) /
(double)(expms*1024.0));
return(0);
}
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~1998-11-15 18:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-11-15 15:12 [9fans] BSD Sockets Franklin
1998-11-15 18:19 forsyth
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).