* shared memory
* unix domain socket
* netlink socket
unix domain socket example
http://www.uwsg.iu.edu/hypermail/linux/kernel/0202.0/0515.html
#include
#include
#include
#include
#include
#include
#include
#include
#include
int main(int argc, char *argv[])
{
char buf[1];
int s;
int retval;
struct sockaddr_un server;
if (argc < 2)
printf("Usage : test socketname");
s = socket(PF_UNIX, SOCK_STREAM, 0);
if (s < 0)
perror("socket :");
else
{
server.sun_family = PF_LOCAL;
strncpy(server.sun_path, argv[1], sizeof(server.sun_path));
if (connect(s,(struct sockaddr *)&server,SUN_LEN(&server)) < 0)
perror("connect :");
else
{
retval = recv(s,buf,0, 0);
if (retval < 0)
perror("recv :");
else
printf("Received %u bytes.",retval);
close(s);
return 0;
}
}
}
沒有留言:
張貼留言