[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 285
  • Last Modified:

Client/Server Programming: Default argument for unknown service name?


I am writing a client server program that doesn't have a specific service name...
I am really only familiar with the "echo" and "time" service.  What should I have as
a default argument for the service if this is something I'm making myself?

void main(int argc, char *argv[])
{
      char      *service = argv[1];  //port number??????      
      char      *host ="localhost";  //IP address
      //arguments are entered in on the command line
      WSADATA      wsadata; //Creating a WSADATA object called wsadata
      switch (argc)
      {
      case 1:      break;
            case 2: service = argv[1];
                        break;
            case 3: service = argv[1];
                        host = argv[2];
                        break;
            default: errexit("usage: TCPmusic[port]\n");
AND SO ON....ETC...

Thanks,
0
bjw5d6
Asked:
bjw5d6
  • 2
  • 2
2 Solutions
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, and automation at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
The service mentioned here is not the port number. A port number represent an endpoint or a channel for network communications. Services are programs that provides you the services.

For example
ftp,telnet,smtp,nntp,ntp,finger are services... and these services are mapped to the port numbers. In *ix OS you will find these services and port numbers in
/etc/services file.

HTH
0
 
bjw5d6Author Commented:
Yes, I know this but isn't the service name needed to get the port number... for
example the part of my program...
      // Map service name to port number
      if(pse=getservbyname(service, transport))
            sin.sin_port= pse->s_port;
needs a service name and a transport (the transport is 'tcp')... I can't just use
sin.sin_port=pse->s_port; to get a default port number... or can I?
0
 
Murugesan NagarajanSubject-matter expert at C++ C delivery, implementation, and automation at UNIX oriented operating systems (Windows: CYGWIN_NT MINGW32_NT MINGW64_NT)Commented:
Here
(pse=getservbyname(service, transport))
the function getservbyname returns a servent structure for the line from /etc/services that matches  the  service name using protocol 'transport'. If you are not able to get the port number check ur /etc/services file that you have proper settings for getting the port number for the particular service.
0
 
bjw5d6Author Commented:
Since I made up my own service I had to enter in a made up port number.  I just
used port number 40947.  Thanks for your help anyway!  I appreciate it.
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now