c++ - How to use a UNIX socket in a CGI program -


I want to write a web interface for a program that has a Unix Socket based server interface, but it seems that it is impossible To connect it successfully within the CGI program.

I looked at the httpd.conf file and searched the web, but nothing was found. The CGI program C ++ is written in the Unix Socket path accessible by the httpd server.

A customer to connect to a unix local socket, you first create an anonymous socket, like For TCP:

  int fd = socket (AF_LOCAL, SOCK_STREAM, 0);  

Then you create the appropriate struct sockaddr_un with the destination path:

  struct sockaddr_un addr; Addr.sun_family = AF_LOCAL; Strcpy (addr.sun_path, "/ path / to / server / socket / file");  

and call connect () :

  connect (FD, (struct sockaddr *) & amp; addr, sizeof ( Addr));  

However, it is widely documented on the pages of all humans and online. There is no C ++ specific method, unless you use third party libraries; These are the Nix-specific extensions for standard C:

  #include & lt; Arpa / inet.h & gt; #include & lt; Netinet / ip.h & gt; # Include & lt; Sys / socket.h & gt; # Include & lt; Sys / types.h & gt;  

GNU C Reference Manual.


Comments

Popular posts from this blog

java - org.apache.http.ProtocolException: Target host is not specified -

java - Gradle dependencies: compile project by relative path -

ruby on rails - Object doesn't support #inspect when used with .include -