Example #1
0
	void compile_error(lua_State * L, int status)
	{
		if(status == 0)
			return; // No errors.

		// This is the human readable error message.
		const char * msg = lua_tostring(L, -1);

		std::stringstream ss;
		
		switch (status)
		{
		case LUA_ERRMEM:
			ss << "Memory allocation error: " << msg << std::endl;
			syserr(ss.str().c_str());
			break;
		case LUA_ERRSYNTAX:
			ss << "Syntax error: " << msg << std::endl;
			syserr(ss.str().c_str());
			break;
		}

		// Remove error message.
		lua_pop(L, 1);
	}
Example #2
0
void servSide(int newsockfd, char* buffer)
{
	int n, size, tempfd;
   struct stat filestats;
	char * filename;
	filename = malloc(sizeof(char)*BUFFSIZE);
	
	//Receive file name
   memset(buffer, 0, BUFFSIZE);
	n = recv(newsockfd, buffer, BUFFSIZE, 0);
	if(n < 0) syserr("can't receive filename from peer");
	sscanf(buffer, "%s", filename);
	printf("filename peer wants to download is: %s\n", filename);
	
	//Send file size and file to peer
	stat(filename, &filestats);
	size = filestats.st_size;
	printf("Size of file to send: %d\n", size);
   size = htonl(size);      
	n = send(newsockfd, &size, sizeof(int), 0);
   if(n < 0) syserr("couldn't send size to peer");
   
	tempfd = open(filename, O_RDONLY);
	if(tempfd < 0) syserr("failed to open file");
	sendall(tempfd, newsockfd, buffer);
	close(tempfd);
	
	//Close the connection to peer	
	printf("Connection to peer shutting down\n");
	int status = 1;
	status = htonl(status);
	n = send(newsockfd, &status, sizeof(int), 0);
   if(n < 0) syserr("didn't send exit signal to client");
}
Example #3
0
int main ()
{
  pid_t pid;
  
   /* wypisuje identyfikator procesu */
  printf("Moj PID = %d\n", getpid());

   /* tworzy nowy proces */
  switch (pid = fork()) {
    case -1: /* blad */
      syserr("Error in fork\n");

    case 0: /* proces potomny */
 
      printf("Jestem procesem potomnym. Moj PID = %d\n", getpid());
      printf("Jestem procesem potomnym. Wartosc przekazana przez fork() =\
 %d\n", pid);
      
      return 0;
    
    default: /* proces macierzysty */

      printf("Jestem procesem macierzystym. Moj PID = %d\n", getpid());
      printf("Jestem procesem macierzystym. Wartosc przekazana przez fork() =\
 %d\n", pid);
       
       /* czeka na zakonczenie procesu potomnego */

      if (wait(0) == -1) 
	syserr("Error in wait\n");

      return 0;
  } /*switch*/
}
Example #4
0
// do_transcation: send a request to the server and get a response back
char * do_transcation(char * msg)
{
    static char buf[MSGLEN];
    struct sockaddr retaddr;
    socklen_t addrlen = sizeof(retaddr);
    int ret;

    // printf("before sendto msg %s\n", msg);
    ret = sendto(sd, msg, strlen(msg), 0, &serv_addr, serv_alen);
    // printf("after sendto ret %d\n", ret);
    if (ret == -1)
    {
        syserr("sendto");
        return(NULL);
    }

    // printf("before recvfrom\n");
    ret = recvfrom(sd, buf, MSGLEN, 0, &retaddr, &addrlen);
    // printf("after recvfrom ret %d\n", ret);
    if (ret == -1)
    {
        syserr("recvfrom");
        return(NULL);
    }

    return(buf);
}
Example #5
0
void pascal(int id, int left[2], int right[2]) {
	uint64_t value = 0;

	assert(id == 0);
	assert(left == NULL);

	for(int i = 1; i < n; ++i)
		if(-1 == write(right[1], &value, sizeof(value)))
			syserr("Pascal: Unable to write");

	if(-1 == close(right[1]))
		syserr("Pascal: Unable to close");

	for(int i = 0; i < n; ++i)
		switch(read(right[0], &value, sizeof(value))) {
			case -1:
				syserr("Pascal: Unable to read");
			case 0:
				fatal("Pascal: Unexpected end of pipe");
			default:
				printf("%" PRIu64 " ", value);
		}

	putchar('\n');

	if(-1 == close(right[0]))
		syserr("Pascal: Unable to close");
}
Example #6
0
static int
compare(tparser *p, thandler *handler, void *userdata, GArray *offsets,
	char *cleanname, char *dataname, long *error_position,
	cmdline *cmdline)
{
	FILE *clean, *data;
	int rc;
	long pos;

	if ( !(clean = fopen(cleanname, "r+"))) syserr();
	if ( !(data = fopen(dataname, "r"))) syserr();
	rc = compare_streams(p, handler, userdata, offsets, clean, data, &pos,
			     error_position);
	if (fclose(clean) == EOF) syserr();
	if (fclose(data) == EOF) syserr();

	if (rc == -2) {
		/* an error has happened */
		int n;

		if (!cmdline) {
			fputs("oops: unexpected error in handler\n", stderr);
			exit(1);
		}

		/* remove already-processed entries from the data file */
		cut_datafile(dataname, pos, cmdline);

		/* flag already-processed entries in the offset table */
		for (n = 0; n < offsets->len; n++)
			if (g_array_index(offsets, long, n) < 0)
				g_array_index(offsets, long, n) = -1;
	}
Example #7
0
File: sigproc.c Project: ertesh/SO
int main ()
{
  register int i;

  if (setpgrp() == -1)  /*ustalenie nowej grupy*/
    syserr("setpgrp");

  for (i = 0; i < 10; i++)
    switch (fork()) {
      case -1:
        syserr("fork");
      case 0: /*proces potomny*/
        if (i & 1)
	  if (setpgrp() == -1)
	    syserr("setpgrp2");
        printf("pid = %d pgrp = %d\n", getpid(), getpgrp());
        if (i & 1)
	  sleep(15);
	else
	  pause();
	return 0;
    }

  sleep(5); /*dajmy czas procesom potomnym na rozpoczecie dzialania*/
  if (kill(0, SIGINT) == -1)
    syserr("kill");
  return 0;
}  /*main*/
Example #8
0
/*Reassembles the original input and gives it to system */
void call(char** args, int wait) {
	pid_t pid;            // process ID
   	//int rc;               // return code

   	pid = getpid();       // get our own pid
   	printf("Process ID before fork: %d\n", (int)pid);

   	switch (pid = fork()) {
      	case -1:
         	syserr("fork");
         	break;
      	case 0:             // execution in child process
         	printf("Process ID in child after fork: %d\n", pid);
         	execvp(args[0], args);
         	syserr("execl"); // error if return from exec
            break;
         default:
            if (wait) {
               /* Parent waits for child process, with no status info returned */
               waitpid(pid, NULL, WUNTRACED);
            }
   	}

// continued execution in parent process

   pid = getpid();        // reget our pid
   printf("Process ID in parent after fork: %d\n", pid);
}
Example #9
0
/*
**  APPQUAL -- append qualification to tree
**
**	The qualification is conjoined to the qualificaion of the
**	tree which is passed.
**
**	Parameters:
**		qual -- a pointer to the qualification to be appended.
**		root -- a pointer to the tree to be appended to.
**
**	Returns:
**		none
**
**	Side Effects:
**		Both 'qual' ad 'root' may be modified.  Note that
**			'qual' is linked into 'root', and must be
**			retained.
**
**	Trace Flags:
**		13
*/
void
appqual(qtree_t *qual, qtree_t *root)
{
	register qtree_t	*p;
	register qtree_t	*r;

	r = root;
#ifdef xQTR3
	if (r == NULL)
		syserr("appqual: NULL root");
#endif

	/*
	**  Find node before QLEND node
	**	p points the node we are examining, r points to
	**	it's parent.
	*/

	while ((p = r->right) != NULL && p->sym.type != QLEND) {
#ifdef xQTR3
		if (p->sym.type != AND)
			syserr("appqual: node %d", p->sym.type);
#endif
		r = p;
	}
	
	/* link in qualification */
	r->right = qual;
}
static int
wl_get_dev_type(char *name, void *buf, int len)
{
    int s;
    int ret;
    struct ifreq ifr;
    struct ethtool_drvinfo info;

    /* open socket to kernel */
    if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
        syserr("socket");

    /* get device type */
    memset(&info, 0, sizeof(info));
    info.cmd = ETHTOOL_GDRVINFO;
    ifr.ifr_data = (caddr_t)&info;
    strncpy(ifr.ifr_name, name, IFNAMSIZ);
    if ((ret = ioctl(s, SIOCETHTOOL, &ifr)) < 0) {

        /* print a good diagnostic if not superuser */
        if (errno == EPERM)
            syserr("wl_get_dev_type");

        *(char *)buf = '\0';
    } else {
        strncpy(buf, info.driver, len);
    }

    close(s);
    return ret;
}
Example #11
0
FET *readfetfile(char *file)
{
   FILE *fp;
   FET *fet;
   char c,buf[MAXFETLENGTH];

   if ((fp = fopen(file,"rb")) == (FILE *)NULL)
      syserr("readfetfile","fopen",file);

   fet = allocfet(MAXFETS);
   while (fscanf(fp,"%s",buf) != EOF){
      while(((c = getc(fp)) == ' ') || (c == '\t'));
      ungetc(c, fp);
      if (fet->num >= fet->alloc)
         reallocfet(fet, fet->alloc + MAXFETS);
      fet->names[fet->num] = strdup(buf);
      if(fet->names[fet->num] == (char *)NULL)
         syserr("readfetfile","strdup","fet->names[]");
      fgets(buf,MAXFETLENGTH-1,fp);
      buf[strlen(buf)-1] = '\0';
      fet->values[fet->num] = (char *)strdup(buf);
      if(fet->values[fet->num] == (char *)NULL)
         syserr("readfetfile","strdup","fet->values[]");
      (fet->num)++;
   }
   fclose(fp);
   return(fet);
}
Example #12
0
File: manager.c Project: ertesh/SO
void make_loop(int n, int* last_pipe, char* grammar) {
    /* last_pipe[0] = input of the recently created pipe    *
     * last_pipe[1] = output of the first pipe              */
	pid_t pid;
	if (n == 1) {
		prepare_input(last_pipe);
        prepare_output(last_pipe);
        close_pipe(last_pipe);
        return;
	}
	int next_pipe[2];
    create_pipe(next_pipe);
	switch (pid = fork()) {
		case -1:
			syserr("Error in fork()\n");
		case 0:
			prepare_input(last_pipe);
            close_pipe(last_pipe);
            prepare_output(next_pipe);
            close_pipe(next_pipe);
			execl("./worker", "./worker", grammar, NULL);
			syserr("Error in execl()\n");
		default:
            last_pipe[0] = next_pipe[0];
            make_loop(n - 1, last_pipe, grammar);
            return;
	}
}
Example #13
0
File: client.c Project: ertesh/SO
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>

#include "mesg.h"
#include "err.h"
#include "simple_sem.h"

int shmid, clisem, servsem;	/* shared memory and semaphore IDs */
Mesg *mesgptr;			/* ptr to message structure, which is
				   in the shared memory segment */
void client()
{
  int n;

  P(clisem);			/* get control of shared memory */

  printf("Enter filename: ");
  if (fgets(mesgptr->mesg_data, MAXMESGDATA, stdin) == NULL)
    syserr("filename read error");

  n = strlen(mesgptr->mesg_data);
  if (mesgptr->mesg_data[n - 1] == '\n')
    n--;			/* ignore newline from fgets() */
  mesgptr->mesg_len = n;
  V(servsem);			/* wake up server */

  P(clisem);			/* wait for server to process */
  while( (n = mesgptr->mesg_len) > 0) {
    if (write(1, mesgptr->mesg_data, n) != n)
      syserr("data write error");
    V(servsem);			/* wake up server */
    P(clisem);			/* wait for server to process */
  }

  if (n < 0)
    syserr("data read error");
}
Example #14
0
/*
**  PR_INTEGRITY -- print out integrity constraints on a relation
**
**	Finds all integrity tuples for this unique relation, and
**	calls pr_int() to print a query from them.
**
**	Parameters:
**		relid -- rel name
**		relowner -- 2 byte owner id
**
**	Returns:
**		none
**
**	Side Effects:
**		file activity, query printing
**
**	Trace Flags:
**		33, 9
*/
void
pr_integrity(char *relid, char *relowner)
{
	extern desc_t		Intdes;
	tid_t			hitid, lotid;
	struct integrity	key, tuple;
	register int		i;


#ifdef xZTR1
	if (tTf(50, 9))
		printf("pr_integrity(relid =%s, relowner=%s)\n", 
			relid, relowner);
#endif

	printf("Integrity constraints on %s are:\n\n", relid);
	opencatalog("integrities", OR_READ);

	/* get integrities tuples for relid, relowner */
	clearkeys(&Intdes);
	ingres_setkey(&Intdes, &key, relid, INTRELID);
	ingres_setkey(&Intdes, &key, relowner, INTRELOWNER);
	if ((i = find(&Intdes, EXACTKEY, &lotid, &hitid, &key)) != 0)
		syserr("pr_integrity: find %d", i);
	for (;;) {
		if ((i = get(&Intdes, &lotid, &hitid, &tuple, TRUE)) != 0)
			break;
		if (kcompare(&Intdes, &tuple, &key) == 0)
			pr_int(&tuple, relid);
	}
	if (i != 1)
		syserr("pr_integrity: get %d", i);
}
Example #15
0
int main ()
{
    pid_t pid;

    /* wypisuje identyfikator procesu */
    printf("Moj PID = %d\n", getpid());

    /* tworzy nowy proces */
    switch (pid = fork()) {
    case -1: /* blad */
        syserr("Error in fork\n");

    case 0: /* proces potomny */

        printf("Jestem procesem potomnym. Moj PID = %d\n", getpid());
        printf("Jestem procesem potomnym. Wartosc przekazana przez fork() ="
               "%d\n", pid);

        /* wykonuje program ps */
        execl("/bin/ps", "ps", 0);
        syserr("Error in execlp\n");

    default: /* proces macierzysty */

        printf("Jestem procesem macierzystym. Moj PID = %d\n", getpid());
        printf("Jestem procesem macierzystym. Wartosc przekazana przez fork() =\
 %d\n", pid);

        /* czeka na zakonczenie procesu potomnego */
        printf("wait: %d\n", wait(0));

        return 0;
    } /*switch*/
}
Example #16
0
/*
 * NAME: ip_bindery
 * USAGE: Establish a local passive (listening) socket at the given port.
 * ARGS: family - AF_INET is the only supported argument.
 *       port - The port to establish the connection upon.  May be 0, 
 *		which requests any open port.
 *	 storage - Pointer to a sockaddr structure big enough for the
 *		   specified family.  Upon success, it will be filled with
 *		   the local sockaddr of the new connection.
 * NOTES: In most cases, the local address for 'storage' will be INADDR_ANY
 *        which doesn't really give you any useful information.  It is not
 *        possible to authoritatively figure out the local IP address
 *        without using ioctl().  However, we guess the best we may.
 *
 * NOTES: This function lacks IPv6 support.
 *        This function lacks Unix Domain Socket support.
 */
int	ip_bindery (int family, unsigned short port, SS *storage)
{
	socklen_t len;
	int	fd;

	if (inet_vhostsockaddr(family, port, NULL, storage, &len))
	{
		syserr(-1, "ip_bindery: inet_vhostsockaddr(%d,%d) failed.", 
							family, port);
		return -1;
	}

	if (!len)
	{
		syserr(-1, "ip_bindery: inet_vhostsockaddr(%d,%d) didn't "
			"return an address I could bind", family, port);
		return -1;
	}

	if ((fd = client_bind((SA *)storage, len)) < 0)
	{
		syserr(-1, "ip_bindery: client_bind(%d,%d) failed.", family, port);
		return -1;
	}

	return fd;
}
Example #17
0
void initializeThreadAttribute(pthread_attr_t* threadAttribute,
  int detachState) {
  if (pthread_attr_init(threadAttribute) != 0)
    syserr(THREAD_ATTRIBUTE_INITIALIZATION_ERROR_CODE);
  if (pthread_attr_setdetachstate(threadAttribute, detachState) != 0)
    syserr(THREAD_ATTRIBUTE_DETACHSTATE_INITIALIZATION_ERROR_CODE);
}
Example #18
0
/*
** XDOT
**	add to attribute stash any missing attributes in the
**	source relation and then build tree with all attribs
**	in the 'a_id' order.  This algorithm assumes that
**	the function 'attadd' insert attributes into the list
**	in 'a_id' order from 1 -> N.
*/
qtree_t *
xdot(int slot)
{
	PARRNG				*rptr;
	attr_t		tuple;
	register attr_t	*ktuple;
	attr_t		ktup;
	tid_t				tid;
	tid_t				limtid;
	qtree_t		*tempt;
	register qtree_t	*vnode;
	int				ik;
	register att_ent_t		*aptr;

	extern PARRNG			Parrng[];
	extern char			*Trname;
	extern desc_t			Attdes;

	rptr = &Parrng[slot];

#ifdef	xPTR2
	tTfp(35, 0, "ALL being processed for %12s\n",
	    rptr->vardesc.d_rangevar);
#endif

	if (rptr->vardesc.d_r.r_attrc <= 0)
		syserr("xdot: rptr->vardesc.d_r.r_attrc %d.\n", rptr->vardesc.d_r.r_attrc);
	/* if attstash is missing any attribs then fill in list */
	if (rptr->vardesc.d_r.r_attrc != attcount(slot)) {
		/* get all entries in attrib relation */
		clearkeys(&Attdes);
		ktuple = &ktup;
		ingres_setkey(&Attdes, ktuple, rptr->vardesc.d_r.r_id, ATTRELID);
		ingres_setkey(&Attdes, ktuple, rptr->vardesc.d_r.r_owner, ATTOWNER);
		if ((ik = find(&Attdes, EXACTKEY, &tid, &limtid, ktuple)) != 0)
			syserr("bad find in xdot '%d'", ik);
		while (!get(&Attdes, &tid, &limtid, &tuple, 1))
			if (!kcompare(&Attdes, &tuple, ktuple))
				/* add any that are not in the stash */
				if (!attfind(slot, tuple.a_name))
					attadd(slot, &tuple);
	}

	/* build tree for ALL */
	tempt = NULL;
	aptr = rptr->attlist;
	while (aptr != 0) {
		vnode = par_tree(NULL, NULL, VAR, sizeof(varnode_t), slot, aptr);
		Trname = aptr->atbname;
		tempt = addresdom(tempt, vnode);
		aptr = aptr->atbnext;
	}

#ifdef	xPTR3
	tTfp(35, 0, "end of xdot %12s\n", rptr->vardesc.d_rangevar);
#endif

	return(tempt);
}
MutexAndSignal_pointer MutexAndSignal_create() {
  MutexAndSignal_pointer this = safe_raw_allocate(1, sizeof(struct MutexAndSignal));
  if (pthread_mutex_init(&this->lock, 0) != 0)
    syserr ("MutexAndSignal_create: gMutex init failed");
  if (pthread_cond_init(&this->signal, 0) != 0)
    syserr ("MutexAndSignal_create: signal init failed");
  return this;
}
Example #20
0
void exit_server()
{
    if (msgctl(server_qid, IPC_RMID, 0) == -1)
        syserr("msgctl RMID");
    if (msgctl(report_qid, IPC_RMID, 0) == -1)
        syserr("msgctl RMID");
    exit(0);
}
Example #21
0
File: klient.c Project: Wookesh/SO2
void getIPCs()
{
	if ((IPCs[out] = msgget(S_KEY, 0)) == -1)
		syserr("msgget");
	
	if ((IPCs[in] = msgget(K_KEY, 0)) == -1)
		syserr("msgget");
}
Example #22
0
void destroyServerSyncTools(sharedSynchronizationTools* tools) {
  if (pthread_mutex_destroy(&tools->mutex) != 0)
    syserr(MUTEX_DESTROY_ERROR_CODE);
  if (pthread_cond_destroy(&tools->committeeUpdateResultsCondition) != 0)
    syserr(COMMITTEES_CONDITION_DESTROY_ERROR_CODE);
  if (pthread_cond_destroy(&tools->reportProcessResultsCondition) != 0)
    syserr(REPORTS_CONDITION_DESTROY_ERROR_CODE);
}
Example #23
0
/* Initialization. */
void initializeServerSyncTools(sharedSynchronizationTools* tools) {
  if (pthread_mutex_init(&tools->mutex, 0) != 0)
    syserr(MUTEX_INITIALIZATION_ERROR_CODE);
  if (pthread_cond_init(&tools->committeeUpdateResultsCondition, 0) != 0)
    syserr(COMMITTEES_CONDITION_INITIALIZATION_ERROR_CODE);
  if (pthread_cond_init(&tools->reportProcessResultsCondition, 0) != 0)
    syserr(REPORTS_CONDITION_INITIALIZATION_ERROR_CODE);
}
Example #24
0
MutexAndSignal_pointer MutexAndSignal_create() {
  MutexAndSignal_pointer this = new(struct MutexAndSignal);
  if (pthread_mutex_init(&this->lock, 0) != 0)
    syserr("MutexAndSignal_create: gMutex init failed");
  if (pthread_cond_init(&this->signal, 0) != 0)
    syserr("MutexAndSignal_create: signal init failed");
  return this;
}
Example #25
0
void create_queues()
{
    const int flags = 0666 | IPC_CREAT | IPC_EXCL;
    if ((server_qid = msgget(SERVER_QUEUE_KEY, flags)) == -1)
        syserr("msgget");
    if ((report_qid  = msgget(REPORT_QUEUE_KEY, flags)) == -1)
        syserr("msgget");
}
Example #26
0
/*
**  REL_FILE -- copy from relation to file
*/
int
rel_file(void)
{
	int			j;
	struct tup_id		tid, limtid;
	char			*cp, save;
	register int		offset;
	register int		i;
	register struct map	*mp;

	/* set scan limits to scan the entire relation */
	if (find(&Des, NOKEY, &tid, &limtid, (void *) NULL))
		syserr("find error");

	while ((i = get(&Des, &tid, &limtid, Inbuf, 1)) == 0) {
		mp = Map;
		offset = 0;
		for (i = 0; i < Mapcount; i++) {
			/*
			** For cases of char to numeric conversion,
			** there must be a null byte at the end of the
			** string. The character just past the current
			** domain is saved an a null byte inserted 
			*/

			cp = &Inbuf[mp->roffset + mp->rlen];	/* compute address */
			save = *cp;	/* get the character */
			*cp = '\0';	/* insert a null */

			/*
			** Special case, we want to copy the tid
			*/
			if ( mp->roffset == -1 ) {
				j = transfer((ANYTYPE *)&tid,
						mp->rtype, mp->rlen,
						mp->ftype, mp->flen, offset);
			} else {
				j = transfer((ANYTYPE *)&Inbuf[mp->roffset],
						mp->rtype, mp->rlen,
						mp->ftype, mp->flen, offset);
			}
			if (j) {
				/* bad ascii to numeric conversion or field length too small */
				return (nferror(j, mp->paramname, &Inbuf[mp->roffset], locv(Tupcount), Relname, Filename, 0));
			}
			*cp = save;	/* restore the saved character */
			offset += mp->flen;
			mp++;
		}
		Tupcount++;
		if (fwrite(Outbuf, 1, offset, File_iop) != offset)
			syserr("copy:cant write to user file %s", Filename);
	}
	if (i < 0)
		syserr("bad get from rel %d", i);
	return (0);
}
/*
**  READ_ARG -- Read a single argument from pipe
**
**	An argument can be as simple as an integer, or as complex
**	as a query tree.
**
**	Parameters:
**		ppb -- the pipe block to read from.
**		pparm -- the parameter descripter to put the
**			argument in.
**
**	Returns:
**		none.
**
**	Side Effects:
**		May allocate space from Qbuf for trees, etc.
**
**	Called By:
**		readinput
**
**	Trace Flags:
**		10.6 - 10.7
*/
int
read_arg(register pb_t *ppb, register paramv_t *pparm)
{
	char	ptype;
	short	plen;
	register int	i;
	register char	*p;
	qtree_t		*q;

	/* get the parameter type */
	i = pb_get(ppb, &ptype, 1);
	if (i == 0) {
		pparm->pv_type = PV_EOF;
		pparm->pv_val.pv_str = NULL;
		return (PV_EOF);
	}
	i = pb_get(ppb, (char *) &plen, 2);
	if (i < 2)
		syserr("readarg: pb_get %d", i);

	/* figure out the type */
	switch (ptype) {
	  case PV_INT:
#ifdef xCM_DEBUG
		if (plen != sizeof(pparm->pv_val.pv_int))
			syserr("readinput: PV_INT %d", plen);
#endif
		pb_get(ppb, (char *) &pparm->pv_val.pv_int, plen);
		break;

	  case PV_STR:
	  case PV_TUPLE:
		p = need(Qbuf, plen);
		pb_get(ppb, p, plen);
		pparm->pv_val.pv_str = p;
		break;

	  case PV_QTREE:
		q = readqry(pb_get, (int) ppb, TRUE);
		pparm->pv_val.pv_qtree = q;
		break;

	  case PV_EOF:
		/* this case is allowed for the mon-par interface */
		break;

	  default:
		syserr("readinput: type %d len %d", ptype, plen);
	}

	/* save the type & length */
	pparm->pv_type = ptype;
	pparm->pv_len = plen;

	return (ptype);
}
Example #28
0
int main(int argc, char* argv[])
{
  int sockfd, portno, n;
  struct hostent* server;
  struct sockaddr_in serv_addr;
  socklen_t addrlen;
  char buffer[256];

  if(argc != 3) {
    fprintf(stderr, "Usage: %s <hostname> <port>\n", argv[0]);
    return 1;
  }
  server = gethostbyname(argv[1]);
  if(!server) {
    fprintf(stderr, "ERROR: no such host: %s\n", argv[1]);
    return 2;
  }
  portno = atoi(argv[2]);
  
  /*{
  struct in_addr **addr_list; int i;
  printf("Official name is: %s\n", server->h_name);
  printf("    IP addresses: ");
  addr_list = (struct in_addr **)server->h_addr_list;
  for(i = 0; addr_list[i] != NULL; i++) {
    printf("%s ", inet_ntoa(*addr_list[i]));
  }
  printf("\n");
  }*/

  sockfd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
  if(sockfd < 0) syserr("can't open socket");
  printf("create socket...\n");

  memset(&serv_addr, 0, sizeof(serv_addr));
  serv_addr.sin_family = AF_INET;
  serv_addr.sin_addr = *((struct in_addr*)server->h_addr);
  /*memcpy(&server->h_addr, &serv_addr.sin_addr.s_addr, server->h_length);*/
  serv_addr.sin_port = htons(portno);

  printf("PLEASE ENTER MESSAGE: ");
  fgets(buffer, 255, stdin);
  n = strlen(buffer); if(n>0 && buffer[n-1] == '\n') buffer[n-1] = '\0';

  addrlen = sizeof(serv_addr);
  n = sendto(sockfd, buffer, strlen(buffer), 0, (struct sockaddr*)&serv_addr, addrlen);
  if(n < 0) syserr("can't send to server");
  printf("send...\n");

  n = recvfrom(sockfd, buffer, 255, 0, (struct sockaddr*)&serv_addr, &addrlen);
  if(n < 0) syserr("can't receive from server");
  printf("CLIENT RECEIVED MESSAGE: %s\n", buffer);

  close(sockfd);
  return 0;
}
Example #29
0
/* Free resources & destroy. */
void freeServerIPCQueuesResources(sharedIPCQueueIds* queueIds) {
  if (msgctl(queueIds->initConnectionIPCQueueId, IPC_RMID, 0) == -1)
    syserr(IPC_QUEUE_REMOVE_OPERATION_ERROR_CODE);
  if (msgctl(queueIds->committeeDataIPCQueueId, IPC_RMID, 0) == -1)
    syserr(IPC_QUEUE_REMOVE_OPERATION_ERROR_CODE);
  if (msgctl(queueIds->finishIPCQueueId, IPC_RMID, 0) == -1)
    syserr(IPC_QUEUE_REMOVE_OPERATION_ERROR_CODE);
  if (msgctl(queueIds->reportDataIPCQueueId, IPC_RMID, 0) == -1)
    syserr(IPC_QUEUE_REMOVE_OPERATION_ERROR_CODE);
}
Example #30
0
void socket_close(socket s)
{
    if (close(s.in_fd) == -1) {
	syserr("socket_close: cannot close in_fd");
    }

    if (close(s.out_fd) == -1) {
	syserr("socket_close: cannot close out_fd");
    }
}