Commit cc6be00a authored by Ryan Pasculano's avatar Ryan Pasculano

why wont this work

parents 157018e7 3a45f2c7
Lab 0 feedback
Problem 1: 40/40
Make works correctly: 15/15
Clean works correctly: 15/15
dlisttest.c is compiled and dlisttest is created correctly: 5/5
variables in the skeleton are used: 5/5
Problem 2: 30/30
dlist_add_front: using the dnode functions to create node: 5/5
checking for empty list: 5/5
dlist_add_back: using dnode functions to create node: 5/5
checking for empty list: 5/5
dlist_remove_front implementation: 5/5
memory leak: 5/5
no memory leaks, be sure to check for them because I
will take off points in future labs
Total: 70/70
Lab 1 feedback
Prelab 1 (cmds.c): 10/10
Prelab 2 (cmdsreverse.c): 10/10
Prelab 3 (myprog.c): 10/10
Problem 0: 5/5
Makefile makes all executables without errors: 5/5
Problem 1: 19/20
Parent and child print pid: 5/5
Answer to 1b in answer.txt: 5/5
fork-wait.c executes in proper order: 5/5
child process calls get(p)pid: 4/5
-1: getpid() and getppid() return the pid of the part and the parent's parent. So for your fork-wait.c file when it says it is printing the childpid it is really printing its parents id. The childs pid should be 0.
Problem 2 25/25
Answer to 2a in answers.txt: 4/4
Answer to 2b in answers.txt: 5/5
fork-file.c executes properly: 6/6
Answer to 2d in answers.txt: 6/6
Fork(void) in fork-file.c and used: 4/4
Problem 3 20/20
catcount.c works as specified: 10/10
print_environment works as specified: 10/10
Total: 99/100
Lab 2 feedback
Prelab 1 (heap-test.c): 15/15
Prelab 2 (pipe-test.c): 15/15
Problem 1: 29/30
Using the Fork wrapper and writing the three additional ones: 9/10
-1: Didn't use Fork
Implementing the correct functionality for sending and receiving
messages byte-by-byte over the pipe: 20/20
Problem 2 17/20
Using the wrappers defined previously: 4/5
-1: Didn't use Fork
Implementing the correct functionality for sending and
receiving messages byte-by-byte over the pipe: 3/5
-2: There is some garbage being printed out
Using the child process to do the case conversion: 10/10
Problem 3 19/20
Using the wrappers defined previously: 4/5
-1: Didn't use Fork
Implementing the correct functionality for sending and receiving
messages between processes according the required protocol: 5/5
Implementing the correct functionality for tokenizing and rebuilding strings: 10/10
Total: 95/100
Lab 3 feedback
Prelab 1 (char-threads.c): 20/20
runs correctly: 10/10
answered questions: 10/10
Prelab 2 (mytime.c): 10/10
Problem 1: 15/15
correct answers to questions: 15/15
Problem 2 20/20
correct answers to questions: 20/20
Problem 3 15/15
two calls to gettimeofday: 10/10
proper subtraction of timeval structs: 5/5
Problem 4: 20/20
each thread computes run time: 10/10
correct answers to questions: 10/10
Total: 100/100
1)If no calls were made to fork in either of the programs you have, why is it that we’re claiming that TCP sockets are a mechanism for interprocess communication?
We consider this an interprocess communication because a TCP socket interconnects two processes that execute on arbitrary machines. The processes can execute on either the same host or networked hosts. The fork is not needs beceuase the processes can be run on differtent machines as long as theyre networked together. This is why we use the host and the port number.
2) Is the socket functionality provided by the kernel or by an external library? Present an argument to justify your answer from the perspectives of the actual implementation on Linux and from the perspective of the design decisions made for the construction of the operating system (think about the implications of these decisions on the performance of a modern networked computer). You should think about what makes sense, do a little research to verify whether you are on the right track, reason about your findings, and only then write your conclusions.
I would believe that the socket functionality is provided by the kernal. I believe this because the host is unique to your network and computer. The connection of sockets in this cases also uses many syscalls working together to make connections and finsh the task. In this case, we use send/recieve so that messages can be sent accross the connection. We also use connect and bind to solidfy and create connections. These are all operations that are done by the kernel and not a external library.
3) Only when you consider a program’s communications needs and the operational constraints around a program can you choose which of the two IPC mechanisms is most appropriate. Describe what drives you decision to use either pipes and sockets to interconnect two processes.
I personally think sockets are much more useful to interconnect the two processes. Sockets give you much more freedom to connect with other computers and other ports. The sockets use syscalls to be set up and maintained. While pipes are also useful, they are unidirectional and require many more compoenents to get the job done.
4)echoreq makes a call to gethostbyname(3). Explain what this library call does for your program and how you use its API.
This function call will call the host and return the host structure. This is useful for our program because you are required to provide the host in order to make the connection between the two functions. Therefore, the host has to match up for any connection and data to be passed accross.
5)gethostbyname(3) is not the most up-to-date function for its kind of task (it is deprecated). Discover what function might eventually replace gethostbyname(3) and explain how differently it might work.
I would use gethostbyaddr as it returns much much more data to work with and make connections with. It works differently in that it provides us with different return data. This is all because it is very descriptive when it takes in the attributes. It wants the addr, len and type. Therefore, you are able to be much more specific with the host.
/*
* CSCI 315 Operating Systems Design
* Author: L. Felipe Perrone
* Date: 2010-02-16
* Copyright (c) 2011 Bucknell University
*
* Permission is hereby granted, free of charge, to any individual
* or institution obtaining a copy of this software and associated
* documentation files (the "Software"), to use, copy, modify, and
* distribute without restriction, provided that this copyright
* and permission notice is maintained, intact, in all copies and
* supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL BUCKNELL UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/uio.h>
#include <unistd.h>
#include <netinet/in.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define BUFFER_SIZE 512 // length of message buffer
#define QLEN 6 // length of request queue
#define FOREVER 1
#define TRUE 1
#define FALSE 0
int num_requests = 0; // tally of client requests
/*------------------------------------------------------------------------
* Program: echod - a server for echo requests
*
* Purpose: repeatedly execute the following:
* (0) wait for a connection request from client
* (1) wait for a null-terminated string from client
* (2) send back the same string to client
* (3) close the connection
* (4) go back to step (0)
*
* Usage: echod [ port ]
*
* port - a port number in user space
*
*------------------------------------------------------------------------
*/
int
main (int argc, char* argv[]) {
struct sockaddr_in sad; // structure to hold server's address
struct sockaddr_in cad; // structure to hold client's address
int sd, sd2; // socket descriptors
int port; // protocol port number
socklen_t alen; // length of address
char in_msg[BUFFER_SIZE]; // buffer for incoming message
// prepare address data structure
// The memset call is ESSENTIAL!
// if you don't do this every time you create a sockaddr struct, you will
// see some pretty strange behaviour
memset((char *)&sad,0,sizeof(sad)); // zero out sockaddr structure
sad.sin_family = AF_INET; // set family to Internet
sad.sin_addr.s_addr = INADDR_ANY; // set the local IP address
// verify usage
if (argc > 1) {
port = atoi(argv[1]);
}
else {
printf("Usage: %s [ port ]\n", argv[0]);
exit(-1);
}
if (port > 0)
// test for illegal value
sad.sin_port = htons((u_short)port);
else {
// print error message and exit
fprintf(stderr,"ECHOD: bad port number %s\n", argv[1]);
exit(-1);
}
// create socket
sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sd < 0) {
perror("ECHOD: socket creation failed");
exit(-1);
}
// assign IP/port number to socket where connections come in
if (bind(sd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
perror("ECHOD: bind failed");
exit(-1);
}
// set up socket to receive incomming connections
if (listen(sd, QLEN) < 0) {
perror("ECHOD: listen failed");
exit(-1);
}
// main server loop - accept and handle requests
while (FOREVER) {
alen = sizeof(cad);
if ( (sd2 = accept(sd, (struct sockaddr *)&cad, &alen)) < 0) {
perror("ECHOD: accept failed\n");
exit(-1);
}
num_requests++;
// receive the string sent by client
strcpy(in_msg, "");
recv(sd2, &in_msg, BUFFER_SIZE, 0);
printf("done");
// send the received string back to client
//send(sd, buf, len flags);
send(sd2, &in_msg, BUFFER_SIZE, 0);
close(sd2);
}
}
/*CSCI 315 Operating Systems Design
* Author: L. Felipe Perrone
* Date: 2014-09-21
* Copyright (c) 2014 Bucknell University
*
* Permission is hereby granted, free of charge, to any individual
* or institution obtaining a copy of this software and associated
* documentation files (the "Software"), to use, copy, modify, and
* distribute without restriction, provided that this copyright
* and permission notice is maintained, intact, in all copies and
* supporting documentation.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL BUCKNELL UNIVERSITY BE LIABLE FOR ANY CLAIM, DAMAGES
* OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
* OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#define BUFFER_SIZE 512
#define TRUE 1
#define FALSE 0
/*------------------------------------------------------------------------
* Program: echoreq
*
* Purpose: allocate a socket, connect to a server, transfer requested
* file to local host, and print file contents to stdout
*
* Usage: echoreq [ host ] [ port ] [ string ]
*
* host - name of a computer on which server is executing
* port - protocol port number server is using
* string - a string in double quotes
*
*------------------------------------------------------------------------
*/
int
main(int argc, char* argv[]) {
struct hostent *ptrh; // pointer to a host table entry
struct sockaddr_in sad; // structure to hold an IP address
int sd; // socket descriptor
int port; // protocol port number
char *host; // pointer to host name
char in_msg[BUFFER_SIZE]; // buffer for incoming message
int ret_val;
sad.sin_family = AF_INET; // set family to Internet
// verify usage
if (argc < 4) {
printf("Usage: %s [ host ] [ port ] [ string ]\n", argv[0]);
exit(-1);
}
host = argv[1];
port = atoi(argv[2]);
if (port > 0)
// test for legal value
sad.sin_port = htons((u_short)port);
else {
// print error message and exit
printf("ECHOREQ: bad port number %s\n", argv[2]);
exit(-1);
}
// convert host name to equivalent IP address and copy to sad
ptrh = gethostbyname(host);
if ( ((char *)ptrh) == NULL ) {
printf("ECHOREQ: invalid host: %s\n", host);
exit(-1);
}
memcpy(&sad.sin_addr, ptrh->h_addr, ptrh->h_length);
// create socket
sd = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
if (sd < 0) {
printf("ECHOREQ: socket creation failed\n");
exit(-1);
}
// connect the socket to the specified server
if (connect(sd, (struct sockaddr *)&sad, sizeof(sad)) < 0) {
perror("ECHOREQ: connect failed");
exit(-1);
}
// send message to server
char write_msg[BUFFER_SIZE];
strcpy(write_msg, argv[3]);
send(sd, &write_msg, BUFFER_SIZE, 0);
printf("sent");
// send the received string back to client
printf("\n");
// //send(sd, buf, len flags);
strcpy(in_msg, "");
recv(sd, &in_msg, BUFFER_SIZE, 0);
//
// receive message echoed back by server
printf("ECHOREQ: from server= %s\n", in_msg);
// close the socket
close(sd);
// terminate the client program gracefully
return(0);
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment