I want to make this program run on solaris machine .... what changes can i do .....

Posted on 2004-08-08
Last Modified: 2013-12-05
Hi guys,

 The following program is for getting credentials......

 I have some problems facing when run on solaris machine ......

Program is following :---->

#include   <stdio.h>
#include   <stdlib.h>
#include   <sys/socket.h>
#include   <errno.h>
#include   <sys/types.h>
#include   <sys/uio.h>
#include   <signal.h>
#include   <time.h>
#include   <sys/types.h>
#include   <stdlib.h>
#include   <pthread.h>
#include   <sys/param.h>
#include   <sys/cred.h>

ssize_t recv_cred(int, void *, size_t, struct cred *);

  int             fd[2], on, n;
  char            buf[100];
  struct cred    cred;
  if (socketpair(AF_UNIX, SOCK_STREAM, 0, fd) < 0)
    perror("Socketpair Error");
  /* must set the socket option on the *receiving* socket */
  on = 1;
  setsockopt(fd[1], 0, LOCAL_CREDS, &on, sizeof(on));
  write(fd[0], "hello, world\n", 13);
  if ( (n = recv_cred(fd[1], buf, sizeof(buf), &cred)) < 0)
    perror("Recv_Cred Error");
  else if (n == 0)
    perror("Recv_Cred, Unexpected EOF");
  buf[n] = 0;                     /* null terminate */
  printf("data: %s", buf);
  if (cred.cr_ngroups == 0)
    printf("[No CREDENTIALS Returned]\n");
      printf(" Real User ID = %d\n", cred.cr_ruid);
      printf(" Real Group ID = %d\n", cred.cr_rgid);
      //      printf(" Login Name = %-*s\n", MAXLOGNAME, cred.cr_login);
      printf(" Effective User ID = %d\n", cred.cr_uid);
      printf(" Effective Group ID = %d\n", cred.cr_gid);
      printf(" %d Supplementary Groups:", cred.cr_ngroups - 1);
      for (n = 1; n < cred.cr_ngroups; n++)   /* [0] is the egid */
      printf(" %d", cred.cr_groups[n]);

#define CONTROL_LEN     (sizeof(struct cmsghdr) + sizeof(struct cred))

recv_cred(int fd, void *ptr, size_t nbytes, struct cred *credptr)
  struct msghdr   msg;
  struct iovec    iov[1];
  char            control[CONTROL_LEN + 20];
  int             n;
  msg.msg_name = NULL;
  msg.msg_namelen = 0;
  iov[0].iov_base = ptr;
  iov[0].iov_len = nbytes;
  msg.msg_iov = iov;
  msg.msg_iovlen = 1;

  msg.msg_control = control;
  msg.msg_controllen = sizeof(control);
  msg.msg_flags = 0;

  if ( (n = recvmsg(fd, &msg, 0)) < 0)
  credptr->cr_ngroups = 0;       /* indicates no credentials returned */
  if (credptr && msg.msg_controllen > 0)
      struct cmsghdr  *cmptr = (struct cmsghdr *) control;
      if (cmptr->cmsg_len != sizeof(struct cmsghdr) + sizeof(struct cred))
      err_quit("control length = %d", cmptr->cmsg_len);
      if (cmptr->cmsg_level != SOL_SOCKET)
      err_quit("control level != SOL_SOCKET");
      if (cmptr->cmsg_type != SCM_CREDS)
      err_quit("control type != SCM_CREDS");
      memcpy(credptr, CMSG_DATA(cmptr), sizeof(struct cred));


To compile on soalris :

 cc -o tfcred02 tfcred02.c -lsocket -lnsl -lrt

To Run :


Am getting some errors:

They are following :---->

[ab1221@eagles ~/AdvNetProg/Assign3]$ cc -o tfcred02 tfcred02.c -lsocket -lnsl -lrt

tfcred02.c: In function `main':
tfcred02.c:30: error: `LOCAL_CREDS' undeclared (first use in this function)
tfcred02.c:30: error: (Each undeclared identifier is reported only once
tfcred02.c:30: error: for each function it appears in.)
tfcred02.c: In function `recv_cred':
tfcred02.c:86: error: structure has no member named `msg_control'
tfcred02.c:87: error: structure has no member named `msg_controllen'
tfcred02.c:88: error: structure has no member named `msg_flags'
tfcred02.c:95: error: structure has no member named `msg_controllen'
tfcred02.c:105: error: `SCM_CREDS' undeclared (first use in this function)
tfcred02.c:108: warning: passing arg 2 of `memcpy' makes pointer from integer without a cast

[ab1221@eagles ~/AdvNetProg/Assign3]$

Pls help me in this program..


Question by:amankhan
1 Comment

Accepted Solution

realrael earned 500 total points
ID: 11749583

did you write this on an windows pc? basically, i think you're using this structure that goes fine with a windows box, but not compatible with solaris. for you to be able to compile this, you have to use the exact structure that's being used in unix. you could look at the source files and see what the actual structures are. from there you could figure out what adjustments you have to do in code. - rael

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Digital Output does not have continuity to ground? 3 90
Solaris 10.  Nmap installation fails 2 57
Unix Command -- Challenging  question 7 88
unix example issues 18 89
Using libpcap/Jpcap to capture and send packets on Solaris version (10/11) Library used: 1.      Libpcap ( Version 1.2 2.      Jpcap( Version 0.6 Prerequisite: 1.      GCC …
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

785 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