Solved

unix networking programming

Posted on 1998-12-17
7
248 Views
Last Modified: 2013-12-23
The answer you gave me to the question about a remote service written in c under unix does not run! It is full of bugs! Help me out!!
0
Comment
Question by:boosta
7 Comments
 
LVL 2

Expert Comment

by:rdelfino
ID: 1582729

Who have you sent this question?

What answer?

Which bugs?

Who am I?

Who was George Washington?

What am I doing here?

Reginaldo
stoned . . . . . . .
 
0
 
LVL 22

Expert Comment

by:blu
ID: 1582730
Since you accepted the first answer, your question no longer
appears. I suggest that you repost the question and/or incorrect
answer so that someone else might be able to help you. For instance, I am having a little trouble understanding the question from you original text and the answer might help, or clarifying the question could help.  What do you mean by converting a username to an IP address?
0
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1582731
 I wonder if you are referring to your earlier question where you asked for a sample service like daytime, which I answered by supplying the following program (reproduced here for the benefit of others who do not wish to have to 'pay' points to read the original question) -

#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>

extern int errno;

int TCPdaytime (const char* host, const char *service);
int errexit (const char *format, ...);
int connectTCP (const char *host, const char *service)

#define LINELEN 128

int main (int argc, char *argv [])
{
  char *host = "localhost";
  char *service = "daytime";

  switch (argc)
  {
    case 1:
      host = "localhost";
      break;

    case 3:
      service = argv [2];

    case 2:
      host = argv [1];
      break

    default:
      fprintf (stderr, "usage: TCPdaytime [host [port]]\n");
      exit (1);
  }

  TCPdaytime (host, service);
  exit (0);
}

TCPdaytime (const char *host, const char *service)
{
  char buf [LINELEN + 1];
  int s, n;

  s = connectTCP (host, service);

  while ( (n = read (s, buf, LINELEN)) > 0)
  {
    buf [n] = '\0';
    (void) fputs (buf, stdout);
  }
}

int errexit (const char *format, ...)
{
  va_list args;

  va_start (args, format);
  vfprintf (stderr, format, args);
  va_end (args);
  exit (1);
}

int connectTCP (const char *host, const char *service)
{
  struct hostent *phe;
  struct servent *pse;
  struct protoent *ppe;
  struct sockaddr_in sin;
  int s, type;

  memset (&sin, 0, sizeof (sin));
  sin.sin_family = AF_INET;

  if (pse = getservbyname (service, "tcp"))
    sin.sin_port = pse->s_port;
  else if ( (sin.sin_port = htons ((u_short) atoi (service))) == 0)
    errexit ("Can't get \"%s\" service entry.\n", service);

  if (phe = gethostbyname (host))
    memcpy (&sin.sin_addr, phe->h_addr, phe->h_length);
  else if ((sin.sin_addr.s_addr = inet_addr (host)) == INADDR_NONE)
    errexit ("Can't get \"%s\" host entry.\n", host);

  if ((ppe = getprotobyname ("tcp")) == 0)
    errexit ("Can't get \"tcp\" protocol entry.\n");

  type = SOCK_STREAM;

  s = socket (PF_INET, type, ppe->p_proto);
  if (s < 0)
    errexit ("Can't create socket: %s\n", strerror (errno));

  if (connect (s, (struct sockaddr *) &sin, sizeof (sin)) < 0)
    errexit ("Can't connect to %s.%s: %s\n", host, service, strerror (errno));

  return s;
}

  Now, you marked my answer as 'correct' on November 15th, and said "Thanx a lot. Its appropriate and accurate." (exact words).
  So, if you are unhappy with my answer, I'm surprised that you have changed your mind a month later, or you marked it as correct and 'accurate' without even running it.
  What version of Unix are you using?  What are the problems you are experiencing?  Please be more explicit.
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1582732
 Perhaps more importantly, have you modified the program, since I provided it !!
0
 
LVL 4

Accepted Solution

by:
davidmwilliams earned 110 total points
ID: 1582733
 The program presented works fine...
0
 

Author Comment

by:boosta
ID: 1582734
I have tested this program NOW and it works fine! Sorry for the inconvenience! Thanx!
0
 
LVL 4

Expert Comment

by:davidmwilliams
ID: 1582735
Phew !  No problem at all.  Glad it helped!
0

Featured Post

Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

This is an article about my experiences with remote access to my clients (so that I may serve them) and eventually to my home office system via Radmin Remote Control. I have been using remote access for over 10 years and have been improving my metho…
If you're not part of the solution, you're part of the problem.   Tips on how to secure IoT devices, even the dumbest ones, so they can't be used as part of a DDoS botnet.  Use PRTG Network Monitor as one of the building blocks, to detect unusual…
Viewers will learn how to connect to a wireless network using the network security key. They will also learn how to access the IP address and DNS server for connections that must be done manually. After setting up a router, find the network security…
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now