1833452 Members
3331 Online
110052 Solutions
New Discussion

Unable to add a socket

 
Raj_4
New Member

Unable to add a socket

Hi all,

I am trying to develop a system (in C under HP-Unix) which would read the syslog messages and work on it. So i tried to create a socket through a call to the "system" function alongwith the variable returned by tmpnam as follows,

char socknam[L_tmpnam + 1];
int optn = 1;
int sockFd = -1;
struct sockaddr_un SockAddr;
char sAux[512];
struct timeval TimeVal;
fd_set ReadList;

tmpnam(socknam);
sockFd = socket(AF_UNIX,SOCK_STREAM,0);
ioctl(sockFd,FIONBIO,&optn);
unlink(socknam);
SockAddr.sun_family=AF_UNIX;
strncpy(SockAddr.sun_path,socknam,sizeof(SockAddr.sun_path)-1);

bind(sockFd,(struct sockaddr_un*)&SockAddr,sizeof(struct sockaddr_un));

listen(sockFd,SOMAXCONN);

sprintf(sAux,"syslgcmd add %s 2> /dev/null",socknam);
system(sAux);

select(sockFd + 1, &ReadList, 0, 0, &TimeVal);


And it always gets timed out in this "select" call, when i have set TimeVal.tv_sec = 10, or in other words it returns zero always.
And when i view the syslog i find that it states, unable to open the particular file which is value of the variable "socknam"(like /var/tmp/aaaa....), and says file ignored. And when i type the command "syslgcmd stats" i dont see this socket being added to the list. When i try to view that particular file(which is present temporarily till the program is running) i am prompted that the operation is not supported.

Can anyone pour some light on this issue as to where probably i might be going wrong.

Thanking u in anticipation.
Raj.
1 REPLY 1
Brian Hackley
Honored Contributor

Re: Unable to add a socket

Raj,

I've got two places for you to look for more help with regards to socket programming.
First, the directory /usr/lib/demos/networking
contains some excellent example client and server programs. Each of the 3 subdirectories is dedicated to example programs for af_unix, dlpi and (Network) socket.

The second place to look is online at http://docs.hp.com -> Networking/Communications
-> LAN/9000 -> BSD Sockets Interface Programmer's Guide (HP-UX 10.x, HP-UX 11.0)

And now that I think of it, there are THREE places to look for more details, if you include the man page for the system call(s) in question.

Hope this helps,

-> Brian Hackley
Ask me about telecommuting!