11 is either w or ps).
12 */
13
14
15 /* these are needed for socket calls */
16 #include <stdio.h>
17 #include <sys/types.h>
18 #include <sys/socket.h>
19 #include <netinet/in.h>
20 #include <netdb.h>
21
22
23 #define WPSPORT 2000 /* server port number */
24 #define BUFSIZE 1000
25
26
27 main(argc,argv)
28 int argc; char **argv;
29
30 { int SD,MsgSize;
31 struct sockaddr_in Addr;
32 struct hostent *HostPtr,*gethostbyname();
33 char Buf[BUFSIZE];
34
35 /* open a socket */
36 SD = socket(AF_INET,SOCK_STREAM,0);
40
41 /* set up for an Internet connection to the host whose
42 name was specified by the user on the command line */
43 Addr.sin_family = AF_INET;
44 Addr.sin_port = WPSPORT;
45 /* get IP address of host */
46 HostPtr = gethostbyname(argv[1]);
47 memcpy(&Addr.sin_addr.s_addr,
48 HostPtr->h_addr_list[0],HostPtr->h_length);
49
50 /* OK, now connect */
51 connect(SD,&Addr,sizeof(Addr));
55
56 /* send user command */
57 write(SD,argv[2],strlen(argv[2]));
58
59 /* display response */
60 MsgSize = read(SD,Buf,BUFSIZE);
14
61 write(1,Buf,MsgSize);
62 }
63
1 /* WPsServer.c */
2
3 /* A server for remote versions of the w and ps
4 commands.
5
6 User can check load on machine without logging
7 in (or even without being able to log in).
8 */
9
10
11 /* these are needed for socket calls */
12 #include <stdio.h>
13 #include <sys/types.h>
14 #include <sys/socket.h>
15 #include <netinet/in.h>
Overview of Computer Networks
Start from the beginning
