Commit aebcd6ac authored by Ryan Pasculano's avatar Ryan Pasculano

Merge branch 'master' of gitlab.bucknell.edu:cdf009/csci315

parents cc6be00a c5148af1
......@@ -9,4 +9,6 @@ wrappers.o: wrappers.h wrappers.c
echoreq: echoreq.c wrappers.o
$(CC) $(CLAGS) echoreq.c -o echoreq
echod: echod.c wrappers.o
$(CC) $(CFLAGS) echod.c -o echod
$(CC) $(CFLAGS) echod.c -o echod
echoreq2: echoreq2.c wrappers.o
$(CC) $(CLAGS) echoreq2.c -o echoreq2
/*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>
#include "wrappers.c"
#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);
struct addrinfo hints;
struct addrinfo *result, *rp;
int sfd, s;
struct sockaddr_storage peer_addr;
socklen_t peer_addr_len;
ssize_t nread;
char buf[BUFFER_SIZE];
if (argc != 2) {
fprintf(stderr, "Usage: %s port\n", argv[0]);
exit(EXIT_FAILURE);
}
memset(&hints, 0, sizeof(struct addrinfo));
hints.ai_family = AF_UNSPEC; /* Allow IPv4 or IPv6 */
hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
hints.ai_flags = AI_PASSIVE; /* For wildcard IP address */
hints.ai_protocol = 0; /* Any protocol */
hints.ai_canonname = NULL;
hints.ai_addr = NULL;
hints.ai_next = NULL;
s = getaddrinfo(NULL, argv[1], &hints, &result);
if (s != 0) {
fprintf(stderr, "getaddrinfo: %s\n", gai_strerror(s));
exit(EXIT_FAILURE);
}
/* getaddrinfo() returns a list of address structures.
* Try each address until we successfully bind(2).
* If socket(2) (or bind(2)) fails, we (close the socket
* and) try the next address. */
for (rp = result; rp != NULL; rp = rp->ai_next) {
sfd = socket(rp->ai_family, rp->ai_socktype,
rp->ai_protocol);
if (sfd == -1)
continue;
if (bind(sfd, rp->ai_addr, rp->ai_addrlen) == 0)
break; /* Success */
close(sfd);
}
if (rp == NULL) { /* No address succeeded */
fprintf(stderr, "Could not bind\n");
exit(EXIT_FAILURE);
}
freeaddrinfo(result); /* No longer needed */
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);
}
#
# Copyright (c) 2012 Bucknell University
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation;
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
#
# Author: L. Felipe Perrone (perrone@bucknell.edu)
#
CC = gcc -I ./include
CFLAGS = -std=gnu99 -Wall -g #-DDEBUG
INC = ./include
SRC = ./src
OBJ = ./obj
DOC = ./doc
BIN = ./bin
vpath %.h ./include
vpath %.c ./src
EXECS = prodcons circular-list.o adt-test
all: mkpaths $(EXECS)
mkpaths:
mkdir -p $(OBJ)
doc:
doxygen
$(OBJ)/circular-list.o: $(INC)/circular-list.h $(SRC)/circular-list.c
$(CC) $(CFLAGS) -c $(SRC)/circular-list.c -o $(OBJ)/circular-list.o
$(BIN)/adt-test: $(SRC)/adt-test.c $(OBJ)/circular-list.o
$(CC) $(CFLAGS) $(SRC)/adt-test.c $(OBJ)/circular-list.o -o $(BIN)/adt-test
prodcons: $(OBJ)/circular-list.o
$(CC) $(CFLAGS) $(SRC)/prodcons.c $(OBJ)/circular-list.o -o $(BIN)/prodcons -lpthread
.PHONY: clean
clean:
/bin/rm -rf $(OBJ) $(EXECS) core* *~ ./src/*~ ./obj/* ./doc
#include "circular-list.c"
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
int main(void){
struct circular_list l;
circular_list_create(&l, 10);
//double *v;
//v = (double*)(malloc(sizeof(double)));
circular_list_insert(&l,1);
//printf("%f", &l);
circular_list_insert(&l,2);
//printf("%f", &l);
circular_list_insert(&l,3);
//printf("%f", &l);
circular_list_insert(&l,4);
//printf("%f", &l);
circular_list_insert(&l,5);
//printf("%f", &l);
circular_list_insert(&l,6);
printf("ENTERING LOOP");
int j;
for(j=0; j<l.elems; j++){
printf("%f\n", l.buffer[j]);
}
double *v;
v = (double*)(malloc(sizeof(double)));
circular_list_remove(&l, v);
printf("%f", *v);
// call multiple inserts
// c
// insert 1
// insert 2
// insert 3
// insert 4
// insert 5
// insert 6
// deleting(&l, &v)
// printf("%d")
// delete
}
/*
* Copyright (c) 2013 Bucknell University
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Author: L. Felipe Perrone (perrone@bucknell.edu)
*/
#include <stdlib.h>
#include "circular-list.h"
#include <stdio.h>
#include <unistd.h>
#include <string.h>
int circular_list_create(struct circular_list *l, int size) {
l->buffer = calloc(size, sizeof(item));
l->start = 0;
l->end = 0;
l->elems = 0;
l->size = size;
return 0;
}
int circular_list_insert(struct circular_list *l, item i) {
if(l->elems == l->size ){ //
return -1;
}
else {
//int len = l->size;
l->buffer[l->end] = i;
//l->end += 1;
l->end = (l->end+1) % l->size;
l->elems += 1;
return 0;
}
}
int circular_list_remove(struct circular_list *l, item *i) {
if(l->end == 0){
printf("Empty List!!!");
return -1;
}
// else{
*i = l->buffer[l->start];
//l->start += 1;
l->start = (l->start+1) % l->size;
l->elems -= 1;
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